clawiter

package
v0.0.0-...-599cc13 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package clawiter provides types for streaming iteration over Claw structs.

Package clawiter provides types for streaming iteration over Claw structs. This enables serialization to various formats (JSON, XML, etc.) without format-specific code in each struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SkipValue

func SkipValue(ts *TokenStream, fieldTok Token) error

SkipValue skips a field value in the token stream, including nested structs and lists.

Types

type IngestOption

type IngestOption func(IngestOptions) (IngestOptions, error)

IngestOption configures Ingest behavior.

func WithIgnoreUnknownFields

func WithIgnoreUnknownFields(ignore bool) IngestOption

WithIgnoreUnknownFields sets whether to ignore unknown fields during ingestion. When true, unknown fields are skipped instead of causing an error.

type IngestOptions

type IngestOptions struct {
	// IgnoreUnknownFields causes unknown field names to be skipped instead of returning an error.
	IgnoreUnknownFields bool
}

IngestOptions holds configuration for Ingest. This is populated by IngestOption functions and passed to XXXIngestFrom.

type Token

type Token struct {
	// Kind is the type of token.
	Kind TokenKind
	// Name is the struct name (for Start/End) or field name (for Field).
	Name string
	// Type is the field type (for TokenField and TokenListStart).
	Type field.Type

	// Bytes stores string and byte slice data. Use String() for zero-copy string conversion.
	Bytes []byte

	// IsEnum indicates if this is an enum value.
	IsEnum bool
	// EnumGroup is the name of the enum group (e.g., "Type").
	EnumGroup string
	// EnumName is the string name of the enum value (e.g., "Car").
	EnumName string

	// StructName is the struct type name for FTStruct/FTListStructs.
	StructName string
	// IsNil indicates the struct or list is nil/empty. No Start/End tokens follow.
	IsNil bool

	// Len is the list length (for TokenListStart).
	Len int

	// TypeHash is the 16-byte SHAKE128 hash for Any type fields.
	// Used for type identification when encoding/decoding Any values.
	TypeHash []byte

	// Map-related fields (for TokenMapStart and TokenMapEntry)
	// KeyType is the type of map keys.
	KeyType field.Type
	// ValueType is the type of map values.
	ValueType field.Type
	// Key holds the map key value (uses same encoding as data/Bytes).
	Key uint64
	// KeyBytes holds string/bytes map keys.
	KeyBytes []byte
	// contains filtered or unexported fields
}

Token represents a single event in the walk stream.

func (Token) Bool

func (t Token) Bool() bool

Bool returns the boolean value. Only valid when Type == FTBool.

func (Token) Float32

func (t Token) Float32() float32

Float32 returns the float32 value. Only valid when Type == FTFloat32.

func (Token) Float64

func (t Token) Float64() float64

Float64 returns the float64 value. Only valid when Type == FTFloat64.

func (Token) Int8

func (t Token) Int8() int8

Int8 returns the int8 value. Only valid when Type == FTInt8.

func (Token) Int16

func (t Token) Int16() int16

Int16 returns the int16 value. Only valid when Type == FTInt16.

func (Token) Int32

func (t Token) Int32() int32

Int32 returns the int32 value. Only valid when Type == FTInt32.

func (Token) Int64

func (t Token) Int64() int64

Int64 returns the int64 value. Only valid when Type == FTInt64.

func (Token) KeyBool

func (t Token) KeyBool() bool

KeyBool returns the boolean key value.

func (Token) KeyFloat32

func (t Token) KeyFloat32() float32

KeyFloat32 returns the float32 key value.

func (Token) KeyFloat64

func (t Token) KeyFloat64() float64

KeyFloat64 returns the float64 key value.

func (Token) KeyInt8

func (t Token) KeyInt8() int8

KeyInt8 returns the int8 key value.

func (Token) KeyInt16

func (t Token) KeyInt16() int16

KeyInt16 returns the int16 key value.

func (Token) KeyInt32

func (t Token) KeyInt32() int32

KeyInt32 returns the int32 key value.

func (Token) KeyInt64

func (t Token) KeyInt64() int64

KeyInt64 returns the int64 key value.

func (Token) KeyString

func (t Token) KeyString() string

KeyString returns the string key value.

func (Token) KeyUint8

func (t Token) KeyUint8() uint8

KeyUint8 returns the uint8 key value.

func (Token) KeyUint16

func (t Token) KeyUint16() uint16

KeyUint16 returns the uint16 key value.

func (Token) KeyUint32

func (t Token) KeyUint32() uint32

KeyUint32 returns the uint32 key value.

func (Token) KeyUint64

func (t Token) KeyUint64() uint64

KeyUint64 returns the uint64 key value.

func (*Token) SetBool

func (t *Token) SetBool(v bool)

SetBool sets the boolean value in the token.

func (*Token) SetFloat32

func (t *Token) SetFloat32(v float32)

SetFloat32 sets the float32 value in the token.

func (*Token) SetFloat64

func (t *Token) SetFloat64(v float64)

SetFloat64 sets the float64 value in the token.

func (*Token) SetInt8

func (t *Token) SetInt8(v int8)

SetInt8 sets the int8 value in the token.

func (*Token) SetInt16

func (t *Token) SetInt16(v int16)

SetInt16 sets the int16 value in the token.

func (*Token) SetInt32

func (t *Token) SetInt32(v int32)

SetInt32 sets the int32 value in the token.

func (*Token) SetInt64

func (t *Token) SetInt64(v int64)

SetInt64 sets the int64 value in the token.

func (*Token) SetKeyBool

func (t *Token) SetKeyBool(v bool)

SetKeyBool sets a boolean key.

func (*Token) SetKeyFloat32

func (t *Token) SetKeyFloat32(v float32)

SetKeyFloat32 sets a float32 key.

func (*Token) SetKeyFloat64

func (t *Token) SetKeyFloat64(v float64)

SetKeyFloat64 sets a float64 key.

func (*Token) SetKeyInt8

func (t *Token) SetKeyInt8(v int8)

SetKeyInt8 sets an int8 key.

func (*Token) SetKeyInt16

func (t *Token) SetKeyInt16(v int16)

SetKeyInt16 sets an int16 key.

func (*Token) SetKeyInt32

func (t *Token) SetKeyInt32(v int32)

SetKeyInt32 sets an int32 key.

func (*Token) SetKeyInt64

func (t *Token) SetKeyInt64(v int64)

SetKeyInt64 sets an int64 key.

func (*Token) SetKeyUint8

func (t *Token) SetKeyUint8(v uint8)

SetKeyUint8 sets a uint8 key.

func (*Token) SetKeyUint16

func (t *Token) SetKeyUint16(v uint16)

SetKeyUint16 sets a uint16 key.

func (*Token) SetKeyUint32

func (t *Token) SetKeyUint32(v uint32)

SetKeyUint32 sets a uint32 key.

func (*Token) SetKeyUint64

func (t *Token) SetKeyUint64(v uint64)

SetKeyUint64 sets a uint64 key.

func (*Token) SetUint8

func (t *Token) SetUint8(v uint8)

SetUint8 sets the uint8 value in the token.

func (*Token) SetUint16

func (t *Token) SetUint16(v uint16)

SetUint16 sets the uint16 value in the token.

func (*Token) SetUint32

func (t *Token) SetUint32(v uint32)

SetUint32 sets the uint32 value in the token.

func (*Token) SetUint64

func (t *Token) SetUint64(v uint64)

SetUint64 sets the uint64 value in the token.

func (Token) String

func (t Token) String() string

String returns the string value using unsafe.String for zero-copy conversion. Only valid when Type == FTString.

func (Token) Uint8

func (t Token) Uint8() uint8

Uint8 returns the uint8 value. Only valid when Type == FTUint8.

func (Token) Uint16

func (t Token) Uint16() uint16

Uint16 returns the uint16 value. Only valid when Type == FTUint16.

func (Token) Uint32

func (t Token) Uint32() uint32

Uint32 returns the uint32 value. Only valid when Type == FTUint32.

func (Token) Uint64

func (t Token) Uint64() uint64

Uint64 returns the uint64 value. Only valid when Type == FTUint64.

type TokenKind

type TokenKind uint8

TokenKind represents the type of token in the walk stream.

const (
	TokenStructStart TokenKind = iota // Beginning of a struct
	TokenStructEnd                    // End of a struct
	TokenField                        // A field (scalar or announces complex type)
	TokenListStart                    // Beginning of a list
	TokenListEnd                      // End of a list
	TokenMapStart                     // Beginning of a map
	TokenMapEnd                       // End of a map
	TokenMapEntry                     // A key-value pair in a map
)

type TokenStream

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

TokenStream wraps an iter.Seq[Token] for pull-based consumption with peek support.

func NewTokenStream

func NewTokenStream(seq iter.Seq[Token]) *TokenStream

NewTokenStream creates a TokenStream from an iter.Seq[Token].

func (*TokenStream) Close

func (ts *TokenStream) Close()

Close releases resources associated with the token stream.

func (*TokenStream) Next

func (ts *TokenStream) Next() (Token, bool)

Next returns the next token from the stream.

func (*TokenStream) Peek

func (ts *TokenStream) Peek() (Token, bool)

Peek returns the next token without consuming it.

type WalkOption

type WalkOption func(walkOptions) (walkOptions, error)

WalkOption configures Walk behavior.

type Walker

type Walker func(YieldToken)

Walker is a function that walks tokens and yields them to a callback. This is the type accepted by Ingest.

type YieldToken

type YieldToken func(Token) bool

YieldToken is the callback type for Walk iteration. Returns false to stop iteration early.

Jump to

Keyboard shortcuts

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