schema

package
v0.1.1-rc.15 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchemaAnyName                    = "SchemaAny"
	SchemaStringName                 = "SchemaString"
	SchemaBytesName                  = "SchemaBytes"
	SchemaMapName                    = "SchemaMap"
	SchemaTypeOnlyName               = "SchemaTypeOnly"
	SchemaBoolName                   = "SchemaBool"
	SchemaInt8Name                   = "SchemaInt8"
	SchemaInt16Name                  = "SchemaInt16"
	SchemaInt32Name                  = "SchemaInt32"
	SchemaInt64Name                  = "SchemaInt64"
	SchemaFloat32Name                = "SchemaFloat32"
	SchemaFloat64Name                = "SchemaFloat64"
	SchemaNamedChainName             = "SchemaNamedChain"
	SchemaMapUnorderedName           = "SchemaMapUnordered"
	SchemaMultiCheckNamesSchemaNamed = "SchemaMultiCheckNamesSchemaNamed"
	SchemaDateName                   = "SchemaDate"
	SchemaEnumNamedListName          = "SchemaEnumNamedList"
	SchemaNumberName                 = "SchemaNumber"
	ChainName                        = "SchemaChain"

	TupleSchemaName      = "TupleSchema"
	TupleSchemaNamedName = "TupleSchemaNamed"
	SRepeatSchemaName    = "SRepeatSchema"
	SchemaMapRepeatName  = "SchemaMapRepeat"
)

Variables

View Source
var (
	SBool         Schema       = SchemaBool{}
	SInt8         Schema       = SchemaInt8{}
	SInt16        SchemaInt16  = SchemaInt16{}
	SInt32        SchemaInt32  = SchemaInt32{}
	SInt64        SchemaInt64  = SchemaInt64{}
	SFloat32      Schema       = SchemaFloat32{}
	SFloat64      Schema       = SchemaFloat64{}
	SNumber       Schema       = SchemaNumber{}
	SNumberString Schema       = SchemaNumber{DecodeAsString: true}
	SNullBool     Schema       = SchemaBool{Nullable: true}
	SNullInt8     Schema       = SchemaInt8{Nullable: true}
	SNullInt16    Schema       = SchemaInt16{Nullable: true}
	SNullInt32    Schema       = SchemaInt32{Nullable: true}
	SNullInt64    Schema       = SchemaInt64{Nullable: true}
	SNullFloat32  Schema       = SchemaFloat32{Nullable: true}
	SNullFloat64  Schema       = SchemaFloat64{Nullable: true}
	SString       SchemaString = SchemaString{Width: 0}
	SAny                       = SchemaAny{}
)
View Source
var ErrTypeMisMatch error = errors.New("Type Mismatch")
View Source
var ErrUnsupportedType error = errors.New("Unsuported Type")

Functions

func CheckFloatRange

func CheckFloatRange(val float64, min *float64, max *float64) error

For float64

func CheckIntRange

func CheckIntRange(val int64, min *int64, max *int64) error

For int64

func CheckRange

func CheckRange[T constraints.Ordered](val T, min *T, max *T) error

CheckRange validates val against optional min/max bounds. Returns a RangeErrorDetails if out of range, otherwise nil.

func DecodeBuffer

func DecodeBuffer(buf []byte, chain SchemaChain) (any, error)

func DecodeBufferNamed

func DecodeBufferNamed(buf []byte, chain SchemaNamedChain) (any, error)

func EncodeValue

func EncodeValue(val any, chain SchemaChain) ([]byte, error)

func EncodeValueNamed

func EncodeValueNamed(val any, chain SchemaNamedChain) ([]byte, error)

func PtrToInt64

func PtrToInt64[T constraints.Integer](val T) *int64

func RegisterSchemaType

func RegisterSchemaType(typeName string, builder func(*SchemaJSON) Schema)

RegisterSchemaType registers a custom Schema builder for a given type name.

Usage:

schema.RegisterSchemaType("MyCustomType", func(js schema.SchemaJSON) schema.Schema {
    // Build your own Schema based on js
    return SString.WithWidth(js.Width) // or any custom logic
})

Notes:

  • Type names are case-sensitive ("MyCustomType" ≠ "mycustomtype").
  • Panics if the type name is already registered (built-in or custom).
  • Use UnregisterSchemaType to remove a custom type.

This allows users to extend BuildSchema with their own typetags without modifying the core switch.

func UnregisterSchemaType

func UnregisterSchemaType(typeName string)

UnregisterSchemaType removes a previously registered custom Schema builder.

Usage:

schema.UnregisterSchemaType("MyCustomType")

If the type name is not found, the function does nothing.

func ValidateBuffer

func ValidateBuffer(buf []byte, chain SchemaChain) error

Types

type ErrorCode

type ErrorCode int
const (
	ErrUnknown            ErrorCode = iota
	ErrInvalidFormat                // decoding failed due to invalid format
	ErrUnexpectedEOF                // sequence ended unexpectedly while advancing or reading
	ErrConstraintViolated           // validation rule failed (width, type mismatch, nullable constraint)
	ErrEncode

	// String‑specific validation codes
	ErrStringMismatch // generic string mismatch
	ErrStringPrefix   // prefix check failed
	ErrStringSuffix   // suffix check failed
	ErrStringPattern  // regex/pattern check failed
	ErrStringMatch    // exact match failed
	ErrStringEmail    // email format validation failed
	ErrStringURL      // URL/URI format validation failed
	ErrStringLang     // language tag format validation failed
	// Numeric validation codes
	ErrOutOfRange     // integer value out of allowed range
	ErrDateOutOfRange // timestamp/date value out of allowed range
)

func (ErrorCode) String

func (e ErrorCode) String() string

String implements fmt.Stringer

type MissingKeyErrorDetails

type MissingKeyErrorDetails struct {
	Key string
}

func (MissingKeyErrorDetails) Error

func (e MissingKeyErrorDetails) Error() string

type Nullable

type Nullable interface {
	IsNullable() bool
}

type RangeErrorDetails

type RangeErrorDetails[T constraints.Ordered] struct {
	Min    *T
	Max    *T
	Actual T
}

RangeErrorDetails represents a structured range violation for any ordered type.

func (RangeErrorDetails[T]) Error

func (r RangeErrorDetails[T]) Error() string

type SRepeatSchema

type SRepeatSchema struct {
	Schemas []Schema
	// contains filtered or unexported fields
}

func SRepeat

func SRepeat(minimum int64, maximum int64, schemas ...Schema) SRepeatSchema

func SRepeatRange

func SRepeatRange(minimum *int64, maximum *int64, schemas ...Schema) SRepeatSchema

func (SRepeatSchema) Decode

func (s SRepeatSchema) Decode(seq *access.SeqGetAccess) (any, error)

func (SRepeatSchema) Encode

func (s SRepeatSchema) Encode(put *access.PutAccess, val any) error

func (SRepeatSchema) IsNullable

func (s SRepeatSchema) IsNullable() bool

func (SRepeatSchema) Validate

func (s SRepeatSchema) Validate(seq *access.SeqGetAccess) error

type Schema

type Schema interface {
	Validate(seq *access.SeqGetAccess) error
	Decode(seq *access.SeqGetAccess) (any, error)
	Encode(put *access.PutAccess, val any) error
	IsNullable() bool
}

func BuildSchema

func BuildSchema(js *SchemaJSON) Schema

BuildSchema constructs a Schema instance from a SchemaJSON definition.

It inspects the `Type` field of the provided SchemaJSON and returns the corresponding Schema. Built-in typetags include:

  • "bool" → SBool / SNullBool
  • "int8" → SInt8 / SNullInt8
  • "int16" → SInt16 with optional Range
  • "int32" → SInt32 with optional Range
  • "int64" → SInt64 with optional Range
  • "date" → SDate with optional DateFrom/DateTo
  • "float32" → SFloat32 / SNullFloat32
  • "float64" → SFloat64 / SNullFloat64
  • "string" → SString with optional width, exact, prefix, suffix, pattern
  • "email" → SEmail
  • "uri" → SURI
  • "lang" → SLang
  • "bytes" → SBytes / SVariableBytes
  • "any" → SAny
  • "tuple" → STuple / STupleNamed / STupleVal (with flatten/variableLength)
  • "repeat" → SRepeat
  • "map" → SMap
  • "mapUnordered" → SMapUnordered / SMapUnorderedOptional
  • "mapRepeat" → SMapRepeatRange
  • "multicheck" → SMultiCheckNames
  • "enum" → SEnum
  • "color" → SColor

If the type is not recognized, BuildSchema checks the custom registry (see RegisterSchemaType) before panicking.

Usage:

