-
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
proposal: protodelim: add delimited-message serialization support package #1382
Comments
Should this instead be: type MarshalOptions proto.MarshalOptions Usage wise, it would be the difference between: protodelim.MarshalOptions{proto.MarshalOptions{...}} and protodelim.MarshalOptions{...} golang/go#9859 would be nice here. Another bike-shedding nit, given that |
Implementation-wise for |
The reason for the separate struct type is to allow us to add delimiter-specific options if we need them. e.g., type UnmarshalOptions struct {
proto.UnmarshalOptions
// MaxSize is the maximum size in wire-format bytes of a single message.
// Unmarshaling a message larger than MaxSize will return an error.
MaxSize int
}
Yes, ReadFrom needs to read a byte at a time until it finds the length prefix, although it could try to get clever by seeing if the We could alternatively have a |
Return a distinguishable error? Guarantee that we've only read the size prefix, so the user can skip the next N bytes if they want? (Requires the error contain the number of bytes to skip.) Have another option to skip the too-large message? Probably don't want to skip it by default, because the user may not want us to try to read that 1GiB of protos. Instead of a |
Another option:
I'd recommend against specializing for |
Another argument for checking for |
I'm not really happy with any of the ways for providing a read source that I've come up with. A concrete Defining our own A plain An Another possibility might be:
Then we wrap |
Several other protobuf implementations include first-class support for (de)serializing varint-delimited messages:
google/protobuf/util/delimited_message_util.h
writeDelimitedTo
andparseDelimitedFrom
methods.Both of these handle messages encoded as a varint size in bytes, followed by exactly that many bytes of a wire-format encoded message.
Perhaps we should provide a similar API.
A possible sketch:
I propose including
WriteTo
/ReadFrom
functions operating on anio.Writer
/io.Reader
, because reading from a stream seems like a common use case for delimited messages.The C++ and Java APIs do not provide any way to limit the size of messages read. Perhaps we could have a
protodelim.MarshalOptions.MaxSize
option to avoid trying to process arbitrarily large messages.The text was updated successfully, but these errors were encountered: