Documentation ¶
Index ¶
- Constants
- Variables
- func CheckExactByteLength(exact int, length int) error
- func CheckMinByteLength(min int, length int) error
- func CheckType(data []byte, shouldType uint32) error
- func CheckTypeByte(data []byte, shouldType byte) error
- type ArrayOf12Bytes
- type ArrayOf20Bytes
- type ArrayOf32Bytes
- type ArrayOf38Bytes
- type ArrayOf49Bytes
- type ArrayOf64Bytes
- type ArrayRules
- func (ar *ArrayRules) AtMostOneOfEachTypeValidator(typeDenotation TypeDenotationType) ElementValidationFunc
- func (ar *ArrayRules) CheckBounds(count uint) error
- func (ar *ArrayRules) ElementUniqueValidator() ElementValidationFunc
- func (ar *ArrayRules) ElementValidationFunc() ElementValidationFunc
- func (ar *ArrayRules) LexicalOrderValidator() ElementValidationFunc
- func (ar *ArrayRules) LexicalOrderWithoutDupsValidator() ElementValidationFunc
- type ArrayValidationMode
- type Byter
- type DeSerializationMode
- type DeserializeFunc
- type Deserializer
- func (d *Deserializer) AbortIf(errProducer ErrProducer) *Deserializer
- func (d *Deserializer) CheckTypePrefix(prefix uint32, prefixType TypeDenotationType, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ConsumedAll(errProducer ErrProducerWithLeftOver) *Deserializer
- func (d *Deserializer) Do(f func()) *Deserializer
- func (d *Deserializer) Done() (int, error)
- func (d *Deserializer) GetObjectType(typeDen TypeDenotationType) (uint32, error)
- func (d *Deserializer) ReadArrayOf12Bytes(arr *ArrayOf12Bytes, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadArrayOf20Bytes(arr *ArrayOf20Bytes, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadArrayOf32Bytes(arr *ArrayOf32Bytes, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadArrayOf38Bytes(arr *ArrayOf38Bytes, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadArrayOf49Bytes(arr *ArrayOf49Bytes, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadArrayOf64Bytes(arr *ArrayOf64Bytes, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadBool(dest *bool, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadByte(dest *byte, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadBytes(slice *[]byte, numBytes int, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadBytesInPlace(slice []byte, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadNum(dest any, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadObject(target interface{}, deSeriMode DeSerializationMode, deSeriCtx interface{}, ...) *Deserializer
- func (d *Deserializer) ReadPayload(s interface{}, deSeriMode DeSerializationMode, deSeriCtx interface{}, ...) *Deserializer
- func (d *Deserializer) ReadPayloadLength() (uint32, error)
- func (d *Deserializer) ReadSequenceOfObjects(itemDeserializer DeserializeFunc, deSeriMode DeSerializationMode, ...) *Deserializer
- func (d *Deserializer) ReadSliceOfArraysOf32Bytes(slice *SliceOfArraysOf32Bytes, deSeriMode DeSerializationMode, ...) *Deserializer
- func (d *Deserializer) ReadSliceOfArraysOf64Bytes(slice *SliceOfArraysOf64Bytes, deSeriMode DeSerializationMode, ...) *Deserializer
- func (d *Deserializer) ReadSliceOfObjects(target interface{}, deSeriMode DeSerializationMode, deSeriCtx interface{}, ...) *Deserializer
- func (d *Deserializer) ReadString(s *string, lenType SeriLengthPrefixType, errProducer ErrProducer, minLen int, ...) *Deserializer
- func (d *Deserializer) ReadTime(dest *time.Time, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadUint256(dest **big.Int, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) ReadVariableByteSlice(slice *[]byte, lenType SeriLengthPrefixType, errProducer ErrProducer, ...) *Deserializer
- func (d *Deserializer) RemainingBytes() []byte
- func (d *Deserializer) Skip(skip int, errProducer ErrProducer) *Deserializer
- func (d *Deserializer) WithValidation(deSeriMode DeSerializationMode, errProducer ErrProducerWithRWBytes) *Deserializer
- type ElementUniquenessSliceFunc
- type ElementValidationFunc
- type ErrProducer
- type ErrProducerWithLeftOver
- type ErrProducerWithRWBytes
- type FromByter
- type LexicalOrdered32ByteArrays
- type LexicalOrderedByteSlices
- type MarshalablePtr
- type ReadObjectConsumerFunc
- type ReadObjectsConsumerFunc
- type SeriLengthPrefixType
- type Serializable
- type SerializableGuard
- type SerializablePostReadGuardFunc
- type SerializableReadGuardFunc
- type SerializableSlice
- type SerializableWithSize
- type SerializableWriteGuardFunc
- type Serializables
- type Serializer
- func (s *Serializer) AbortIf(errProducer ErrProducer) *Serializer
- func (s *Serializer) Do(f func()) *Serializer
- func (s *Serializer) Serialize() ([]byte, error)
- func (s *Serializer) WithValidation(deSeriMode DeSerializationMode, errProducer ErrProducerWithRWBytes) *Serializer
- func (s *Serializer) Write32BytesArraySlice(slice SliceOfArraysOf32Bytes, deSeriMode DeSerializationMode, ...) *Serializer
- func (s *Serializer) Write64BytesArraySlice(slice SliceOfArraysOf64Bytes, deSeriMode DeSerializationMode, ...) *Serializer
- func (s *Serializer) WriteBool(v bool, errProducer ErrProducer) *Serializer
- func (s *Serializer) WriteByte(data byte, errProducer ErrProducer) *Serializer
- func (s *Serializer) WriteBytes(data []byte, errProducer ErrProducer) *Serializer
- func (s *Serializer) WriteNum(v interface{}, errProducer ErrProducer) *Serializer
- func (s *Serializer) WriteObject(seri Serializable, deSeriMode DeSerializationMode, deSeriCtx interface{}, ...) *Serializer
- func (s *Serializer) WritePayload(payload Serializable, deSeriMode DeSerializationMode, deSeriCtx interface{}, ...) *Serializer
- func (s *Serializer) WritePayloadLength(length int, errProducer ErrProducer) *Serializer
- func (s *Serializer) WriteSliceOfByteSlices(data [][]byte, deSeriMode DeSerializationMode, lenType SeriLengthPrefixType, ...) *Serializer
- func (s *Serializer) WriteSliceOfObjects(source interface{}, deSeriMode DeSerializationMode, deSeriCtx interface{}, ...) *Serializer
- func (s *Serializer) WriteString(str string, lenType SeriLengthPrefixType, errProducer ErrProducer, minLen int, ...) *Serializer
- func (s *Serializer) WriteTime(timeToWrite time.Time, errProducer ErrProducer) *Serializer
- func (s *Serializer) WriteUint256(num *big.Int, errProducer ErrProducer) *Serializer
- func (s *Serializer) WriteVariableByteSlice(data []byte, lenType SeriLengthPrefixType, errProducer ErrProducer, minLen int, ...) *Serializer
- func (s *Serializer) Written() int
- type SliceOfArraysOf32Bytes
- type SliceOfArraysOf64Bytes
- type SortedSerializables
- type TypeDenotationType
- type TypePrefixes
Constants ¶
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 ¶
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 ¶
CheckExactByteLength checks that the given length equals exact.
func CheckMinByteLength ¶
CheckMinByteLength checks that length is min. min.
func CheckTypeByte ¶
CheckTypeByte checks that the denoted type byte equals the shouldType.
Types ¶
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 ¶
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 ¶
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 ¶
ElementValidationFunc is a function which runs during array validation (e.g. lexical ordering).
type ErrProducerWithLeftOver ¶
ErrProducerWithLeftOver might produce an error and is called with the bytes left to read.
type ErrProducerWithRWBytes ¶
ErrProducerWithRWBytes might produce an error and is called with the currently read or written bytes.
type FromByter ¶
FromByter is a type constraint that ensures that the type can be deserialized from bytes.
type LexicalOrdered32ByteArrays ¶
type LexicalOrdered32ByteArrays [][32]byte
LexicalOrdered32ByteArrays are 32 byte arrays ordered in lexical order.
func (LexicalOrdered32ByteArrays) Len ¶
func (l LexicalOrdered32ByteArrays) Len() int
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 MarshalablePtr ¶
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 Serializer ¶
type Serializer struct {
// contains filtered or unexported fields
}
Serializer is a utility to serialize bytes.
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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package serix serializes and deserializes complex Go objects into/from bytes using reflection.
|
Package serix serializes and deserializes complex Go objects into/from bytes using reflection. |