package serdes

import "github.com/datastax/astra-db-go/v2/astra/serdes"

Copyright IBM Corp.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Code generated by gen-options; DO NOT EDIT.

Index

Functions

func Deserialize

func Deserialize(data []byte, res any, targetDecodeCtx TargetDecodeCtx, target Target, flags ...DesFlags) error

func Serialize

func Serialize(data any, target Target, flags ...SerFlags) ([]byte, error)

func SerializeInto

func SerializeInto(data any, target Target, dst []byte, flags ...SerFlags) ([]byte, error)

Types

type AstraMarshaler

type AstraMarshaler interface {
	MarshalAstra(ctx EncodeCtx) (any, error)
}

type AstraRawMarshaler

type AstraRawMarshaler interface {
	MarshalAstraRaw(ctx EncodeCtx, dst []byte) ([]byte, error)
}

type AstraRawUnmarshaler

type AstraRawUnmarshaler interface {
	UnmarshalAstraRaw(ctx DecodeCtx, value []byte) error
}

type AstraUnmarshaler

type AstraUnmarshaler interface {
	UnmarshalAstra(ctx DecodeCtx, value any) error
}

type DecodeAction

type DecodeAction int
const (
	DecodeActionSyntax DecodeAction = iota
	DecodeActionTypeMismatch
	DecodeActionCustomUnmarshaler
	DecodeActionUnsupported
	DecodeActionInvalid
)

type DecodeCtx

type DecodeCtx struct {
	Target    Target
	TargetCtx TargetDecodeCtx
	Flags     DesFlags
	// contains filtered or unexported fields
}

type DecodeError

type DecodeError struct {
	Action  DecodeAction
	Msg     string
	Value   string
	Type    reflect.Type
	Snippet string
	Offset  int64
	Err     error
	// contains filtered or unexported fields
}
func (*DecodeError) Error
func (e *DecodeError) Error() string
func (*DecodeError) Unwrap
func (e *DecodeError) Unwrap() error

type DesFlags

type DesFlags int
const (
	// SparseRows can be used to disable populating missing columns in untyped rows.
	SparseRows DesFlags = 1 << iota

	// UseNumber can be used for untyped documents/rows in case they're expecting large numbers often.
	UseNumber

	// DesNoCache can be used to disable the serdes cache for deserialization.
	DesNoCache

	// ExtendedErrorSnippet can be used to include more of the JSON snippet in error messages (default is 16 chars, ExtendedErrorSnippet allows up to 64 chars).
	//
	// Note that extending the error context has a higher chance of leaking sensitive data in error messages; be mindful of its usage.
	ExtendedErrorSnippet

	// UseJSONUnmarshal can be used to recognize the standard library's json.Unmarshaler interface.
	// Custom Astra unmarshalers still take precedence.
	UseJSONUnmarshal

	// CaseInsensitiveFieldMatching can be used to fallback to case-insensitive
	// struct field lookups if an exact match isn't found.
	CaseInsensitiveFieldMatching
)

type EncodeAction

type EncodeAction int
const (
	EncodeActionCustomMarshaler EncodeAction = iota
	EncodeActionUnsupportedValue
	EncodeActionUnsupportedType
)

type EncodeCtx

type EncodeCtx struct {
	Target Target
	Flags  SerFlags
	// contains filtered or unexported fields
}

type EncodeError

type EncodeError struct {
	Action EncodeAction
	Msg    string
	Type   reflect.Type
	Err    error
	// contains filtered or unexported fields
}
func (*EncodeError) Error
func (e *EncodeError) Error() string
func (*EncodeError) Unwrap
func (e *EncodeError) Unwrap() error

type RawMap

type RawMap struct {
	Data map[string]json.RawMessage
	// contains filtered or unexported fields
}

RawMap is a partially-deserialized map that retains the DecodeCtx from the original decode call. This allows lazy per-field deserialization to correctly apply field hints (e.g. $vector → datatypes.Vector) that would otherwise be lost when raw bytes are stored and decoded independently later.

func (*RawMap) Ctx
func (m *RawMap) Ctx() DecodeCtx

Ctx returns the DecodeCtx that was active when this map was decoded. Prefer this over manually reconstructing a DecodeCtx from Target/TargetCtx/Flags.

func (*RawMap) DecodeAny
func (m *RawMap) DecodeAny(key string, dest any) error

DecodeAny deserializes the value for key into dest, applying the correct field hint derived from the key name.

func (*RawMap) DecodeField
func (m *RawMap) DecodeField(fieldName string, raw json.RawMessage, dest any) error

DecodeField deserializes raw into dest, applying the field hint for fieldName. Use this when you've already navigated to the raw bytes and know the field name.

func (*RawMap) Flags
func (m *RawMap) Flags() DesFlags

Flags returns the DesFlags that were active when this map was decoded.

func (*RawMap) GetAny
func (m *RawMap) GetAny(key string) (any, bool)

GetAny deserializes the value for key as an any, applying the correct field hint derived from the key name (e.g. "$vector" → datatypes.Vector).

func (*RawMap) GetField
func (m *RawMap) GetField(fieldName string, raw json.RawMessage) (any, bool)

GetField deserializes raw as an any, applying the field hint for fieldName. Use this when you've already navigated to the raw bytes and know the field name.

func (*RawMap) UnmarshalAstraRaw
func (m *RawMap) UnmarshalAstraRaw(ctx DecodeCtx, value []byte) error

UnmarshalAstraRaw captures the decode context and decodes the value as a map[string]json.RawMessage, deferring per-field deserialization to GetAny/DecodeAny.

type SerFlags

type SerFlags int
const (
	// TrustRawMessage can be used as a slight optimization for when internal code has something it knows for sure is trusted.
	TrustRawMessage SerFlags = 1 << iota

	// SortMapKeys can be used to force the keys of a map to be sorted using datatypes.ComparatorFor when serializing
	SortMapKeys

	// SerNoCache can be used to disable the serdes cache for serialization.
	SerNoCache

	// UseJSONMarshal can be used to recognize the standard library's json.Marshaler interface.
	// Custom Astra marshalers still take precedence.
	UseJSONMarshal
)

type Target

type Target int
const (
	TargetNone Target = iota
	TargetCollection
	TargetTable
)
func (Target) String
func (t Target) String() string

type TargetDecodeCtx

type TargetDecodeCtx interface {
	UntypedTargetInterface() reflect.Type
	NewUntypedTarget(ctx DecodeCtx, p unsafe.Pointer) AstraRawUnmarshaler
}