ifaces

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Overview

Package ifaces exposes all interfaces to work with adapters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	MarshalAdapter
	UnmarshalAdapter

	OrderedAdapter
}

Adapter exposes an interface like the standard [json] library.

type Capabilities

type Capabilities uint8

Capabilities holds several unitary capability flags

func (Capabilities) Has

func (c Capabilities) Has(capability Capability) bool

Has some capability flag enabled.

func (Capabilities) String

func (c Capabilities) String() string

type Capability

type Capability uint8

Capability indicates what a JSON adapter is capable of.

const (
	CapabilityMarshalJSON Capability = 1 << iota
	CapabilityUnmarshalJSON
	CapabilityOrderedMarshalJSON
	CapabilityOrderedUnmarshalJSON
	CapabilityOrderedMap
)

func (Capability) String

func (c Capability) String() string

type MarshalAdapter

type MarshalAdapter interface {
	Poolable

	Marshal(any) ([]byte, error)
}

MarshalAdapter behaves likes the standard library [json.Marshal].

type Ordered

type Ordered interface {
	OrderedItems() iter.Seq2[string, any]
}

Ordered knows how to iterate over the (key,value) pairs of a JSON object.

type OrderedAdapter

type OrderedAdapter interface {
	OrderedMarshalAdapter
	OrderedUnmarshalAdapter
	NewOrderedMap(capacity int) OrderedMap
}

OrderedAdapter exposes interfaces to process JSON and keep the order of object keys.

type OrderedMap

type OrderedMap interface {
	Ordered
	SetOrdered

	OrderedMarshalJSON() ([]byte, error)
	OrderedUnmarshalJSON([]byte) error
}

OrderedMap represent a JSON object (i.e. like a map[string,any]), and knows how to serialize and deserialize JSON with the order of keys maintained.

type OrderedMarshalAdapter

type OrderedMarshalAdapter interface {
	Poolable

	OrderedMarshal(Ordered) ([]byte, error)
}

OrderedMarshalAdapter behaves likes the standard library [json.Marshal], preserving the order of keys in objects.

type OrderedUnmarshalAdapter

type OrderedUnmarshalAdapter interface {
	Poolable

	OrderedUnmarshal([]byte, SetOrdered) error
}

OrderedUnmarshalAdapter behaves likes the standard library [json.Unmarshal], preserving the order of keys in objects.

type Poolable

type Poolable interface {
	// Self-redeem: for [Adapter] s that are allocated from a pool.
	// The [Adapter] must not be used after calling [Redeem].
	Redeem()

	// Reset the state of the [Adapter], if any.
	Reset()
}

type Registrar

type Registrar interface {
	RegisterFor(RegistryEntry)
}

Registrar is a type that knows how to keep registration calls from adapters.

type RegistryEntry

type RegistryEntry struct {
	Who         string
	What        Capabilities
	Constructor func() Adapter
	Support     func(what Capability, value any) bool
}

RegistryEntry describes how any given adapter registers its capabilities to the Registrar.

type SetOrdered

type SetOrdered interface {
	SetOrderedItems(iter.Seq2[string, any])
}

SetOrdered knows how to append or update the keys of a JSON object, given an iterator over (key,value) pairs.

If the provided iterator is nil then the receiver should be set to nil.

type UnmarshalAdapter

type UnmarshalAdapter interface {
	Poolable

	Unmarshal([]byte, any) error
}

UnmarshalAdapter behaves likes the standard library [json.Unmarshal].

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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