serializer

package module
v2.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0, BSD-2-Clause Imports: 11 Imported by: 81

Documentation

Index

Constants

View Source
const (
	// OneByte is the byte size of a single byte.
	OneByte = 1
	// Int16ByteSize is the byte size of an int16.
	Int16ByteSize = 2
	// UInt16ByteSize is the byte size of a uint16.
	UInt16ByteSize = 2
	// Int32ByteSize is the byte size of an int32.
	Int32ByteSize = 4
	// UInt32ByteSize is the byte size of a uint32.
	UInt32ByteSize = 4
	// Float32ByteSize is the byte size of a float32.
	Float32ByteSize = 4
	// Int64ByteSize is the byte size of an int64.
	Int64ByteSize = 8
	// UInt64ByteSize is the byte size of an uint64.
	UInt64ByteSize = 8
	// UInt256ByteSize is the byte size of an uint256.
	UInt256ByteSize = 32
	// Float64ByteSize is the byte size of a float64.
	Float64ByteSize = 8
	// TypeDenotationByteSize is the size of a type denotation.
	TypeDenotationByteSize = UInt32ByteSize
	// SmallTypeDenotationByteSize is the size of a type denotation for a small range of possible values.
	SmallTypeDenotationByteSize = OneByte
	// PayloadLengthByteSize is the size of the payload length denoting bytes.
	PayloadLengthByteSize = UInt32ByteSize
	// MinPayloadByteSize is the minimum size of a payload (together with its length denotation).
	MinPayloadByteSize = UInt32ByteSize + OneByte
)

Variables

View Source
var (
	// ErrInvalidBytes gets returned when data is invalid for deserialization.
	ErrInvalidBytes = errors.New("invalid bytes")
	// ErrDeserializationTypeMismatch gets returned when a denoted type for a given object is mismatched.
	// For example, while trying to deserialize a signature unlock block, a reference unlock block is seen.
	ErrDeserializationTypeMismatch = errors.New("data type is invalid for deserialization")
	// ErrUnknownArrayValidationMode gets returned for unknown array validation modes.
	ErrUnknownArrayValidationMode = errors.New("unknown array validation mode")
	// ErrArrayValidationMinElementsNotReached gets returned if the count of elements is too small.
	ErrArrayValidationMinElementsNotReached = errors.New("min count of elements within the array not reached")
	// ErrArrayValidationMaxElementsExceeded gets returned if the count of elements is too big.
	ErrArrayValidationMaxElementsExceeded = errors.New("max count of elements within the array exceeded")
	// ErrArrayValidationViolatesUniqueness gets returned if the array elements are not unique.
	ErrArrayValidationViolatesUniqueness = errors.New("array elements must be unique")
	// ErrArrayValidationViolatesTypeUniqueness gets returned if the array contains the same type multiple times.
	ErrArrayValidationViolatesTypeUniqueness = errors.New("array elements must be of a unique type")
	// ErrArrayValidationOrderViolatesLexicalOrder gets returned if the array elements are not in lexical order.
	ErrArrayValidationOrderViolatesLexicalOrder = errors.New("array elements must be in their lexical order (byte wise)")
	// ErrArrayValidationTypesNotOccurred gets returned if not all types as specified in an ArrayRules.MustOccur are in an array.
	ErrArrayValidationTypesNotOccurred = errors.New("not all needed types are present")
	// ErrDeserializationNotEnoughData gets returned if there is not enough data available to deserialize a given object.
	ErrDeserializationNotEnoughData = errors.New("not enough data for deserialization")
	// ErrDeserializationInvalidBoolValue gets returned when a bool value is tried to be read but it is neither 0 or 1.
	ErrDeserializationInvalidBoolValue = errors.New("invalid bool value")
	// ErrDeserializationLengthInvalid gets returned if a length denotation exceeds a specified limit.
	ErrDeserializationLengthInvalid = errors.New("length denotation invalid")
	// ErrDeserializationNotAllConsumed gets returned if not all bytes were consumed during deserialization of a given type.
	ErrDeserializationNotAllConsumed = errors.New("not all data has been consumed but should have been")
	// ErrUint256NumNegative gets returned if a supposed uint256 has a sign bit.
	ErrUint256NumNegative = errors.New("uint256 is negative")
	// ErrSliceLengthTooShort gets returned if a slice is less than a min length.
	ErrSliceLengthTooShort = errors.New("slice length is too short")
	// ErrSliceLengthTooLong gets returned if a slice exceeds a max length.
	ErrSliceLengthTooLong = errors.New("slice length is too long")
	// ErrStringTooShort gets returned if a string is less than a min length.
	ErrStringTooShort = errors.New("string is too short")
	// ErrStringTooLong gets returned if a string exceeds a max length.
	ErrStringTooLong = errors.New("string is too long")
	// ErrUint256TooBig gets returned when a supposed uint256 big.Int value is more than 32 bytes in size.
	ErrUint256TooBig = errors.New("uint256 big int is too big")
	// ErrUint256Nil gets returned when a uint256 *big.Int is nil.
	ErrUint256Nil = errors.New("uint256 must not be nil")
)

Functions

func CheckExactByteLength

func CheckExactByteLength(exact int, length int) error

CheckExactByteLength checks that the given length equals exact.

func CheckMinByteLength

func CheckMinByteLength(min int, length int) error

CheckMinByteLength checks that length is min. min.

func CheckType

func CheckType(data []byte, shouldType uint32) error

CheckType checks that the denoted type equals the shouldType.

func CheckTypeByte

func CheckTypeByte(data []byte, shouldType byte) error

CheckTypeByte checks that the denoted type byte equals the shouldType.

Types

type ArrayOf12Bytes

type ArrayOf12Bytes = [12]byte

ArrayOf12Bytes is an array of 12 bytes.

type ArrayOf20Bytes

type ArrayOf20Bytes = [20]byte

ArrayOf20Bytes is an array of 20 bytes.

type ArrayOf32Bytes

type ArrayOf32Bytes = [32]byte

ArrayOf32Bytes is an array of 32 bytes.

type ArrayOf38Bytes

type ArrayOf38Bytes = [38]byte

ArrayOf38Bytes is an array of 38 bytes.

type ArrayOf49Bytes

type ArrayOf49Bytes = [49]byte

ArrayOf49Bytes is an array of 49 bytes.

type ArrayOf64Bytes

type ArrayOf64Bytes = [64]byte

ArrayOf64Bytes is an array of 64 bytes.

type ArrayRules

type ArrayRules struct {
	// The min array bound.
	Min uint
	// The max array bound.
	Max uint
	// A map of types which must occur within the array.
	MustOccur TypePrefixes
	// The guards applied while de/serializing Serializables.
	Guards SerializableGuard
	// The mode of validation.
	ValidationMode ArrayValidationMode
	// The slice reduction function for uniqueness checks.
	UniquenessSliceFunc ElementUniquenessSliceFunc
}

ArrayRules defines rules around a to be deserialized array. Min and Max at 0 define an unbounded array.

func (*ArrayRules) AtMostOneOfEachTypeValidator

func (ar *ArrayRules) AtMostOneOfEachTypeValidator(typeDenotation TypeDenotationType) ElementValidationFunc

AtMostOneOfEachTypeValidator returns an ElementValidationFunc which returns an error if a given type occurs multiple times within the array.

func (*ArrayRules) CheckBounds

func (ar *ArrayRules) CheckBounds(count uint) error

CheckBounds checks whether the given count violates the array bounds.

func (*ArrayRules) ElementUniqueValidator

func (ar *ArrayRules) ElementUniqueValidator() ElementValidationFunc

ElementUniqueValidator returns an ElementValidationFunc which returns an error if the given element is not unique.

func (*ArrayRules) ElementValidationFunc

func (ar *ArrayRules) ElementValidationFunc() ElementValidationFunc

ElementValidationFunc returns a new ElementValidationFunc according to the given mode.

