currently only used by test case
(value interface{})
| 78 | |
| 79 | // currently only used by test case |
| 80 | func 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 | |
| 114 | func DecodeValue(source *common.ZeroCopySource) (interface{}, error) { |
| 115 | ty, eof := source.NextByte() |