-
Notifications
You must be signed in to change notification settings - Fork 75
use varints for delimiting plaintext 2.0 msgs #74
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I don't think we need tests since this was a one-off, and any test we write to cover this would actually be testing gogo's ability to length-encode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I don't know Go 🤷♂️
Thanks for fixing this so quickly! |
func readWriteMsg(rw io.ReadWriter, out *pb.Exchange) (*pb.Exchange, error) { | ||
const maxMsgSize = 1 << 16 | ||
r := gogoio.NewDelimitedReader(rw, maxMsgSize) | ||
w := gogoio.NewDelimitedWriter(rw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will over-read and corrupt the stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(it buffers internally)
This fixes a bug in plaintext 2.0, which according to the spec should use varints for delimiting messages. I used
go-msgio
thinking that it used varints under the hood, but it actually uses 4 byte unsigned ints instead.This switches out msgio for gogoprotobuf's varint delimited Reader / Writer types.