func (*ArrayRules) LexicalOrderValidator

func (ar *ArrayRules) LexicalOrderValidator() ElementValidationFunc

LexicalOrderValidator returns an ElementValidationFunc which returns an error if the given byte slices are not ordered lexicographically.

func (*ArrayRules) LexicalOrderWithoutDupsValidator

func (ar *ArrayRules) LexicalOrderWithoutDupsValidator() ElementValidationFunc

LexicalOrderWithoutDupsValidator returns an ElementValidationFunc which returns an error if the given byte slices are not ordered lexicographically or any elements are duplicated.

type ArrayValidationMode

type ArrayValidationMode byte

ArrayValidationMode defines the mode of array validation.

const (
	// ArrayValidationModeNone instructs the array validation to perform no validation.
	ArrayValidationModeNone ArrayValidationMode = 0
	// ArrayValidationModeNoDuplicates instructs the array validation to check for duplicates.
	ArrayValidationModeNoDuplicates ArrayValidationMode = 1 << 0
	// ArrayValidationModeLexicalOrdering instructs the array validation to check for lexical order.
	ArrayValidationModeLexicalOrdering ArrayValidationMode = 1 << 1
	// ArrayValidationModeAtMostOneOfEachTypeByte instructs the array validation to allow a given type prefix byte to occur only once in the array.
	ArrayValidationModeAtMostOneOfEachTypeByte ArrayValidationMode = 1 << 2
	// ArrayValidationModeAtMostOneOfEachTypeUint32 instructs the array validation to allow a given type prefix uint32 to occur only once in the array.
	ArrayValidationModeAtMostOneOfEachTypeUint32 ArrayValidationMode = 1 << 3
)

func (ArrayValidationMode) HasMode

func (av ArrayValidationMode) HasMode(mode ArrayValidationMode) bool

HasMode checks whether the array element validation mode includes the given mode.

type DeSerializationMode

type DeSerializationMode byte

DeSerializationMode defines the mode of de/serialization.

const (
	// DeSeriModeNoValidation instructs de/serialization to perform no validation.
	DeSeriModeNoValidation DeSerializationMode = 0
	// DeSeriModePerformValidation instructs de/serialization to perform validation.
	DeSeriModePerformValidation DeSerializationMode = 1 << 0
	// DeSeriModePerformLexicalOrdering instructs de/deserialization to automatically perform ordering of
	// certain arrays by their lexical serialized form.
	DeSeriModePerformLexicalOrdering DeSerializationMode = 1 << 1
)

func (DeSerializationMode) HasMode

func (sm DeSerializationMode) HasMode(mode DeSerializationMode) bool

HasMode checks whether the de/serialization mode includes the given mode.

type DeserializeFunc

type DeserializeFunc func(b []byte) (bytesRead int, err error)

DeserializeFunc is a function that reads bytes from b and returns how much bytes was read.

type Deserializer

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

Deserializer is a utility to deserialize bytes.

func NewDeserializer

func NewDeserializer(src []byte) *Deserializer

NewDeserializer creates a new Deserializer.

func (*Deserializer) AbortIf

func (d *Deserializer) AbortIf(errProducer ErrProducer) *Deserializer

AbortIf calls the given ErrProducer if the Deserializer did not encounter an error yet. Return nil from the ErrProducer to indicate continuation of the deserialization.

func (*Deserializer) CheckTypePrefix

func (d *Deserializer) CheckTypePrefix(prefix uint32, prefixType TypeDenotationType, errProducer ErrProducer) *Deserializer

CheckTypePrefix checks whether the type prefix corresponds to the expected given prefix. This function will advance the deserializer by the given TypeDenotationType length.

func (*Deserializer) ConsumedAll

func (d *Deserializer) ConsumedAll(errProducer ErrProducerWithLeftOver) *Deserializer

ConsumedAll calls the given ErrProducerWithLeftOver if not all bytes have been consumed from the Deserializer's src.

func (*Deserializer) Do

