encoder

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttrEncID

type AttrEncID struct {
	TxSys types.PartitionID
	Attr  uint16 // tx type id
}

tx attribute encoder ID

type TVEnc

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

TVEnc is an encoder for serializing data info format which can be parsed by Alphabill Rust predicate SDK.

Encodes simple data as {type id; data} pairs, to encode more complex data structures additional "tag" can be assigned to each "data record" (see EncodeTagged method).

func (*TVEnc) Bytes

func (enc *TVEnc) Bytes() ([]byte, error)

Bytes returns the serialized representation of the data so far and error if any happened during encoding. Buffer is not reset!

func (*TVEnc) Encode

func (enc *TVEnc) Encode(item any)

func (*TVEnc) EncodeTagged

func (enc *TVEnc) EncodeTagged(tag Tag, item any)

func (*TVEnc) WriteBytes

func (enc *TVEnc) WriteBytes(value []byte)

func (*TVEnc) WriteString

func (enc *TVEnc) WriteString(value string)

func (*TVEnc) WriteUInt16

func (enc *TVEnc) WriteUInt16(value uint16)

func (*TVEnc) WriteUInt32

func (enc *TVEnc) WriteUInt32(value uint32)

func (*TVEnc) WriteUInt64

func (enc *TVEnc) WriteUInt64(value uint64)

type TXSystemEncoder

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

TXSystemEncoder is "generic" tx system encoder, parts specific to given tx system (which wants to use it with Wazero WASM predicates) must be added using Register*Encoder methods.

func New

func New(f ...any) (TXSystemEncoder, error)

func (TXSystemEncoder) Encode

func (enc TXSystemEncoder) Encode(obj any, ver uint32, getHandle func(obj any) uint64) ([]byte, error)

Encode serializes well known types (not tx system specific) to representation WASM predicate SDK can load.

  • obj: data to serialize, must be of "well known type";
  • ver: version of the encoding/object the predicate expects;
  • getHandle: callback to register variable in the execution context, returns handle of the new variable. Ie instead of "flattening" sub-object it can be registered and it's handle returned as part of response allowing predicate to load the sub-object with next call.

func (*TXSystemEncoder) RegisterAttrEncoder

func (enc *TXSystemEncoder) RegisterAttrEncoder(id AttrEncID, encoder TxAttributesEncoder) error

RegisterAttrEncoder registers tx attribute encoder.

func (*TXSystemEncoder) RegisterTxAttributeEncoders

func (enc *TXSystemEncoder) RegisterTxAttributeEncoders(reg func(func(id AttrEncID, enc TxAttributesEncoder) error) error, filter func(AttrEncID) bool) error

RegisterTxAttributeEncoders is like RegisterAttrEncoder but allows to filter out undesired encoders.

  • reg: func which attempts to register "all" encoders but for each "filter" is executed and only these for which filter returned true actual registration is attempted.

func (*TXSystemEncoder) RegisterUnitDataEncoder

func (enc *TXSystemEncoder) RegisterUnitDataEncoder(ud any, encoder UnitDataEncoder) error

func (TXSystemEncoder) TxAttributes

func (enc TXSystemEncoder) TxAttributes(txo *types.TransactionOrder, ver uint32) ([]byte, error)

func (TXSystemEncoder) UnitData

func (enc TXSystemEncoder) UnitData(unit *state.Unit, ver uint32) ([]byte, error)

type Tag

type Tag = uint8

type TxAttributesEncoder

type TxAttributesEncoder func(txo *types.TransactionOrder, ver uint32) ([]byte, error)

returns tx order attributes encoded to WASM representation

type UnitDataEncoder

type UnitDataEncoder func(data types.UnitData, ver uint32) ([]byte, error)

Jump to

Keyboard shortcuts

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