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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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