func (d *Deserializer) Do(f func()) *Deserializer

Do calls f in the Deserializer chain.

func (*Deserializer) Done

func (d *Deserializer) Done() (int, error)

Done finishes the Deserializer by returning the read bytes and occurred errors.

func (*Deserializer) GetObjectType

func (d *Deserializer) GetObjectType(typeDen TypeDenotationType) (uint32, error)

GetObjectType reads object type but doesn't change the offset.

func (*Deserializer) ReadArrayOf12Bytes

func (d *Deserializer) ReadArrayOf12Bytes(arr *ArrayOf12Bytes, errProducer ErrProducer) *Deserializer

ReadArrayOf12Bytes reads an array of 12 bytes.

func (*Deserializer) ReadArrayOf20Bytes

func (d *Deserializer) ReadArrayOf20Bytes(arr *ArrayOf20Bytes, errProducer ErrProducer) *Deserializer

ReadArrayOf20Bytes reads an array of 20 bytes.

func (*Deserializer) ReadArrayOf32Bytes

func (d *Deserializer) ReadArrayOf32Bytes(arr *ArrayOf32Bytes, errProducer ErrProducer) *Deserializer

ReadArrayOf32Bytes reads an array of 32 bytes.

func (*Deserializer) ReadArrayOf38Bytes

func (d *Deserializer) ReadArrayOf38Bytes(arr *ArrayOf38Bytes, errProducer ErrProducer) *Deserializer

ReadArrayOf38Bytes reads an array of 38 bytes.

func (*Deserializer) ReadArrayOf49Bytes

func (d *Deserializer) ReadArrayOf49Bytes(arr *ArrayOf49Bytes, errProducer ErrProducer) *Deserializer

ReadArrayOf49Bytes reads an array of 49 bytes.

func (*Deserializer) ReadArrayOf64Bytes

func (d *Deserializer) ReadArrayOf64Bytes(arr *ArrayOf64Bytes, errProducer ErrProducer) *Deserializer

ReadArrayOf64Bytes reads an array of 64 bytes.

func (*Deserializer) ReadBool

func (d *Deserializer) ReadBool(dest *bool, errProducer ErrProducer) *Deserializer

ReadBool reads a bool into dest.

func (*Deserializer) ReadByte

func (d *Deserializer) ReadByte(dest *byte, errProducer ErrProducer) *Deserializer

ReadByte reads a byte into dest.

func (*Deserializer) ReadBytes

func (d *Deserializer) ReadBytes(slice *[]byte, numBytes int, errProducer ErrProducer) *Deserializer

ReadBytes reads specified number of bytes. Use this function only to read fixed size slices/arrays, otherwise use ReadVariableByteSlice instead.

func (*Deserializer) ReadBytesInPlace

func (d *Deserializer) ReadBytesInPlace(slice []byte, errProducer ErrProducer) *Deserializer

ReadBytesInPlace reads slice length amount of bytes into slice. Use this function only to read arrays.

func (*Deserializer) ReadNum

func (d *Deserializer) ReadNum(dest any, errProducer ErrProducer) *Deserializer

ReadNum reads a number into dest.

func (*Deserializer) ReadObject

func (d *Deserializer) ReadObject(target interface{}, deSeriMode DeSerializationMode, deSeriCtx interface{}, typeDen TypeDenotationType, serSel SerializableReadGuardFunc, errProducer ErrProducer) *Deserializer

ReadObject reads an object, using the given SerializableReadGuardFunc.

func (*Deserializer) ReadPayload

func (d *Deserializer) ReadPayload(s interface{}, deSeriMode DeSerializationMode, deSeriCtx interface{}, sel SerializableReadGuardFunc, errProducer ErrProducer) *Deserializer

ReadPayload reads a payload.

func (*Deserializer) ReadPayloadLength

func (d *Deserializer) ReadPayloadLength() (uint32, error)

ReadPayloadLength reads the payload length from the deserializer.

func (*Deserializer) ReadSequenceOfObjects

