Skip to content
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

Issue619 #621

Closed
wants to merge 2 commits into from
Closed

Issue619 #621

wants to merge 2 commits into from

Conversation

jmarais
Copy link
Contributor

@jmarais jmarais commented Sep 8, 2019

Compensate the buffer's slice when marshaling into a larger backing buf.

…en a proto.Buffer and proto.Marshal with different proto.Buffer sizes.
…. This allows us to marshal at the correct place when the buffer contains a larger backing buffer. (gogo#619)
@@ -189,8 +189,22 @@ type Marshaler interface {
// prefixed by a varint-encoded length.
func (p *Buffer) EncodeMessage(pb Message) error {
siz := Size(pb)
sizVar := SizeVarint(uint64(siz))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be fixing p.Marshal rather than the calling code? If we have to change code that calls Marshal, then I suspect something must be wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right. The large change here isn't necessary

if err != nil {
t.Fatal(err)
}
err = buf.Marshal(m)
Copy link
Contributor

@apelisse apelisse Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is buf.Marshal supposed to concatenate into the buffer? I didn't realize that was the expected behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the case. Using golang/protobuf in this same test does yield a buffer with the same message concatenated into it.

The proto/lib.go does have an explicit Reset() method. Which a client can call when he is done.
https://github.com/golang/protobuf/blob/master/proto/lib.go#L362

t.Fatal(err)
}
bufferBytes := buf.Bytes()
protoBytes, _ := proto.Marshal(m)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to check the ignored err here

}
}

func marshalCheck(t *testing.T, m proto.Message, size int) {
Copy link
Contributor

@apelisse apelisse Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I liked better the first version of the test (the one in the parent commit)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one did you reference here? I think having a test for encoding twice into the buffer is useful. However, I can make an explicit test for twice encoding.

@apelisse apelisse mentioned this pull request Sep 9, 2019
@jmarais
Copy link
Contributor Author

jmarais commented Oct 11, 2019

In favor of: #627

@jmarais jmarais closed this Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants