MCPcopy Create free account
hub / github.com/DNAProject/DNA / EncodeValue

Function EncodeValue

vm/crossvm_codec/codec.go:80–112  ·  view source on GitHub ↗

currently only used by test case

(value interface{})

Source from the content-addressed store, hash-verified

78
79// currently only used by test case
80func EncodeValue(value interface{}) ([]byte, error) {
81 sink := common.NewZeroCopySink(nil)
82 switch val := value.(type) {
83 case []byte:
84 EncodeBytes(sink, val)
85 case string:
86 EncodeString(sink, val)
87 case common.Address:
88 EncodeAddress(sink, val)
89 case bool:
90 EncodeBool(sink, val)
91 case common.Uint256:
92 EncodeH256(sink, val)
93 case *big.Int:
94 err := EncodeBigInt(sink, val)
95 if err != nil {
96 return nil, err
97 }
98 case int:
99 EncodeInt128(sink, common.I128FromInt64(int64(val)))
100 case int64:
101 EncodeInt128(sink, common.I128FromInt64(val))
102 case []interface{}:
103 err := EncodeList(sink, val)
104 if err != nil {
105 return nil, err
106 }
107 default:
108 log.Warn("encode value: unsupported type:", reflect.TypeOf(val).String())
109 }
110
111 return sink.Bytes(), nil
112}
113
114func DecodeValue(source *common.ZeroCopySource) (interface{}, error) {
115 ty, eof := source.NextByte()

Callers 1

EncodeNotifyFunction · 0.85

Calls 13

BytesMethod · 0.95
NewZeroCopySinkFunction · 0.92
I128FromInt64Function · 0.92
WarnFunction · 0.92
EncodeBytesFunction · 0.85
EncodeStringFunction · 0.85
EncodeBoolFunction · 0.85
EncodeH256Function · 0.85
EncodeBigIntFunction · 0.85
EncodeInt128Function · 0.85
EncodeListFunction · 0.85
EncodeAddressFunction · 0.70

Tested by 1

EncodeNotifyFunction · 0.68