func (d *Deserializer) ReadSequenceOfObjects(
	itemDeserializer DeserializeFunc, deSeriMode DeSerializationMode,
	lenType SeriLengthPrefixType, arrayRules *ArrayRules, errProducer ErrProducer,
) *Deserializer

ReadSequenceOfObjects reads a sequence of objects and calls DeserializeFunc for evey encountered item.

func (*Deserializer) ReadSliceOfArraysOf32Bytes

func (d *Deserializer) ReadSliceOfArraysOf32Bytes(slice *SliceOfArraysOf32Bytes, deSeriMode DeSerializationMode, lenType SeriLengthPrefixType, arrayRules *ArrayRules, errProducer ErrProducer) *Deserializer

ReadSliceOfArraysOf32Bytes reads a slice of arrays of 32 bytes.

func (*Deserializer) ReadSliceOfArraysOf64Bytes

func (d *Deserializer) ReadSliceOfArraysOf64Bytes(slice *SliceOfArraysOf64Bytes, deSeriMode DeSerializationMode, lenType SeriLengthPrefixType, arrayRules *ArrayRules, errProducer ErrProducer) *Deserializer

ReadSliceOfArraysOf64Bytes reads a slice of arrays of 64 bytes.

func (*Deserializer) ReadSliceOfObjects

func (d *Deserializer) ReadSliceOfObjects(
	target interface{}, deSeriMode DeSerializationMode, deSeriCtx interface{}, lenType SeriLengthPrefixType,
	typeDen TypeDenotationType, arrayRules *ArrayRules, errProducer ErrProducer,
) *Deserializer

ReadSliceOfObjects reads a slice of objects.

func (*Deserializer) ReadString

func (d *Deserializer) ReadString(s *string, lenType SeriLengthPrefixType, errProducer ErrProducer, minLen int, maxLen int) *Deserializer

ReadString reads a string.

func (*Deserializer) ReadTime

func (d *Deserializer) ReadTime(dest *time.Time, errProducer ErrProducer) *Deserializer

ReadTime reads a Time value from the internal buffer.

func (*Deserializer) ReadUint256

func (d *Deserializer) ReadUint256(dest **big.Int, errProducer ErrProducer) *Deserializer

ReadUint256 reads a little endian encoded uint256 into dest.

func (*Deserializer) ReadVariableByteSlice

func (d *Deserializer) ReadVariableByteSlice(slice *[]byte, lenType SeriLengthPrefixType, errProducer ErrProducer, minLen int, maxLen int) *Deserializer

ReadVariableByteSlice reads a variable byte slice which is denoted by the given SeriLengthPrefixType.

func (*Deserializer) RemainingBytes

func (d *Deserializer) RemainingBytes() []byte

func (*Deserializer) Skip

func (d *Deserializer) Skip(skip int, errProducer ErrProducer) *Deserializer

Skip skips the number of bytes during deserialization.

func (*Deserializer) WithValidation

func (d *Deserializer) WithValidation(deSeriMode DeSerializationMode, errProducer ErrProducerWithRWBytes) *Deserializer

WithValidation runs errProducer if deSeriMode has DeSeriModePerformValidation.

type ElementUniquenessSliceFunc

type ElementUniquenessSliceFunc func(next []byte) []byte

ElementUniquenessSliceFunc is a function which takes a byte slice and reduces it to the part which is deemed relevant for uniqueness checks. If this function is used in conjunction with ArrayValidationModeLexicalOrdering, then the reduction must only reduce the slice from index 0 onwards, as otherwise lexical ordering on the set elements can not be enforced.

type ElementValidationFunc

type ElementValidationFunc func(index int, next []byte) error

ElementValidationFunc is a function which runs during array validation (e.g. lexical ordering).

type ErrProducer

type ErrProducer func(err error) error

ErrProducer might produce an error.

type ErrProducerWithLeftOver

type ErrProducerWithLeftOver func(left int, err error) error

ErrProducerWithLeftOver might produce an error and is called with the bytes left to read.

