serialize

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2019 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

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 DeserializeFromBytes(b []byte, val interface{}) error

func DeserializeWithTags

func DeserializeWithTags(bb *ByteBuffer, val interface{}, ts Tags) error

func Serialize

func Serialize(w *[]byte, val interface{}) error

func SerializeStructWithout

func SerializeStructWithout(val reflect.Value, w *[]byte, excludeList map[string]bool) error

func SerializeToBytes

func SerializeToBytes(val interface{}) ([]byte, error)

SerializeToBytes returns the serialize result of val.

func SerializeWithTags

func SerializeWithTags(w *[]byte, val interface{}, ts Tags) error

Types

type BigUint

type BigUint struct {
	Value *big.Int
}

type ByteBuffer

type ByteBuffer struct {
	// contains filtered or unexported fields
}

func NewByteBuffer

func NewByteBuffer(bytes []byte) *ByteBuffer

func (*ByteBuffer) GetBytes

func (bb *ByteBuffer) GetBytes(size int) ([]byte, error)

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

func (*Uint128) Serialize

func (ui *Uint128) Serialize(w *[]byte) error

type Uint256

type Uint256 BigUint

func (*Uint256) Deserialize

func (ui *Uint256) Deserialize(bb *ByteBuffer) error

func (*Uint256) Serialize

func (ui *Uint256) Serialize(w *[]byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL