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

Function DecodeValue

vm/crossvm_codec/codec.go:114–196  ·  view source on GitHub ↗
(source *common.ZeroCopySource)

Source from the content-addressed store, hash-verified

112}
113
114func DecodeValue(source *common.ZeroCopySource) (interface{}, error) {
115 ty, eof := source.NextByte()
116 if eof {
117 return nil, ERROR_PARAM_FORMAT
118 }
119
120 switch ty {
121 case ByteArrayType:
122 size, eof := source.NextUint32()
123 if eof {
124 return nil, ERROR_PARAM_FORMAT
125 }
126
127 buf, eof := source.NextBytes(uint64(size))
128 if eof {
129 return nil, ERROR_PARAM_FORMAT
130 }
131
132 return buf, nil
133 case StringType:
134 size, eof := source.NextUint32()
135 if eof {
136 return nil, ERROR_PARAM_FORMAT
137 }
138
139 buf, eof := source.NextBytes(uint64(size))
140 if eof {
141 return nil, ERROR_PARAM_FORMAT
142 }
143
144 return string(buf), nil
145 case AddressType:
146 addr, eof := source.NextAddress()
147 if eof {
148 return nil, ERROR_PARAM_FORMAT
149 }
150
151 return addr, nil
152 case BooleanType:
153 by, irr, eof := source.NextBool()
154 if eof {
155 return nil, ERROR_PARAM_FORMAT
156 }
157
158 if irr {
159 return nil, ERROR_PARAM_FORMAT
160 }
161
162 return by, nil
163 case IntType:
164 val, eof := source.NextI128()
165 if eof {
166 return nil, ERROR_PARAM_FORMAT
167 }
168
169 return val.ToBigInt(), nil
170 case H256Type:
171 hash, eof := source.NextHash()

Callers 3

parseNotifyFunction · 0.85
DeserializeInputFunction · 0.85
DeserializeCallParamFunction · 0.85

Calls 8

NextByteMethod · 0.80
NextUint32Method · 0.80
NextAddressMethod · 0.80
NextBoolMethod · 0.80
NextI128Method · 0.80
NextHashMethod · 0.80
NextBytesMethod · 0.45
ToBigIntMethod · 0.45

Tested by

no test coverage detected