Skip to content

Commit

Permalink
fix: provide unmarshal options for streams (#343)
Browse files Browse the repository at this point in the history
We want to discard unknown so if the server sends new data we don't
blow up on it if our proto is not up-to-date.
  • Loading branch information
codyoss committed May 3, 2024
1 parent 18bb8af commit ddf9a90
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion v2/proto_json_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func (s *ProtoJSONStream) Recv() (proto.Message, error) {
// Initialize a new instance of the protobuf message to unmarshal the
// raw data into.
m := s.typ.New().Interface()
err := protojson.Unmarshal(raw, m)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
err := unm.Unmarshal(raw, m)

return m, err
}
Expand Down
3 changes: 2 additions & 1 deletion v2/proto_json_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ func prepareStream(messages []proto.Message) (io.ReadCloser, error) {
}

data := []byte("[")
mo := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
for _, m := range messages {
d, err := protojson.Marshal(m)
d, err := mo.Marshal(m)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ddf9a90

Please sign in to comment.