js := SchemaJSON{Type: "string", Width: 20, Prefix: "ID_"}
s := BuildSchema(js)
s now validates strings up to 20 chars starting with "ID_"

Custom type example:

schema.RegisterSchemaType("MyCustomType", func(js schema.SchemaJSON) schema.Schema {
    return SString.Pattern("[A-Z]{3}[0-9]{2}")
})
custom := BuildSchema(SchemaJSON{Type: "MyCustomType"})

Notes:

  • Type names are case-sensitive.
  • Nullable fields are respected where applicable.
  • Min/Max apply to numeric typetags.
  • DateFrom/DateTo must be RFC3339 strings.
  • For "mapUnordered", FieldNames and Schema must align in length.
  • For "mapRepeat", Schema must contain exactly two entries.

func SBytes

func SBytes(width int) Schema

func SColor

func SColor(nullable bool) Schema

func SDate

func SDate(nullable bool, from, to time.Time) Schema

func SDateRange

func SDateRange(nullable bool, from, to *time.Time) Schema

func SEmail

func SEmail(optional bool) Schema

func SEnum

func SEnum(fieldNames []string, nullable bool) Schema

func SLang

func SLang(optional bool) Schema

SLang validates language codes using golang.org/x/text/language

func SMap

func SMap(nested ...Schema) Schema

func SMapUnordered

func SMapUnordered(mappedSchemas map[string]Schema) Schema

func SMapUnorderedOptional

func SMapUnorderedOptional(mappedSchemas map[string]Schema) Schema

func SStringExact

func SStringExact(expected string) Schema

func SStringLen

func SStringLen(width int) Schema

func SType

func SType(tag typetags.Type) Schema

func SURI

func SURI(optional bool) Schema

SURI adds URI validation + normalization (prepend https:// if missing)

func SVariableBytes

func SVariableBytes() Schema

func SVariableMap

func SVariableMap(nested ...Schema) Schema

func SVariableString

func SVariableString() Schema

type SchemaAny

type SchemaAny struct {
	DecodeAsOrderedMap bool
}

func SchemaAnyOrdered

func SchemaAnyOrdered() SchemaAny

func (SchemaAny) Decode

func (s SchemaAny) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaAny) Encode

func (s SchemaAny) Encode(put *access.PutAccess, val any) error

func (SchemaAny) IsNullable

func (s SchemaAny) IsNullable() bool

func (SchemaAny) Validate

func (s SchemaAny) Validate(seq *access.SeqGetAccess) error

type SchemaBool

type SchemaBool struct{ Nullable bool }

Primitives

func (SchemaBool) Decode

func (s SchemaBool) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaBool) Encode

func (s SchemaBool) Encode(put *access.PutAccess, val any) error

func (SchemaBool) IsNullable

func (s SchemaBool) IsNullable() bool

func (SchemaBool) Validate

func (s SchemaBool) Validate(seq *access.SeqGetAccess) error

type SchemaBytes

type SchemaBytes struct{ Width int }

func (SchemaBytes) Decode

func (s SchemaBytes) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaBytes) Encode

func (s SchemaBytes) Encode(put *access.PutAccess, val any) error

func (SchemaBytes) IsNullable

func (s SchemaBytes) IsNullable() bool

func (SchemaBytes) Validate

func (s SchemaBytes) Validate(seq *access.SeqGetAccess) error

type SchemaChain

type SchemaChain struct {
	Schemas []Schema
}

func SChain

func SChain(schemas ...Schema) SchemaChain

type SchemaEnumNamedList

type SchemaEnumNamedList struct {
	FieldNames []string
	Nullable   bool
}

SchemaEnumNamedList constrains an index to a list of names, encoded in 2 bytes. Perfect for radio groups or select dropdowns.

func (SchemaEnumNamedList) Decode

func (s SchemaEnumNamedList) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaEnumNamedList) Encode

func (s SchemaEnumNamedList) Encode(put *access.PutAccess, val any) error

func (SchemaEnumNamedList) IsNullable

func (s SchemaEnumNamedList) IsNullable() bool

func (SchemaEnumNamedList) Validate

func (s SchemaEnumNamedList) Validate(seq *access.SeqGetAccess) error

type SchemaError

type SchemaError struct {
	Code     ErrorCode
	Name     string
	Field    string
	Position int
	InnerErr error
}

func NewSchemaError

func NewSchemaError(code ErrorCode, name, field string, pos int, inner error) *SchemaError

func (*SchemaError) Error

func (v *SchemaError) Error() string

func (*SchemaError) Unwrap

func (v *SchemaError) Unwrap() error

type SchemaFloat32

type SchemaFloat32 struct{ Nullable bool }

func (SchemaFloat32) Decode

func (s SchemaFloat32) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaFloat32) Encode

func (s SchemaFloat32) Encode(put *access.PutAccess, val any) error

func (SchemaFloat32) IsNullable

func (s SchemaFloat32) IsNullable() bool

func (SchemaFloat32) Validate

func (s SchemaFloat32) Validate(seq *access.SeqGetAccess) error

type SchemaFloat64

type SchemaFloat64 struct{ Nullable bool }

func (SchemaFloat64) Decode

func (s SchemaFloat64) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaFloat64) Encode

func (s SchemaFloat64) Encode(put *access.PutAccess, val any) error

func (SchemaFloat64) IsNullable

func (s SchemaFloat64) IsNullable() bool

func (SchemaFloat64) Validate

func (s SchemaFloat64) Validate(seq *access.SeqGetAccess) error

type SchemaGeneric

type SchemaGeneric struct {
	ValidateFunc  func(seq *access.SeqGetAccess) error
	DecodeFunc    func(seq *access.SeqGetAccess) (any, error)
	EncodeFunc    func(put *access.PutAccess, val any) error
	NullableCheck func() bool
}

func (SchemaGeneric) Decode

func (f SchemaGeneric) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaGeneric) Encode

func (f SchemaGeneric) Encode(put *access.PutAccess, val any) error

func (SchemaGeneric) IsNullable

func (f SchemaGeneric) IsNullable() bool

func (SchemaGeneric) Validate

func (f SchemaGeneric) Validate(seq *access.SeqGetAccess) error

type SchemaInt8

type SchemaInt8 struct{ Nullable bool }

func (SchemaInt8) Decode

func (s SchemaInt8) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaInt8) Encode

func (s SchemaInt8) Encode(put *access.PutAccess, val any) error

func (SchemaInt8) IsNullable

func (s SchemaInt8) IsNullable() bool

func (SchemaInt8) Validate

func (s SchemaInt8) Validate(seq *access.SeqGetAccess) error

type SchemaInt16

type SchemaInt16 struct{ Nullable bool }

func (SchemaInt16) Decode

func (s SchemaInt16) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaInt16) Encode

func (s SchemaInt16) Encode(put *access.PutAccess, val any) error

func (SchemaInt16) IsNullable

func (s SchemaInt16) IsNullable() bool

func (SchemaInt16) Range

func (s SchemaInt16) Range(min, max *int64) Schema

func (SchemaInt16) RangeValues

func (s SchemaInt16) RangeValues(min, max int64) Schema

func (SchemaInt16) Validate

func (s SchemaInt16) Validate(seq *access.SeqGetAccess) error

type SchemaInt32

type SchemaInt32 struct{ Nullable bool }

func (SchemaInt32) Decode

func (s SchemaInt32) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaInt32) Encode

func (s SchemaInt32) Encode(put *access.PutAccess, val any) error

func (SchemaInt32) IsNullable

func (s SchemaInt32) IsNullable() bool

func (SchemaInt32) Range

func (s SchemaInt32) Range(min, max *int64) Schema

func (SchemaInt32) RangeValues

func (s SchemaInt32) RangeValues(min, max int64) Schema

func (SchemaInt32) Validate

func (s SchemaInt32) Validate(seq *access.SeqGetAccess) error

type SchemaInt64

type SchemaInt64 struct{ Nullable bool }

func (SchemaInt64) DateRange

func (s SchemaInt64) DateRange(from, to *time.Time) Schema

func (SchemaInt64) DateRangeValues

func (s SchemaInt64) DateRangeValues(from, to time.Time) Schema

func (SchemaInt64) Decode

func (s SchemaInt64) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaInt64) Encode

func (s SchemaInt64) Encode(put *access.PutAccess, val any) error

func (SchemaInt64) IsNullable

func (s SchemaInt64) IsNullable() bool

func (SchemaInt64) Range

func (s SchemaInt64) Range(min, max *int64) Schema

func (SchemaInt64) RangeValues

func (s SchemaInt64) RangeValues(min, max int64) Schema

func (SchemaInt64) Validate

func (s SchemaInt64) Validate(seq *access.SeqGetAccess) error

type SchemaJSON