type ErrProducerWithRWBytes

type ErrProducerWithRWBytes func(read []byte, err error) error

ErrProducerWithRWBytes might produce an error and is called with the currently read or written bytes.

type LexicalOrdered32ByteArrays

type LexicalOrdered32ByteArrays [][32]byte

LexicalOrdered32ByteArrays are 32 byte arrays ordered in lexical order.

func (LexicalOrdered32ByteArrays) Len

func (LexicalOrdered32ByteArrays) Less

func (l LexicalOrdered32ByteArrays) Less(i, j int) bool

func (LexicalOrdered32ByteArrays) Swap

func (l LexicalOrdered32ByteArrays) Swap(i, j int)

type LexicalOrderedByteSlices

type LexicalOrderedByteSlices [][]byte

LexicalOrderedByteSlices are byte slices ordered in lexical order.

func (LexicalOrderedByteSlices) Len

func (l LexicalOrderedByteSlices) Len() int

func (LexicalOrderedByteSlices) Less

func (l LexicalOrderedByteSlices) Less(i, j int) bool

func (LexicalOrderedByteSlices) Swap

func (l LexicalOrderedByteSlices) Swap(i, j int)

type ReadObjectConsumerFunc

type ReadObjectConsumerFunc func(seri Serializable)

ReadObjectConsumerFunc gets called after an object has been deserialized from a Deserializer.

type ReadObjectsConsumerFunc

type ReadObjectsConsumerFunc func(seri Serializables)

ReadObjectsConsumerFunc gets called after objects have been deserialized from a Deserializer.

type SeriLengthPrefixType

type SeriLengthPrefixType byte

SeriLengthPrefixType defines the type of the value denoting the length of a collection.

const (
	// SeriLengthPrefixTypeAsByte defines a collection length to be denoted by a byte.
	SeriLengthPrefixTypeAsByte SeriLengthPrefixType = iota
	// SeriLengthPrefixTypeAsUint16 defines a collection length to be denoted by a uint16.
	SeriLengthPrefixTypeAsUint16
	// SeriLengthPrefixTypeAsUint32 defines a collection length to be denoted by a uint32.
	SeriLengthPrefixTypeAsUint32
)

type Serializable

type Serializable interface {
	json.Marshaler
	json.Unmarshaler
	// Deserialize deserializes the given data (by copying) into the object and returns the amount of bytes consumed from data.
	// If the passed data is not big enough for deserialization, an error must be returned.
	// During deserialization additional validation may be performed if the given modes are set.
	Deserialize(data []byte, deSeriMode DeSerializationMode, deSeriCtx interface{}) (int, error)
	// Serialize returns a serialized byte representation.
	// During serialization additional validation may be performed if the given modes are set.
	Serialize(deSeriMode DeSerializationMode, deSeriCtx interface{}) ([]byte, error)
}

Serializable is something which knows how to serialize/deserialize itself from/into bytes while also performing syntactical checks on the written/read data.

type SerializableGuard

type SerializableGuard struct {
	// The read guard applied before reading an entire object.
	ReadGuard SerializableReadGuardFunc
	// The read guard applied after an object has been read.
	PostReadGuard SerializablePostReadGuardFunc
	// The write guard applied when writing objects.
	WriteGuard SerializableWriteGuardFunc
}

SerializableGuard defines the guards to de/serialize Serializable.

type SerializablePostReadGuardFunc

type SerializablePostReadGuardFunc func(seri Serializable) error

SerializablePostReadGuardFunc is a function which inspects the read Serializable add runs additional validation against it.

type SerializableReadGuardFunc

type SerializableReadGuardFunc func(ty uint32) (Serializable, error)

SerializableReadGuardFunc is a function that given a type prefix, returns an empty instance of the given underlying type. If the type doesn't resolve or is not supported in the deserialization context, an error is returned.

type SerializableSlice

type SerializableSlice interface {
	// ToSerializables returns the representation of the slice as a Serializables.
	ToSerializables() Serializables
	// FromSerializables updates the slice itself with the given Serializables.
	FromSerializables(seris Serializables)
}

