Skip to content

Issue619#621

Closed
jmarais wants to merge 2 commits intogogo:masterfrom
jmarais:issue619
Closed

Issue619#621
jmarais wants to merge 2 commits intogogo:masterfrom
jmarais:issue619

Conversation

@jmarais
Copy link
Copy Markdown
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)
// prefixed by a varint-encoded length.
func (p *Buffer) EncodeMessage(pb Message) error {
siz := Size(pb)
sizVar := SizeVarint(uint64(siz))
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

2 participants