From 9f363b0afe8ad31a0d23657c1f148a46685bb3fd Mon Sep 17 00:00:00 2001 From: Cody Oss Date: Fri, 3 May 2024 09:08:22 -0500 Subject: [PATCH] fix: provide unmarshal options for streams 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. --- v2/proto_json_stream.go | 3 ++- v2/proto_json_stream_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/v2/proto_json_stream.go b/v2/proto_json_stream.go index cc4486eb..9b690d40 100644 --- a/v2/proto_json_stream.go +++ b/v2/proto_json_stream.go @@ -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 } diff --git a/v2/proto_json_stream_test.go b/v2/proto_json_stream_test.go index 784e3b82..9cd1ce03 100644 --- a/v2/proto_json_stream_test.go +++ b/v2/proto_json_stream_test.go @@ -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 }