-
Notifications
You must be signed in to change notification settings - Fork 198
/
protoMarshalizerMock.go
38 lines (30 loc) · 1.1 KB
/
protoMarshalizerMock.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/ElrondNetwork/elrond-go-core/marshal"
)
var _ marshal.Marshalizer = (*ProtoMarshalizerMock)(nil)
// ProtoMarshalizerMock implements marshaling with protobuf
type ProtoMarshalizerMock struct {
}
// Marshal does the actual serialization of an object
// The object to be serialized must implement the gogoProtoObj interface
func (pmm *ProtoMarshalizerMock) 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 *ProtoMarshalizerMock) 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 *ProtoMarshalizerMock) IsInterfaceNil() bool {
return pmm == nil
}