codec

package
v0.0.0-...-0d7bf00 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownMessage = errors.New("unknown message type")

Functions

func DecodeTLBCellToAny

func DecodeTLBCellToAny(c *cell.Cell, tlbs tvm.TLBMap) (any, error)

func DecodeTLBStructKeys

func DecodeTLBStructKeys(v any, tlbs tvm.TLBMap) ([]string, error)

Returns ordered keys based TL-B annotated struct type

func DecodeTLBStructToJSON

func DecodeTLBStructToJSON(v any, tlbs tvm.TLBMap) (string, map[string]any, error)

func DecodeTLBValToJSON

func DecodeTLBValToJSON(v any, tlbs tvm.TLBMap) (string, any, error)

func EnsureTLBStructPointer

func EnsureTLBStructPointer(value any) (any, error)

EnsureTLBStructPointer ensures that the provided value is a pointer to a TL-B struct or struct itself.

func LoadNestedEnvelopes

func LoadNestedEnvelopes(value any, registry tvm.ContractTLBRegistry) error

LoadNestedEnvelopes recursively traverses value and loads any nested MessageEnvelope instances.

It works for any concrete generic instantiation (for example MessageEnvelope[T], *MessageEnvelope[T], MessageEnvelope[any], etc.) by matching the common LoadDecoded method rather than concrete generic type. Cycles through pointers are detected and skipped.

Types

type MessageEnvelope

type MessageEnvelope[T any] struct {
	Metadata MessageMeta     `json:"metadata"`
	Payload  json.RawMessage `json:"payload"`
	Cell     *cell.Cell      `json:"-"`
	Value    T               `json:"-"`
}

MessageEnvelope is the JSON-friendly representation of a TL-B message. The generic type parameter T represents the specific message type being wrapped.

func MustWrapMessage

func MustWrapMessage[T any](contract string, val T) *MessageEnvelope[T]

func WrapMessage

func WrapMessage[T any](contract string, val T) (*MessageEnvelope[T], error)

WrapMessage prepares a type-safe envelope for the provided TL-B message.

func (*MessageEnvelope[T]) LoadDecoded

func (e *MessageEnvelope[T]) LoadDecoded(r tvm.ContractTLBRegistry) error

LoadFromRegistry attempts to populate the Value T field from the Payload or Cell using the provided registry.

func (*MessageEnvelope[T]) LoadFromCell

func (e *MessageEnvelope[T]) LoadFromCell(slice *cell.Slice) error

func (MessageEnvelope[T]) MarshalJSON

func (e MessageEnvelope[T]) MarshalJSON() ([]byte, error)

MarshalJSON ensures we persist the cached payload bytes when present.

func (MessageEnvelope[T]) ToCell

func (e MessageEnvelope[T]) ToCell() (*cell.Cell, error)

func (*MessageEnvelope[T]) UnmarshalJSON

func (e *MessageEnvelope[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON populates the envelope metadata and rebuilds the typed value.

type MessageMeta

type MessageMeta struct {
	Contract string
	Opcode   uint64

	// Go runtime type information
	TypeName string
	GoType   reflect.Type
}

MessageMeta keeps the information required to serialize/deserialize TL-B messages.

func NewMessageMeta

func NewMessageMeta(contract string, typ reflect.Type) (MessageMeta, error)

func NewMessageMetaFromValue

func NewMessageMetaFromValue(contract string, v any) (MessageMeta, error)

func (MessageMeta) QualifiedKey

func (m MessageMeta) QualifiedKey() string

type NonFatalResolverError

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

NonFatalResolverError indicates that resolution error is non-fatal and the resolver should be skipped

func NewNonFatalResolverError

func NewNonFatalResolverError(cause error) NonFatalResolverError

func (NonFatalResolverError) Error

func (e NonFatalResolverError) Error() string

type Resolver

type Resolver[IN any, OUT any] interface {
	Resolve(in IN) (OUT, error)
}

Resolver is a generic interface for resolving input to output

type ResolverChecker

type ResolverChecker[IN any] interface {
	CanResolve(in IN) bool
}

ResolverChecker checks if a resolver can handle a given input

type ResolverKeyProvider

type ResolverKeyProvider interface {
	Key() string
}

ResolverKeyProvider provides a key for identifying the resolver

type ResolverRegistry

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

ResolverRegistry manages a collection of typed resolvers

func NewResolverRegistry

func NewResolverRegistry(resolvers ...TypedResolver) *ResolverRegistry

NewResolverRegistry creates a new ResolverRegistry with optional initial resolvers

func (*ResolverRegistry) Register

func (r *ResolverRegistry) Register(resolver TypedResolver)

Register adds a resolver to the registry

func (*ResolverRegistry) Resolve

func (r *ResolverRegistry) Resolve(input any) (any, error)

Resolve is a convenience method that handles any input type

type TypedResolver

type TypedResolver interface {
	// ResolverChecker.CanResolve checks if this resolver can handle the given input type
	ResolverChecker[any]
	// Resolver.Resolve performs the resolution, returning the resolved value
	Resolver[any, any]
	// ResolverKeyProvider.Key returns the unique key for this resolver
	ResolverKeyProvider
	// InputType returns the reflect.Type this resolver accepts
	InputType() reflect.Type
	// OutputType returns the reflect.Type this resolver produces
	OutputType() reflect.Type
}

TypedResolver wraps a resolver with type information for dynamic dispatch

func NewTypedResolver

func NewTypedResolver[IN any, OUT any](resolver Resolver[IN, OUT]) TypedResolver

NewTypedResolver creates a TypedResolver from a generic Resolver

func NewTypedResolverWith

func NewTypedResolverWith[IN any, OUT any](resolver Resolver[IN, OUT], key string) TypedResolver

NewTypedResolverWith creates a TypedResolver from a generic Resolver with a specified key

Jump to

Keyboard shortcuts

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