encoding

package
v1.18.9 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package encoding implements hdb field type encodings and decodings.

Index

Constants

View Source
const IntegerFieldSize = 4

IntegerFieldSize constant.

Variables

View Source
var ErrDecimalOutOfRange = errors.New("decimal out of range error")

ErrDecimalOutOfRange means that a big.Rat exceeds the size of hdb decimal fields.

Functions

This section is empty.

Types

type Decimal added in v1.17.2

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

Decimal is the internal representation of a decimal value as mantissa and exponent.

func NewDecimalFromDecompose added in v1.17.2

func NewDecimalFromDecompose(form byte, negative bool, coefficient []byte, exponent int32) (Decimal, error)

NewDecimalFromDecompose creates a Decimal (dec128) from decimalDecompose parts.

func NewDecimalFromRat added in v1.17.2

func NewDecimalFromRat(r *big.Rat) (Decimal, error)

NewDecimalFromRat creates a Decimal (dec128) from a *big.Rat.

func NewFixedFromDecompose added in v1.17.2

func NewFixedFromDecompose(form byte, negative bool, coefficient []byte, exponent int32, prec, scale int) (Decimal, error)

NewFixedFromDecompose creates a Decimal (fixed) from decimalDecompose parts.

func NewFixedFromRat added in v1.17.2

func NewFixedFromRat(r *big.Rat, prec, scale int) (Decimal, error)

NewFixedFromRat creates a Decimal (fixed) from a *big.Rat.

func (Decimal) AsRat added in v1.17.2

func (d Decimal) AsRat(v *big.Rat)

AsRat returns the decimal value as a *big.Rat.

func (Decimal) Decompose added in v1.17.2

func (d Decimal) Decompose(buf []byte) (form byte, negative bool, coefficient []byte, exponent int32)

Decompose implements the database/sql decimalDecompose interface.

type Decoder

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

Decoder decodes hdb protocol datatypes on basis of an buffer.

Decoder primitives slice the buffer using lengths/counts taken from the wire. A read is length-checked first: if the buffer is shorter than the read requires - an internally inconsistent frame, which a correct server never sends - the read panics ShortBufferError rather than a raw slice-bounds error. The typed panic lets the part-decode boundary recover it deterministically (see protocol.recoverShortBuffer) and fail just the current statement, while a genuine driver bug (a different panic) still crashes.

func NewDecoder

func NewDecoder(buf []byte, tr transform.Transformer) *Decoder

NewDecoder returns a new Decoder over buf using tr for CESU-8 -> UTF-8 field decoding. Either argument may be nil (nil buf: set later via SetBuffer; nil tr: no CESU-8 field decoding on this decoder).

func (*Decoder) AlphanumField added in v1.8.14

func (d *Decoder) AlphanumField(alphanumDfv1 bool) (any, error)

AlphanumField decodes an alphanum field.

func (*Decoder) AuthBigUint32 added in v1.16.2

func (d *Decoder) AuthBigUint32() (uint32, error)

AuthBigUint32 decodes an auth big uint32 field.

func (*Decoder) AuthBytes added in v1.16.2

func (d *Decoder) AuthBytes() []byte

AuthBytes decodes an auth variable bytes field.

func (*Decoder) AuthCesu8String added in v1.16.2

func (d *Decoder) AuthCesu8String() (string, error)

AuthCesu8String decodes an auth variable cesu8 string field.

func (*Decoder) AuthString added in v1.16.2

func (d *Decoder) AuthString() string

AuthString decodes an auth variable string field.

func (*Decoder) AuthVarFieldInd added in v1.16.2

func (d *Decoder) AuthVarFieldInd() int

AuthVarFieldInd decodes an auth variable field indicator.

func (*Decoder) Bool

func (d *Decoder) Bool() bool

Bool decodes a boolean.

func (*Decoder) BooleanField added in v1.8.14

func (d *Decoder) BooleanField() (any, error)

BooleanField decodes a boolean field.

func (*Decoder) Buffer added in v1.18.6

func (d *Decoder) Buffer() []byte

Buffer returns the decoder's (remaining) buffer.

func (*Decoder) Byte

func (d *Decoder) Byte() byte

Byte decodes a byte.

func (*Decoder) Bytes

func (d *Decoder) Bytes(n int) []byte

Bytes decodes bytes.

func (*Decoder) CESU8Bytes