type SchemaJSON struct {
	Type           string       `json:"type"`
	FieldNames     []string     `json:"fieldNames,omitempty"`
	Schema         []SchemaJSON `json:"schema,omitempty"`
	Nullable       bool         `json:"nullable,omitempty"`
	VariableLength bool         `json:"variableLength,omitempty"`
	Flatten        bool         `json:"flatten,omitempty"`

	// Constraint helpers
	Width         int    `json:"width,omitempty"`
	Min           *int64 `json:"min,omitempty"`
	Max           *int64 `json:"max,omitempty"`
	Exact         string `json:"exact,omitempty"`
	Prefix        string `json:"prefix,omitempty"`
	Suffix        string `json:"suffix,omitempty"`
	Pattern       string `json:"pattern,omitempty"`
	DateFrom      string `json:"dateFrom,omitempty"`
	DateTo        string `json:"dateTo,omitempty"`
	DecodeDefault string `json:"decodeDefault,omitempty"`

	// Extra metadata for UI or other purposes
	Extra map[string]any `json:"extra,omitempty"`
}

type SchemaMap

type SchemaMap struct {
	Width   int
	Schemas []Schema
}

NOTE: SchemaMap expects keys in sorted order. Validation will fail if map keys are unordered or mismatched.

func (SchemaMap) Decode

func (s SchemaMap) Decode(seq *access.SeqGetAccess) (any, error)

Decode reads a SchemaMap from the sequence into an OrderedMapAny.

func (SchemaMap) Encode

func (s SchemaMap) Encode(put *access.PutAccess, val any) error

Encode writes an OrderedMapAny into the sequence according to the SchemaMap.

func (SchemaMap) IsNullable

func (s SchemaMap) IsNullable() bool

func (SchemaMap) Validate

func (s SchemaMap) Validate(seq *access.SeqGetAccess) error

Validate checks that the sequence matches the SchemaMap definition.

type SchemaMapRepeat

type SchemaMapRepeat struct {
	Key   Schema
	Value Schema
	// contains filtered or unexported fields
}

func SMapRepeat

func SMapRepeat(key Schema, value Schema) SchemaMapRepeat

func SMapRepeatRange

func SMapRepeatRange(key Schema, value Schema, minimum, maximum *int64) SchemaMapRepeat

func (SchemaMapRepeat) Decode

func (s SchemaMapRepeat) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaMapRepeat) Encode

func (s SchemaMapRepeat) Encode(put *access.PutAccess, val any) error

func (SchemaMapRepeat) IsNullable

func (s SchemaMapRepeat) IsNullable() bool

func (SchemaMapRepeat) Validate

func (s SchemaMapRepeat) Validate(seq *access.SeqGetAccess) error

type SchemaMapUnordered

type SchemaMapUnordered struct {
	Fields   map[string]Schema
	Nullable bool
}

func (SchemaMapUnordered) Decode

func (s SchemaMapUnordered) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaMapUnordered) Encode

func (s SchemaMapUnordered) Encode(put *access.PutAccess, val any) error

func (SchemaMapUnordered) IsNullable

func (s SchemaMapUnordered) IsNullable() bool

func (SchemaMapUnordered) Validate

func (s SchemaMapUnordered) Validate(seq *access.SeqGetAccess) error

type SchemaMultiCheckNamesSchema

type SchemaMultiCheckNamesSchema struct {
	FieldNames []string
	Nullable   bool
}

SchemaMultiCheckNamesSchema is a convenience schema: every field is a SchemaBool.

func SMultiCheckNames

func SMultiCheckNames(fieldNames []string) SchemaMultiCheckNamesSchema

func (SchemaMultiCheckNamesSchema) Decode

func (SchemaMultiCheckNamesSchema) Encode

func (SchemaMultiCheckNamesSchema) IsNullable

func (s SchemaMultiCheckNamesSchema) IsNullable() bool

func (SchemaMultiCheckNamesSchema) Validate

type SchemaNamedChain

type SchemaNamedChain struct {
	SchemaChain
	FieldNames []string
}

type SchemaNumber

type SchemaNumber struct {
	DecodeAsString bool
	Min            *float64
	Max            *float64
}

func (SchemaNumber) Decode

func (s SchemaNumber) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaNumber) DecodeValidate

func (s SchemaNumber) DecodeValidate(seq *access.SeqGetAccess, decodeAlways bool) (any, error)

func (SchemaNumber) Encode

