MCPcopy Create free account
hub / github.com/tendermint/tendermint / cdcEncode

Function cdcEncode

types/encoding_helper.go:11–47  ·  view source on GitHub ↗

cdcEncode returns nil if the input is nil, otherwise returns proto.Marshal( Value{Value: item})

(item interface{})

Source from the content-addressed store, hash-verified

9// cdcEncode returns nil if the input is nil, otherwise returns
10// proto.Marshal(<type>Value{Value: item})
11func cdcEncode(item interface{}) []byte {
12 if item != nil && !isTypedNil(item) && !isEmpty(item) {
13 switch item := item.(type) {
14 case string:
15 i := gogotypes.StringValue{
16 Value: item,
17 }
18 bz, err := i.Marshal()
19 if err != nil {
20 return nil
21 }
22 return bz
23 case int64:
24 i := gogotypes.Int64Value{
25 Value: item,
26 }
27 bz, err := i.Marshal()
28 if err != nil {
29 return nil
30 }
31 return bz
32 case bytes.HexBytes:
33 i := gogotypes.BytesValue{
34 Value: item,
35 }
36 bz, err := i.Marshal()
37 if err != nil {
38 return nil
39 }
40 return bz
41 default:
42 return nil
43 }
44 }
45
46 return nil
47}

Callers 2

TestHeaderHashFunction · 0.85
HashMethod · 0.85

Calls 3

isTypedNilFunction · 0.85
isEmptyFunction · 0.85
MarshalMethod · 0.45

Tested by 1

TestHeaderHashFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…