contentblock

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBlock

func DecodeBlock[T any, B ~string](
	data []byte,
	expected B,
	blockType func(T) B,
	normalize func(*T, B),
) (T, error)

DecodeBlock unmarshals one typed content-block payload and enforces its expected type.

func MarshalEnvelopeJSON

func MarshalEnvelopeJSON[T ~string](blockType T, data json.RawMessage) ([]byte, error)

MarshalEnvelopeJSON preserves the canonical JSON payload stored in an envelope.

func ValidatePayload

func ValidatePayload(block any) error

ValidatePayload rejects nil payloads before they reach encoding/json.

Types

type Envelope

type Envelope[T ~string] struct {
	Type T
	Data json.RawMessage
}

Envelope stores one typed content-block payload in canonical JSON form.

func MarshalEnvelope

func MarshalEnvelope[T ~string](block any) (Envelope[T], error)

MarshalEnvelope encodes one typed block and returns its canonical envelope data.

func UnmarshalEnvelopeJSON

func UnmarshalEnvelopeJSON[T ~string](
	data []byte,
	validate func(T, []byte) error,
) (Envelope[T], error)

UnmarshalEnvelopeJSON validates one content-block payload and stores its canonical JSON form.

Jump to

Keyboard shortcuts

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