SerializableSlice is a slice of a type which can convert itself to Serializables.

type SerializableWithSize

type SerializableWithSize interface {
	Serializable
	// Size returns the size of the serialized object
	Size() int
}

SerializableWithSize implements Serializable interface and has the extra functionality of returning the size of the resulting serialized object (ideally without actually serializing it).

type SerializableWriteGuardFunc

type SerializableWriteGuardFunc func(seri Serializable) error

SerializableWriteGuardFunc is a function that given a Serializable, tells whether the given type is allowed to be serialized.

type Serializables

type Serializables []Serializable

Serializables is a slice of Serializable.

type Serializer

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

Serializer is a utility to serialize bytes.

func NewSerializer

func NewSerializer() *Serializer

NewSerializer creates a new Serializer.

func (*Serializer) AbortIf

func (s *Serializer) AbortIf(errProducer ErrProducer) *Serializer

AbortIf calls the given ErrProducer if the Serializer did not encounter an error yet. Return nil from the ErrProducer to indicate continuation of the serialization.

func (*Serializer) Do

func (s *Serializer) Do(f func()) *Serializer

Do calls f in the Serializer chain.

func (*Serializer) Serialize

func (s *Serializer) Serialize() ([]byte, error)

Serialize finishes the serialization by returning the serialized bytes or an error if any intermediate step created one.

func (*Serializer) WithValidation

func (s *Serializer) WithValidation(deSeriMode DeSerializationMode, errProducer ErrProducerWithRWBytes) *Serializer

WithValidation runs errProducer if deSeriMode has DeSeriModePerformValidation.

func (*Serializer) Write32BytesArraySlice

func (s *Serializer) Write32BytesArraySlice(slice SliceOfArraysOf32Bytes, deSeriMode DeSerializationMode, lenType SeriLengthPrefixType, arrayRules *ArrayRules, errProducer ErrProducer) *Serializer

Write32BytesArraySlice writes a slice of arrays of 32 bytes to the Serializer.

func (*Serializer) Write64BytesArraySlice

func (s *Serializer) Write64BytesArraySlice(slice SliceOfArraysOf64Bytes, deSeriMode DeSerializationMode, lenType SeriLengthPrefixType, arrayRules *ArrayRules, errProducer ErrProducer) *Serializer

Write64BytesArraySlice writes a slice of arrays of 64 bytes to the Serializer.

func (*Serializer) WriteBool

func (s *Serializer) WriteBool(v bool, errProducer ErrProducer) *Serializer

WriteBool writes the given bool to the Serializer.

func (*Serializer) WriteByte

func (s *Serializer) WriteByte(data byte, errProducer ErrProducer) *Serializer

WriteByte writes the given byte to the Serializer.

func (*Serializer) WriteBytes

func (s *Serializer) WriteBytes(data []byte, errProducer ErrProducer) *Serializer

WriteBytes writes the given byte slice to the Serializer. Use this function only to write fixed size slices/arrays, otherwise use WriteVariableByteSlice instead.

func (*Serializer) WriteNum

func (s *Serializer) WriteNum(v interface{}, errProducer ErrProducer) *Serializer

WriteNum writes the given num v to the Serializer.

func (*Serializer) WriteObject

func (s *Serializer) WriteObject(seri Serializable, deSeriMode DeSerializationMode, deSeriCtx interface{}, guard SerializableWriteGuardFunc, errProducer ErrProducer) *Serializer

WriteObject writes the given Serializable to the Serializer.

func (*Serializer) WritePayload

func (s *Serializer) WritePayload(payload Serializable, deSeriMode DeSerializationMode, deSeriCtx interface{}, guard SerializableWriteGuardFunc, errProducer ErrProducer) *Serializer

WritePayload writes the given payload Serializable into the Serializer. This is different to WriteObject as it also writes the length denotation of the payload.

func (*Serializer) WritePayloadLength