func (d *Decoder) CESU8Bytes(size int) ([]byte, error)

CESU8Bytes decodes CESU-8 into UTF-8 bytes. - error is only returned in case of conversion errors.

func (*Decoder) CESU8LIBytes added in v0.107.3

func (d *Decoder) CESU8LIBytes() (int, []byte, error)

CESU8LIBytes decodes CESU-8 into UTF-8 bytes with length indicator.

func (*Decoder) CESU8LIString added in v0.107.3

func (d *Decoder) CESU8LIString() (int, string, error)

CESU8LIString decodes a CESU-8 into a UTF-8 string with length indicator.

func (*Decoder) Cesu8Field added in v1.8.14

func (d *Decoder) Cesu8Field() (any, error)

Cesu8Field decodes a cesu8 field.

func (*Decoder) DateField added in v1.8.14

func (d *Decoder) DateField() (any, error)

DateField decodes a date field.

func (*Decoder) DaydateField added in v1.8.14

func (d *Decoder) DaydateField(emptyDateAsNull bool) (any, error)

DaydateField decodes a daydate field.

func (*Decoder) Decimal

func (d *Decoder) Decimal() (*big.Int, int, error)

Decimal decodes a decimal. - error is only returned in case of conversion errors.

func (*Decoder) DecimalField added in v1.8.14

func (d *Decoder) DecimalField() (any, error)

DecimalField decodes a decimal field.

func (*Decoder) DoubleField added in v1.8.14

func (d *Decoder) DoubleField() (any, error)

DoubleField decodes a double field.

func (*Decoder) Fixed

func (d *Decoder) Fixed(size int) *big.Int

Fixed decodes a fixed decimal.

func (*Decoder) Fixed8Field added in v1.8.14

func (d *Decoder) Fixed8Field(scale int) (any, error)

Fixed8Field decodes a fixed8 field.

func (*Decoder) Fixed12Field added in v1.8.14

func (d *Decoder) Fixed12Field(scale int) (any, error)

Fixed12Field decodes a fixed12 field.

func (*Decoder) Fixed16Field added in v1.8.14

func (d *Decoder) Fixed16Field(scale int) (any, error)

Fixed16Field decodes a fixed16 field.

func (*Decoder) Float32

func (d *Decoder) Float32() float32

Float32 decodes a float32.

func (*Decoder) Float64

func (d *Decoder) Float64() float64

Float64 decodes a float64.

func (*Decoder) HexField added in v1.8.14

func (d *Decoder) HexField() (any, error)

HexField decodes a hex field.

func (*Decoder) Int8

func (d *Decoder) Int8() int8

Int8 decodes an int8.

func (*Decoder) Int16

func (d *Decoder) Int16() int16

Int16 decodes an int16.

func (*Decoder) Int32

func (d *Decoder) Int32() int32

Int32 decodes an int32.

func (*Decoder) Int64

func (d *Decoder) Int64() int64

Int64 decodes an int64.

func (*Decoder) LIBytes added in v0.107.3

func (d *Decoder) LIBytes() (int, []byte)

LIBytes decodes bytes with length indicator.

func (*Decoder) LIString added in v0.107.3

func (d *Decoder) LIString() (n int, s string)

LIString decodes a string with length indicator.

func (*Decoder) LongdateField added in v1.8.14

func (d *Decoder) LongdateField() (any, error)

LongdateField decodes a longdate field.

func (*Decoder) RealField added in v1.8.14

func (d *Decoder) RealField() (any, error)

RealField decodes a real field.

func (*Decoder) SeconddateField added in v1.8.14

func (d *Decoder) SeconddateField() (any, error)

SeconddateField decodes a seconddate field.

func (*Decoder) SecondtimeField added in v1.8.14

func (d *Decoder) SecondtimeField() (any, error)

SecondtimeField decodes a secondtime field.

func (*Decoder) SetBuffer added in v1.18.6

func (d *Decoder) SetBuffer(buf []byte)

SetBuffer points the decoder at buf, resetting its read position. The transformer is retained.

func (*Decoder) Skip

func (d *Decoder) Skip(cnt int)

Skip skips cnt bytes from reading.

func (*Decoder) Str added in v1.17.2

func (d *Decoder) Str(n int) string

Str decodes strings.

func (*Decoder) TimeField added in v1.8.14

func (d *Decoder) TimeField() (any, error)

TimeField decodes a time field.

