Documentation ¶
Index ¶
- func Deserialize(bb *ByteBuffer, val interface{}) error
- func DeserializeFromBytes(b []byte, val interface{}) error
- func DeserializeWithTags(bb *ByteBuffer, val interface{}, ts Tags) error
- func Serialize(w *[]byte, val interface{}) error
- func SerializeStructWithout(val reflect.Value, w *[]byte, excludeList map[string]bool) error
- func SerializeToBytes(val interface{}) ([]byte, error)
- func SerializeWithTags(w *[]byte, val interface{}, ts Tags) error
- type BigUint
- type ByteBuffer
- func (bb *ByteBuffer) GetBytes(size int) ([]byte, error)
- func (bb ByteBuffer) GetOffset() int
- func (bb *ByteBuffer) GetUInt16() (uint16, error)
- func (bb *ByteBuffer) GetUInt32() (uint32, error)
- func (bb *ByteBuffer) GetUInt64() (uint64, error)
- func (bb *ByteBuffer) GetUInt8() (uint8, error)
- func (bb *ByteBuffer) GetVarBytes(byteSizeOfSliceLen int) ([]byte, error)
- func (bb *ByteBuffer) Remaining() int
- type Serializable
- type Tags
- type Uint128
- type Uint256
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deserialize ¶
func Deserialize(bb *ByteBuffer, val interface{}) error
Example ¶
input, _ := hex.DecodeString("010a0000001400000006666F6F626172") type example struct { A uint B uint32 private uint // private fields are Ignored String string } var s example err := Deserialize(&ByteBuffer{input, 0}, &s) if err != nil { fmt.Printf("Error: %v\n", err) } else { fmt.Printf("Deserialized value: %#v\n", s) }
Output: Deserialized value: serialize.example{A:0xa, B:0x14, private:0x0, String:"foobar"}
Example (StructTagNil) ¶
// In this example, we'll use the "nil" struct tag to change // how a pointer-typed field is deserialized. The input contains an RLP // list of one element, an empty string. input := []byte{0x00} // This type uses the normal rules. // The empty input string is deserialized as a pointer to an empty Go string. var normalRules struct { String *[]byte } Deserialize(&ByteBuffer{input, 0}, &normalRules) fmt.Printf("normal: String = %v\n", *normalRules.String) // This type uses the struct tag. // The empty input string is deserialized as a nil pointer. var withEmptyOK struct { String *[]byte `ser:"nil"` } Deserialize(&ByteBuffer{input, 0}, &withEmptyOK) fmt.Printf("with nil tag: String = %v\n", withEmptyOK.String)
Output: normal: String = [] with nil tag: String = <nil>
Example (StructTagNilAndIgnore) ¶
// In this example, we'll use the "nil" struct tag to change // how a pointer-typed field is deserialized. The input contains an RLP // list of one element, an empty string. input := []byte{0x00, 0x01, 0x03, 0x04, 0x05, 0x06} s := new(structForTest) Deserialize(&ByteBuffer{input, 0}, &s) fmt.Printf("From = %v\n", *s.From) fmt.Printf("To = %v\n", *s.To)
Output: From = [] To = [4 5 6]
func DeserializeFromBytes ¶
func DeserializeWithTags ¶
func DeserializeWithTags(bb *ByteBuffer, val interface{}, ts Tags) error
func SerializeStructWithout ¶
func SerializeToBytes ¶
SerializeToBytes returns the serialize result of val.
func SerializeWithTags ¶
Types ¶
type ByteBuffer ¶
type ByteBuffer struct {
// contains filtered or unexported fields
}
func NewByteBuffer ¶
func NewByteBuffer(bytes []byte) *ByteBuffer
func (ByteBuffer) GetOffset ¶
func (bb ByteBuffer) GetOffset() int
func (*ByteBuffer) GetUInt16 ¶
func (bb *ByteBuffer) GetUInt16() (uint16, error)
func (*ByteBuffer) GetUInt32 ¶
func (bb *ByteBuffer) GetUInt32() (uint32, error)
func (*ByteBuffer) GetUInt64 ¶
func (bb *ByteBuffer) GetUInt64() (uint64, error)
func (*ByteBuffer) GetUInt8 ¶
func (bb *ByteBuffer) GetUInt8() (uint8, error)
func (*ByteBuffer) GetVarBytes ¶
func (bb *ByteBuffer) GetVarBytes(byteSizeOfSliceLen int) ([]byte, error)
func (*ByteBuffer) Remaining ¶
func (bb *ByteBuffer) Remaining() int
type Serializable ¶
type Serializable interface { Serialize(w *[]byte) error Deserialize(bb *ByteBuffer) error }
type Tags ¶
type Tags struct { // ser:"nil" controls whether empty input results in a nil pointer. NilOK bool // ser:"-" ignores fields. Ignored bool // bytesizeofslicelen: number ByteSizeOfSliceLen int }
represents struct Tags
type Uint128 ¶
type Uint128 BigUint
func (*Uint128) Deserialize ¶
func (ui *Uint128) Deserialize(bb *ByteBuffer) error
Click to show internal directories.
Click to hide internal directories.