-
Notifications
You must be signed in to change notification settings - Fork 0
/
protoMarshallerMock.go
38 lines (30 loc) · 1.09 KB
/
protoMarshallerMock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package testscommon
import (
"fmt"
"github.com/bhagyaraj1208117/andes-abc-1/marshal"
)
var _ marshal.Marshalizer = (*ProtoMarshallerMock)(nil)
// ProtoMarshallerMock implements marshaling with protobuf
type ProtoMarshallerMock struct {
}
// Marshal does the actual serialization of an object
// The object to be serialized must implement the gogoProtoObj interface
func (pmm *ProtoMarshallerMock) Marshal(obj interface{}) ([]byte, error) {
if msg, ok := obj.(marshal.GogoProtoObj); ok {
return msg.Marshal()
}
return nil, fmt.Errorf("%T, %w", obj, marshal.ErrMarshallingProto)
}
// Unmarshal does the actual deserialization of an object
// The object to be deserialized must implement the gogoProtoObj interface
func (pmm *ProtoMarshallerMock) Unmarshal(obj interface{}, buff []byte) error {
if msg, ok := obj.(marshal.GogoProtoObj); ok {
msg.Reset()
return msg.Unmarshal(buff)
}
return fmt.Errorf("%T, %w", obj, marshal.ErrUnmarshallingProto)
}
// IsInterfaceNil returns true if there is no value under the interface
func (pmm *ProtoMarshallerMock) IsInterfaceNil() bool {
return pmm == nil
}