func (*Decoder) TimestampField added in v1.8.14

func (d *Decoder) TimestampField() (any, error)

TimestampField decodes a timestamp field.

func (*Decoder) Transformer added in v1.8.21

func (d *Decoder) Transformer() transform.Transformer

Transformer returns the decoder's CESU-8 transformer.

func (*Decoder) Uint16

func (d *Decoder) Uint16() uint16

Uint16 decodes an uint16.

func (*Decoder) Uint16ByteOrder added in v0.107.0

func (d *Decoder) Uint16ByteOrder(byteOrder binary.ByteOrder) uint16

Uint16ByteOrder decodes an uint16 in given byte order.

func (*Decoder) Uint32

func (d *Decoder) Uint32() uint32

Uint32 decodes an uint32.

func (*Decoder) Uint32ByteOrder

func (d *Decoder) Uint32ByteOrder(byteOrder binary.ByteOrder) uint32

Uint32ByteOrder decodes an uint32 in given byte order.

func (*Decoder) Uint64

func (d *Decoder) Uint64() uint64

Uint64 decodes an uint64.

func (*Decoder) VarField added in v1.8.14

func (d *Decoder) VarField() (any, error)

VarField decodes a var field.

type Encoder

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

Encoder encodes hdb protocol datatypes on basis of an io.Writer.

func NewEncoder

func NewEncoder(buf []byte, tr transform.Transformer) *Encoder

NewEncoder returns a new Encoder over buf using tr for UTF-8 -> CESU-8 field encoding. Either argument may be nil (nil buf: append from empty; nil tr: no CESU-8 field encoding on this encoder).

func (*Encoder) BigintField added in v1.8.14

func (e *Encoder) BigintField(v any) error

BigintField encodes a bigint field.

func (*Encoder) Bool

func (e *Encoder) Bool(v bool)

Bool encodes a boolean.

func (*Encoder) BooleanField added in v1.8.14

func (e *Encoder) BooleanField(v any) error

BooleanField encodes a boolean field.

func (*Encoder) Buffer added in v1.18.6

func (e *Encoder) Buffer() []byte

Buffer returns the encoder's accumulated buffer.

func (*Encoder) Byte

func (e *Encoder) Byte(b byte)

Byte encodes a byte.

func (*Encoder) Bytes

func (e *Encoder) Bytes(p []byte)

Bytes encodes bytes.

func (*Encoder) CESU8Bytes

func (e *Encoder) CESU8Bytes(p []byte) (int, error)

CESU8Bytes encodes UTF-8 bytes into CESU-8 and returns the CESU-8 bytes written.

func (*Encoder) CESU8LIBytes added in v0.107.3

func (e *Encoder) CESU8LIBytes(p []byte) error

CESU8LIBytes encodes UTF-8 into CESU-8 bytes with length indicator.

func (*Encoder) CESU8LIString added in v0.107.3

func (e *Encoder) CESU8LIString(s string) error

CESU8LIString encodes an UTF-8 into a CESU-8 string with length indicator.

func (*Encoder) CESU8String

func (e *Encoder) CESU8String(s string) (int, error)

CESU8String encodes an UTF-8 string into CESU-8 and returns the CESU-8 bytes written.

func (*Encoder) Cesu8Field added in v1.8.14

func (e *Encoder) Cesu8Field(v any) error

Cesu8Field encodes a cesu8 field.

func (*Encoder) DateField added in v1.8.14

func (e *Encoder) DateField(v any) error

DateField encodes a date field.

func (*Encoder) DaydateField added in v1.8.14

func (e *Encoder) DaydateField(v any) error

DaydateField encodes a daydate field.

func (*Encoder) Decimal

func (e *Encoder) Decimal(m *big.Int, exp int)

Decimal encodes a decimal value.

func (*Encoder) DecimalField added in v1.8.14

func (e *Encoder) DecimalField(v any) error

DecimalField encodes a decimal field.

func (*Encoder) DoubleField added in v1.8.14

func (e *Encoder) DoubleField(v any) error

DoubleField encodes a double field.

func (*Encoder) Fixed

func (e *Encoder) Fixed(m *big.Int, size int)

Fixed encodes a fixed decimal value. Fixed consumes m: for negative values it mutates m in place (two's complement). Callers must pass a freshly allocated, single-use *big.Int (do not reuse m afterwards).

func (*Encoder) FixedField added in v1.17.2

func (e *Encoder) FixedField(v any, size int) error

FixedField encodes a fixed field.

func (*Encoder) Float32

func (e *Encoder) Float32(f float32)

Float32 encodes a float32.

func (*Encoder) Float64

func (e *Encoder) Float64(f float64)

Float64 encodes a float64.

func (*Encoder) HexField added in v1.8.14

func (e *Encoder) HexField(v any) error

HexField encodes a hex field.

func (*Encoder) Int8

func (e *Encoder) Int8(i8 int8)

Int8 encodes an int8.

func (*Encoder) Int16

func (e *Encoder) Int16(i16 int16)

Int16 encodes an int16.

func (*Encoder) Int32

func (e *Encoder) Int32(i32 int32)

Int32 encodes an int32.

func (*Encoder) Int64

func (e *Encoder) Int64(i64 int64)

Int64 encodes an int64.

func (*Encoder) IntegerField added in v1.8.14

func (e *Encoder) IntegerField(v any) error

IntegerField encodes an integer field.

func (*Encoder) LIBytes added in v0.107.3

func (e *Encoder) LIBytes(p []byte) error

LIBytes encodes bytes with length indicator.

func (*Encoder) LIString added in v0.107.3

func (e *Encoder) LIString(s string) error

LIString encodes a string with length indicator.

func (*Encoder) LongdateField added in v1.8.14

func (e *Encoder) LongdateField(v any) error

LongdateField encodes a longdate field.

func (*Encoder) RealField added in v1.8.14

func (e *Encoder) RealField(v any) error

RealField encodes a real field.

func (*Encoder) SeconddateField added in v1.8.14

func (e *Encoder) SeconddateField(v any) error

SeconddateField encodes a seconddate field.

func (*Encoder) SecondtimeField added in v1.8.14

func (e *Encoder) SecondtimeField(v any) error

SecondtimeField encodes a secondtime field.

func (*Encoder) SetBuffer added in v1.18.6

func (e *Encoder) SetBuffer(buf []byte)

SetBuffer points the encoder at buf (its write head is len(buf)). The transformer is retained.

func (*Encoder) SmallintField added in v1.8.14

func (e *Encoder) SmallintField(v any) error

SmallintField encodes a smallint field.

func (*Encoder) String

func (e *Encoder) String(s string)

String encodes a string.

func (*Encoder) TimeField added in v1.8.14

func (e *Encoder) TimeField(v any) error

TimeField encodes a time field.

func (*Encoder) TimestampField added in v1.8.14

func (e *Encoder) TimestampField(v any) error

TimestampField encodes a timestamp field.

func (*Encoder) TinyintField added in v1.8.14

func (e *Encoder) TinyintField(v any) error

TinyintField encodes a tinyint field.

func (*Encoder) Transformer added in v1.18.6

func (e *Encoder) Transformer() transform.Transformer

Transformer returns the encoder's CESU-8 transformer, e.g. to seed a separate encoder that must encode CESU-8 with the same transformer (see auth.Prms).

func (*Encoder) Uint16

func (e *Encoder) Uint16(u16 uint16)

Uint16 encodes an uint16.

func (*Encoder) Uint16ByteOrder added in v0.107.0

func (e *Encoder) Uint16ByteOrder(u16 uint16, byteOrder binary.ByteOrder)

Uint16ByteOrder encodes an uint16 in given byte order.

func (*Encoder) Uint32

func (e *Encoder) Uint32(u32 uint32)

Uint32 encodes an uint32.

func (*Encoder) Uint64

func (e *Encoder) Uint64(u64 uint64)

Uint64 encodes an uint64.

func (*Encoder) VarField added in v1.8.14

func (e *Encoder) VarField(v any) error

VarField encodes a var field.

func (*Encoder) Zeroes

func (e *Encoder) Zeroes(n int)

Zeroes encodes cnt zero byte values.

type ShortBufferError added in v1.18.2

type ShortBufferError struct{ Need, Have int }

ShortBufferError is panicked by a Decoder read that would consume more bytes than remain in the buffer - a truncated or internally inconsistent part payload, which a correct server never sends. It is recovered at the part-decode boundary and turned into a normal statement error; it is not meant to escape the protocol layer.

func (ShortBufferError) Error added in v1.18.2

func (e ShortBufferError) Error() string

Jump to

Keyboard shortcuts

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