codec

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HexCodec

type HexCodec struct{}

HexCodec encodes/decodes values to/from hex strings using the Canton MCMS format. This format is used for encoding operation parameters in Canton smart contracts.

Encoding format:

  • uint8: 1 byte, hex-encoded
  • uint32/int: 4 bytes, big-endian, hex-encoded
  • int64: 8 bytes, big-endian, hex-encoded
  • bool: 1 byte (00 or 01)
  • text/string: uint8(len) + utf8 bytes
  • list/slice: uint8(count) + items (encoded sequentially)
  • struct: concatenate fields in order

func NewHexCodec

func NewHexCodec() *HexCodec

NewHexCodec creates a new HexCodec instance

func (*HexCodec) Marshal

func (c *HexCodec) Marshal(value interface{}) (string, error)

Marshal encodes value to hex string

func (*HexCodec) Unmarshal

func (c *HexCodec) Unmarshal(data string, target interface{}) error

Unmarshal decodes hex string to value

type JsonCodec

type JsonCodec struct {
	// encodeNumericAsString controls whether numeric values are encoded as strings (true) or numbers (false)
	// The latter might be useful for querying and mathematical operations, but can lose precision due to float point errors
	EncodeNumericAsString bool

	// encodeInt64AsString controls whether int64 values are encoded as strings (true) or numbers (false)
	// The latter might be useful for querying and mathematical operations, but can lose precision,
	// as numbers in some json implementations are backed by Double
	EncodeInt64AsString bool

	// excludeNullValuesInRecords controls whether fields with null values in records are excluded from JSON (true)
	// or included with a null value (false)
	ExcludeNullValuesInRecords bool
}

JsonCodec follows the transcode JsonCodec pattern for encoding DAML values to JSON

func NewJsonCodec

func NewJsonCodec() *JsonCodec

NewJsonCodec creates a new JsonCodec with default settings following transcode patterns

func NewJsonCodecWithOptions

func NewJsonCodecWithOptions(encodeNumericAsString, encodeInt64AsString, excludeNullValues bool) *JsonCodec

NewJsonCodecWithOptions creates a JsonCodec with custom options

func (*JsonCodec) Marshal

func (codec *JsonCodec) Marshal(value interface{}) ([]byte, error)

Marshal converts a DAML structure to JSON bytes following transcode patterns

func (*JsonCodec) Unmarshal

func (codec *JsonCodec) Unmarshal(data []byte, target interface{}) error

Unmarshal converts JSON bytes back to a DAML structure following transcode patterns

Jump to

Keyboard shortcuts

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