MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / TestProtoEncoderDecodert

Function TestProtoEncoderDecodert

runtime/marshal_proto_test.go:63–91  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestProtoEncoderDecodert(t *testing.T) {
64 marshaller := runtime.ProtoMarshaller{}
65
66 var buf bytes.Buffer
67
68 encoder := marshaller.NewEncoder(&buf)
69 decoder := marshaller.NewDecoder(&buf)
70
71 // Encode
72 err := encoder.Encode(message)
73 if err != nil {
74 t.Fatalf("Encoding returned error: %s", err.Error())
75 }
76
77 // Decode
78 unencoded := &examplepb.ABitOfEverything{}
79 err = decoder.Decode(unencoded)
80 if err != nil {
81 t.Fatalf("Unmarshalling returned error: %s", err.Error())
82 }
83
84 if !proto.Equal(unencoded, message) {
85 t.Errorf(
86 "Unencoded didn't match original message: (original = %v) != (unencoded = %v)",
87 unencoded,
88 message,
89 )
90 }
91}

Callers

nothing calls this directly

Calls 5

NewEncoderMethod · 0.95
NewDecoderMethod · 0.95
EncodeMethod · 0.95
DecodeMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected