-
Notifications
You must be signed in to change notification settings - Fork 107
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 stable codec interface and implementations #460
Conversation
d431aa2
to
e1b604a
Compare
// If this function returns false, the data returned from Marshal and | ||
// MarshalStable are considered valid text and may be used in contexts | ||
// where text is expected. | ||
IsBinary() bool |
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.
Codecs shouldn't need to expose anything about their format.
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.
Importantly, for Connect GET support, we need to know whether or not the URL data is/needs to be base64 encoded or not. The codec itself could handle this without exposing this detail, but that breaks transparency: there would be no way for a middlebox to know for sure how to translate a Connect GET request to an ordinary Connect Unary request or gRPC request. Unless we change the Connect GET design, this bit does need to escape the codec one way or another.
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.
Agreed with John here. To make Envoy and other middleboxes work, the runtime needs to know whether the encoded data is text or binary.
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.
I think unit tests for the codecs are appropriate now. I leaned toward end-to-end tests during connect's development b/c they were more robust to refactoring and gave me a better feel for the user experience.
Can you add a few tests? Otherwise this looks great.
Added tests and unexported the interface. The tests are a bit anemic at this point in time, if anyone has any ideas for how they could be expanded with more edge cases I'd like to. I'm working on stuff a bit out of order at the moment. |
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! Think the testing could be improved a bit, but as long as those changes are confined to codec_test.go
this can land without further review.
&pingv1.PingRequest{Text: "text", Number: 1}, | ||
[]byte(`{"number":"1","text":"text"}`), | ||
) | ||
} |
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.
A few suggestions to improve test coverage:
- I always like
testing/quick
to do these sorts of round-trip testing. There are a handful of examples in this repository. - Rather than directly asserting the wire format, can we create a protobuf message with a
map[string]string
and assert that repeatedly marshaling it always produces the same output?
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 was a little tricky but I think I have made tests that work how you wanted.
Changes were confined to |
Unfortunately, protobuf offers no story whatsoever for canonicalization of protobuf or protojson output. It seems the best we can get is to just make it deterministic within each implementation.
Related issues: