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 ¶
- func SkipValue(ts *TokenStream, fieldTok Token) error
- type IngestOption
- type IngestOptions
- type Token
- func (t Token) Bool() bool
- func (t Token) Float32() float32
- func (t Token) Float64() float64
- func (t Token) Int8() int8
- func (t Token) Int16() int16
- func (t Token) Int32() int32
- func (t Token) Int64() int64
- func (t Token) KeyBool() bool
- func (t Token) KeyFloat32() float32
- func (t Token) KeyFloat64() float64
- func (t Token) KeyInt8() int8
- func (t Token) KeyInt16() int16
- func (t Token) KeyInt32() int32
- func (t Token) KeyInt64() int64
- func (t Token) KeyString() string
- func (t Token) KeyUint8() uint8
- func (t Token) KeyUint16() uint16
- func (t Token) KeyUint32() uint32
- func (t Token) KeyUint64() uint64
- func (t *Token) SetBool(v bool)
- func (t *Token) SetFloat32(v float32)
- func (t *Token) SetFloat64(v float64)
- func (t *Token) SetInt8(v int8)
- func (t *Token) SetInt16(v int16)
- func (t *Token) SetInt32(v int32)
- func (t *Token) SetInt64(v int64)
- func (t *Token) SetKeyBool(v bool)
- func (t *Token) SetKeyFloat32(v float32)
- func (t *Token) SetKeyFloat64(v float64)
- func (t *Token) SetKeyInt8(v int8)
- func (t *Token) SetKeyInt16(v int16)
- func (t *Token) SetKeyInt32(v int32)
- func (t *Token) SetKeyInt64(v int64)
- func (t *Token) SetKeyUint8(v uint8)
- func (t *Token) SetKeyUint16(v uint16)
- func (t *Token) SetKeyUint32(v uint32)
- func (t *Token) SetKeyUint64(v uint64)
- func (t *Token) SetUint8(v uint8)
- func (t *Token) SetUint16(v uint16)
- func (t *Token) SetUint32(v uint32)
- func (t *Token) SetUint64(v uint64)
- func (t Token) String() string
- func (t Token) Uint8() uint8
- func (t Token) Uint16() uint16
- func (t Token) Uint32() uint32
- func (t Token) Uint64() uint64
- type TokenKind
- type TokenStream
- type WalkOption
- type Walker
- type YieldToken
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) KeyFloat32 ¶
KeyFloat32 returns the float32 key value.
func (Token) KeyFloat64 ¶
KeyFloat64 returns the float64 key value.
func (*Token) SetFloat32 ¶
SetFloat32 sets the float32 value in the token.
func (*Token) SetFloat64 ¶
SetFloat64 sets the float64 value in the token.
func (*Token) SetKeyFloat32 ¶
SetKeyFloat32 sets a float32 key.
func (*Token) SetKeyFloat64 ¶
SetKeyFloat64 sets a float64 key.
func (Token) String ¶
String returns the string value using unsafe.String for zero-copy conversion. Only valid when Type == FTString.
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 ¶
YieldToken is the callback type for Walk iteration. Returns false to stop iteration early.