-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add EOF() method to proto.Buffer #296
Conversation
I added Any chance of getting this small change approved and merged? |
Ping? |
Ping. Any chance that anyone will look at this, even if to say "no thanks"? |
The fact that Can you explain a bit more what your use-case for |
If I am using a buffer, there is no way to tell when I hit EOF on an expected boundary, as opposed to hitting it erroneously in the middle of a field. As is, anything that tries to consume the contents of the buffer would simply have to ignore malformed messages where EOF occurs in the middle of something (like incomplete encoded varint or incomplete length-delimited value). The internal code that uses buffer can directly examine unexported fields: https://github.com/golang/protobuf/blob/master/proto/decode.go#L467
Hmmm. I guess it depends on what is the purpose of the existing wide API. It appears to be for parsing a stream that is a serialized proto. And it seems to be exported for the value of code outside of the
|
Honestly I'm not entirely sure why The functions in the standard encoding/binary package will get you efficient varint and fixed-width decoding on an arbitrary slice or Beyond that, it's not clear to me why you would want to use |
I was using I was basically looking for something like Java's CodedInputStream and CodedOutputStream, except in Go. My interest in an alternate parser isn't related to performance of the current one. Right now, the Go protobuf library only supports serializing from/de-serializing to protoc-generated structs. I was working on an implementation of a reflection-based message, that uses descriptor protos to parse and marshal messages. jhump/protoreflect@61443d9#diff-ac6f0c5d2bd348d0d1e29c20576fa9d1R305 |
I agree that it would be nice to have an equivalent to Going in the other direction, I think if we were to make |
That would be great. So do you recommend that I just close this pull request and (sigh...) fork the parts of |
I think that's probably best for now. You could always fork them into a proper reusable |
@bcmills I just want to make sure that it's obvious that while us folks using protobufs outside of Google understand the concerns, discussion, cautious curation etc. on issues like this one, and appreciate that there are long-term protobuf arcs of work inside Google that have months- and years-worth of sliding-block-puzzle dependency chains to work out, and that "working on protobuf" teams inside Google are understaffed and overburdened, and that there is a constant, wearying flood of terrible pull requests and suggestions that fail to comprehend even large design themes let alone wrinkles and intricacies… (whew)… It nevertheless feels almost impossible to contribute to protobufs in a meaningful way, even with the best of intentions and a lot of work trying to upstream things. And that feels bad, especially with protobufs being central to GRPC. |
@zellyn Agreed. We are aware that the current situation w.r.t. protobuf and pull requests is a significant problem, and we're trying to find a more sustainable way forward. I can't make any promises at the moment, but we feel your pain. |
@bcmills: slightly related ask -- what would you say about changing Right now, any code that is using reflection to crawl a generated struct has to re-parse the I'm happy to open a pull request if there's a chance it could be merged. WDYT? |
@jhump |
The
Buffer
type has a wide API that is very useful for writing my own message marshaller. However, what is does not have is a way to check whether EOF has been reached. The variousDecode*
methods returnio.ErrUnexpectedEOF
when they reach EOF, but that's not sufficient. For example, when reading the next tag+value pair, there was no way to distinguish end-of-message (e.g. no bytes left) from a malformed message (e.g. try to read next varint and/or field contents and reach EOF in the middle).This small change seems inline with the spirit of this type since much of its API is exported. With it, it is possible to write a function that unmarshals a message and properly distinguishes end-of-message from an erroneous/unexpected EOF.