func (s *Serializer) WritePayloadLength(length int, errProducer ErrProducer) *Serializer

WritePayloadLength write payload length token into serializer.

func (*Serializer) WriteSliceOfByteSlices

func (s *Serializer) WriteSliceOfByteSlices(data [][]byte, deSeriMode DeSerializationMode, lenType SeriLengthPrefixType, sliceRules *ArrayRules, errProducer ErrProducer) *Serializer

WriteSliceOfByteSlices writes slice of []byte into the Serializer.

func (*Serializer) WriteSliceOfObjects

func (s *Serializer) WriteSliceOfObjects(source interface{}, deSeriMode DeSerializationMode, deSeriCtx interface{}, lenType SeriLengthPrefixType, arrayRules *ArrayRules, errProducer ErrProducer) *Serializer

WriteSliceOfObjects writes Serializables into the Serializer. For every written Serializable, the given WrittenObjectConsumer is called if it isn't nil.

func (*Serializer) WriteString

func (s *Serializer) WriteString(str string, lenType SeriLengthPrefixType, errProducer ErrProducer, minLen int, maxLen int) *Serializer

WriteString writes the given string to the Serializer.

func (*Serializer) WriteTime

func (s *Serializer) WriteTime(timeToWrite time.Time, errProducer ErrProducer) *Serializer

WriteTime writes a marshaled Time value to the internal buffer.

func (*Serializer) WriteUint256

func (s *Serializer) WriteUint256(num *big.Int, errProducer ErrProducer) *Serializer

WriteUint256 writes the given *big.Int v representing an uint256 value to the Serializer.

func (*Serializer) WriteVariableByteSlice

func (s *Serializer) WriteVariableByteSlice(data []byte, lenType SeriLengthPrefixType, errProducer ErrProducer, minLen int, maxLen int) *Serializer

WriteVariableByteSlice writes the given slice with its length to the Serializer.

func (*Serializer) Written

func (s *Serializer) Written() int

Written returns the amount of bytes written into the Serializer.

type SliceOfArraysOf32Bytes

type SliceOfArraysOf32Bytes = []ArrayOf32Bytes

SliceOfArraysOf32Bytes is a slice of arrays of which each is 32 bytes.

func RemoveDupsAndSortByLexicalOrderArrayOf32Bytes

func RemoveDupsAndSortByLexicalOrderArrayOf32Bytes(slice SliceOfArraysOf32Bytes) SliceOfArraysOf32Bytes

RemoveDupsAndSortByLexicalOrderArrayOf32Bytes returns a new SliceOfArraysOf32Bytes sorted by lexical order and without duplicates.

type SliceOfArraysOf64Bytes

type SliceOfArraysOf64Bytes = []ArrayOf64Bytes

SliceOfArraysOf64Bytes is a slice of arrays of which each is 64 bytes.

type SortedSerializables

type SortedSerializables Serializables

SortedSerializables are Serializables sorted by their serialized form.

func (SortedSerializables) Len

func (ss SortedSerializables) Len() int

func (SortedSerializables) Less

func (ss SortedSerializables) Less(i, j int) bool

func (SortedSerializables) Swap

func (ss SortedSerializables) Swap(i, j int)

type TypeDenotationType

type TypeDenotationType byte

TypeDenotationType defines a type denotation.

const (
	// TypeDenotationUint32 defines a denotation which defines a type ID by a uint32.
	TypeDenotationUint32 TypeDenotationType = iota
	// TypeDenotationByte defines a denotation which defines a type ID by a byte.
	TypeDenotationByte
	// TypeDenotationNone defines that there is no type denotation.
	TypeDenotationNone
)

func (TypeDenotationType) String

func (i TypeDenotationType) String() string

type TypePrefixes

type TypePrefixes map[uint32]struct{}

TypePrefixes defines a set of type prefixes.

func (TypePrefixes) Subset

func (typePrefixes TypePrefixes) Subset(other TypePrefixes) bool

Subset checks whether every type prefix is a member of other.

Jump to

Keyboard shortcuts

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