func (s SchemaNumber) Encode(put *access.PutAccess, val any) error

func (SchemaNumber) IsNullable

func (s SchemaNumber) IsNullable() bool

func (SchemaNumber) Validate

func (s SchemaNumber) Validate(seq *access.SeqGetAccess) error

type SchemaString

type SchemaString struct {
	Width            int
	DefaultDecodeVal string
}

func (SchemaString) CheckFunc

func (s SchemaString) CheckFunc(code ErrorCode, expected string, test func(payloadStr string) bool) Schema

func (SchemaString) Decode

func (s SchemaString) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaString) DefaultDecodeValue

func (s SchemaString) DefaultDecodeValue(decodeDefault string) SchemaString

func (SchemaString) Encode

func (s SchemaString) Encode(put *access.PutAccess, val any) error

func (SchemaString) IsNullable

func (s SchemaString) IsNullable() bool

func (SchemaString) Match

func (s SchemaString) Match(expected string) Schema

func (SchemaString) Optional

func (s SchemaString) Optional() SchemaString

func (SchemaString) Pattern

func (s SchemaString) Pattern(expr string) Schema

func (SchemaString) Prefix

func (s SchemaString) Prefix(prefix string) Schema

func (SchemaString) Suffix

func (s SchemaString) Suffix(suffix string) Schema

func (SchemaString) Validate

func (s SchemaString) Validate(seq *access.SeqGetAccess) error

func (SchemaString) WithWidth

func (s SchemaString) WithWidth(n int) SchemaString

type SchemaTypeOnly

type SchemaTypeOnly struct {
	Tag             typetags.Type
	DecodeOrdereMap bool
}

func (SchemaTypeOnly) Decode

func (s SchemaTypeOnly) Decode(seq *access.SeqGetAccess) (any, error)

func (SchemaTypeOnly) Encode

func (s SchemaTypeOnly) Encode(put *access.PutAccess, val any) error

func (SchemaTypeOnly) IsNullable

func (s SchemaTypeOnly) IsNullable() bool

func (SchemaTypeOnly) Validate

func (s SchemaTypeOnly) Validate(seq *access.SeqGetAccess) error

type SizeExact

type SizeExact struct {
	Exact  int
	Actual int
}

func (SizeExact) Error

func (r SizeExact) Error() string

type StringErrorDetails

type StringErrorDetails struct {
	Expected string
	Actual   string
}

func (StringErrorDetails) Error

func (e StringErrorDetails) Error() string

type TupleSchema

type TupleSchema struct {
	Schemas        []Schema
	Nullable       bool
	VariableLength bool
	Flatten        bool
}

func STuple

func STuple(Schema ...Schema) TupleSchema

func STupleVal

func STupleVal(Schema ...Schema) TupleSchema

func STupleValFlatten

func STupleValFlatten(Schema ...Schema) TupleSchema

func (TupleSchema) Decode

func (s TupleSchema) Decode(seq *access.SeqGetAccess) (any, error)

func (TupleSchema) Encode

func (s TupleSchema) Encode(put *access.PutAccess, val any) error

func (TupleSchema) IsNullable

func (s TupleSchema) IsNullable() bool

func (TupleSchema) Validate

func (s TupleSchema) Validate(seq *access.SeqGetAccess) error

type TupleSchemaNamed

type TupleSchemaNamed struct {
	Schemas        []Schema
	FieldNames     []string
	Nullable       bool
	Flatten        bool
	VariableLength bool
}

func STupleNamed

func STupleNamed(fieldNames []string, Schema ...Schema) TupleSchemaNamed

func STupleNamedVal

func STupleNamedVal(fieldNames []string, Schema ...Schema) TupleSchemaNamed

Strict named tuple: exact field count

func STupleNamedValFlattened

func STupleNamedValFlattened(fieldNames []string, Schema ...Schema) TupleSchemaNamed

Flexible named tuple: allows repeats/extra fields

func (TupleSchemaNamed) Decode

func (s TupleSchemaNamed) Decode(seq *access.SeqGetAccess) (any, error)

func (TupleSchemaNamed) Encode

func (s TupleSchemaNamed) Encode(put *access.PutAccess, val any) error

func (TupleSchemaNamed) IsNullable

func (s TupleSchemaNamed) IsNullable() bool

func (TupleSchemaNamed) Validate

func (s TupleSchemaNamed) Validate(seq *access.SeqGetAccess) error

Jump to

Keyboard shortcuts

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