ormfield

package
v1.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DurationSecondsMin int64 = -315576000000
	DurationSecondsMax int64 = 315576000000
	DurationNanosMin         = -999999999
	DurationNanosMax         = 999999999
)
View Source
const (
	TimestampSecondsMin int64 = -62135596800
	TimestampSecondsMax int64 = 253402300799
	TimestampNanosMax         = 999999999
)

Variables

This section is empty.

Functions

func DecodeCompactUint32

func DecodeCompactUint32(reader io.Reader) (uint32, error)

DecodeCompactUint32 decodes a uint32 encoded with EncodeCompactU32.

func DecodeCompactUint64

func DecodeCompactUint64(reader io.Reader) (uint64, error)

func EncodeCompactUint32

func EncodeCompactUint32(x uint32) []byte

EncodeCompactUint32 encodes uint32 values in 2,3,4 or 5 bytes. Unlike regular varints, this encoding is suitable for ordered prefix scans. The length of the output + 2 is encoded in the first 2 bits of the first byte and the remaining bits encoded with big-endian ordering. Values less than 2^14 fill fit in 2 bytes, values less than 2^22 will fit in 3, and values less than 2^30 will fit in 4.

func EncodeCompactUint64

func EncodeCompactUint64(x uint64) []byte

EncodeCompactUint64 encodes uint64 values in 2,4,6 or 9 bytes. Unlike regular varints, this encoding is suitable for ordered prefix scans. The first two bits of the first byte indicate the length of the buffer - 00 for 2, 01 for 4, 10 for 6 and 11 for 9. The remaining bits are encoded with big-endian ordering. Values less than 2^14 fill fit in 2 bytes, values less than 2^30 will fit in 4, and values less than 2^46 will fit in 6.

Types

type BoolCodec

type BoolCodec struct{}

BoolCodec encodes a bool value as a single byte 0 or 1.

func (BoolCodec) Compare

func (b BoolCodec) Compare(v1, v2 protoreflect.Value) int

func (BoolCodec) ComputeBufferSize

func (b BoolCodec) ComputeBufferSize(protoreflect.Value) (int, error)

func (BoolCodec) Decode

func (b BoolCodec) Decode(r Reader) (protoreflect.Value, error)

func (BoolCodec) Encode

func (b BoolCodec) Encode(value protoreflect.Value, w io.Writer) error

func (BoolCodec) FixedBufferSize

func (b BoolCodec) FixedBufferSize() int

func (BoolCodec) IsOrdered

func (b BoolCodec) IsOrdered() bool

type BytesCodec

type BytesCodec struct{}

BytesCodec encodes bytes as raw bytes. It errors if the byte array is longer than 255 bytes.

func (BytesCodec) Compare

func (b BytesCodec) Compare(v1, v2 protoreflect.Value) int

func (BytesCodec) ComputeBufferSize

func (b BytesCodec) ComputeBufferSize(value protoreflect.Value) (int, error)

ComputeBufferSize returns the bytes size of the value.

func (BytesCodec) Decode

func (b BytesCodec) Decode(r Reader) (protoreflect.Value, error)

func (BytesCodec) Encode

func (b BytesCodec) Encode(value protoreflect.Value, w io.Writer) error

func (BytesCodec) FixedBufferSize

func (b BytesCodec) FixedBufferSize() int

func (BytesCodec) IsOrdered

func (b BytesCodec) IsOrdered() bool

type Codec

type Codec interface {
	// Decode decodes a value in a key.
	Decode(r Reader) (protoreflect.Value, error)

	// Encode encodes a value in a key.
	Encode(value protoreflect.Value, w io.Writer) error

	// Compare compares two values of this type and should primarily be used
	// for testing.
	Compare(v1, v2 protoreflect.Value) int

	// IsOrdered returns true if callers can always assume that this ordering
	// is suitable for sorted iteration.
	IsOrdered() bool

	// FixedBufferSize returns a positive value if encoders should assume a
	// fixed size buffer for encoding. Encoders will use at most this much size
	// to encode the value.
	FixedBufferSize() int

	// ComputeBufferSize estimates the buffer size needed to encode the field.
	// Encoders will use at most this much size to encode the value.
	ComputeBufferSize(value protoreflect.Value) (int, error)
}

Codec defines an interface for decoding and encoding values in ORM index keys.

func GetCodec

func GetCodec(field protoreflect.FieldDescriptor, nonTerminal bool) (Codec, error)

GetCodec returns the Codec for the provided field if one is defined. nonTerminal should be set to true if this value is being encoded as a non-terminal segment of a multi-part key.

type CompactUint32Codec

type CompactUint32Codec struct{}

CompactUint32Codec encodes uint32 values using EncodeCompactUint32.

func (CompactUint32Codec) Compare

func (c CompactUint32Codec) Compare(v1, v2 protoreflect.Value) int

func (CompactUint32Codec) ComputeBufferSize

func (c CompactUint32Codec) ComputeBufferSize(protoreflect.Value) (int, error)

func (CompactUint32Codec) Decode

func (CompactUint32Codec) Encode

func (c CompactUint32Codec) Encode(value protoreflect.Value, w io.Writer) error

func (CompactUint32Codec) FixedBufferSize

func (c CompactUint32Codec) FixedBufferSize() int

func (CompactUint32Codec) IsOrdered

func (c CompactUint32Codec) IsOrdered() bool

type CompactUint64Codec

type CompactUint64Codec struct{}

CompactUint64Codec encodes uint64 values using EncodeCompactUint64.

func (CompactUint64Codec) Compare

func (c CompactUint64Codec) Compare(v1, v2 protoreflect.Value) int

func (CompactUint64Codec) ComputeBufferSize

func (c CompactUint64Codec) ComputeBufferSize(protoreflect.Value) (int, error)

func (CompactUint64Codec) Decode

func (CompactUint64Codec) Encode

func (c CompactUint64Codec) Encode(value protoreflect.Value, w io.Writer) error

func (CompactUint64Codec) FixedBufferSize

func (c CompactUint64Codec) FixedBufferSize() int

func (CompactUint64Codec) IsOrdered

func (c CompactUint64Codec) IsOrdered() bool

type DurationCodec

type DurationCodec struct{}

DurationCodec encodes google.protobuf.Duration values with the following encoding: - nil is encoded as []byte{0xFF} - seconds (which can range from -315,576,000,000 to +315,576,000,000) is encoded as 5 fixed bytes - nanos (which can range from 0 to 999,999,999 or -999,999,999 to 0 if seconds is negative) is encoded as:

  • []byte{0x0} for zero nanos
  • 4 fixed bytes with the bit mask 0xC0 applied to the first byte, with negative nanos scaled so that -999,999,999 is encoded as 1 and -1 is encoded as 999,999,999

When iterating over timestamp indexes, nil values will always be ordered last.

Values for seconds and nanos outside the ranges specified by google.protobuf.Duration will be rejected.

func (DurationCodec) Compare

func (d DurationCodec) Compare(v1, v2 protoreflect.Value) int

func (DurationCodec) ComputeBufferSize

func (d DurationCodec) ComputeBufferSize(protoreflect.Value) (int, error)

func (DurationCodec) Decode

func (d DurationCodec) Decode(r Reader) (protoreflect.Value, error)

func (DurationCodec) Encode

func (d DurationCodec) Encode(value protoreflect.Value, w io.Writer) error

func (DurationCodec) FixedBufferSize

func (d DurationCodec) FixedBufferSize() int

func (DurationCodec) IsOrdered

func (d DurationCodec) IsOrdered() bool

type DurationV0Codec

type DurationV0Codec struct{}

DurationV0Codec encodes a google.protobuf.Duration value as 12 bytes using Int64Codec for seconds followed by Int32Codec for nanos. This allows for sorted iteration.

func (DurationV0Codec) Compare

func (d DurationV0Codec) Compare(v1, v2 protoreflect.Value) int

func (DurationV0Codec) ComputeBufferSize

func (d DurationV0Codec) ComputeBufferSize(protoreflect.Value) (int, error)

func (DurationV0Codec) Decode

func (DurationV0Codec) Encode

func (d DurationV0Codec) Encode(value protoreflect.Value, w io.Writer) error

func (DurationV0Codec) FixedBufferSize

func (d DurationV0Codec) FixedBufferSize() int

func (DurationV0Codec) IsOrdered

func (d DurationV0Codec) IsOrdered() bool

type EnumCodec

type EnumCodec struct{}

EnumCodec encodes enum values as varints.

func (EnumCodec) Compare

func (e EnumCodec) Compare(v1, v2 protoreflect.Value) int

func (EnumCodec) ComputeBufferSize

func (e EnumCodec) ComputeBufferSize(protoreflect.Value) (int, error)

func (EnumCodec) Decode

func (e EnumCodec) Decode(r Reader) (protoreflect.Value, error)

func (EnumCodec) Encode

func (e EnumCodec) Encode(value protoreflect.Value, w io.Writer) error

func (EnumCodec) FixedBufferSize

func (e EnumCodec) FixedBufferSize() int

func (EnumCodec) IsOrdered

func (e EnumCodec) IsOrdered() bool

type FixedUint32Codec

type FixedUint32Codec struct{}

FixedUint32Codec encodes uint32 values as 4-byte big-endian integers.

func (FixedUint32Codec) Compare

func (u FixedUint32Codec) Compare(v1, v2 protoreflect.Value) int

func (FixedUint32Codec) ComputeBufferSize

func (u FixedUint32Codec) ComputeBufferSize(protoreflect.Value) (int, error)

func (FixedUint32Codec) Decode

func (FixedUint32Codec) Encode

func (u FixedUint32Codec) Encode(value protoreflect.Value, w io.Writer) error

func (FixedUint32Codec) FixedBufferSize

func (u FixedUint32Codec) FixedBufferSize() int

func (FixedUint32Codec) IsOrdered

func (u FixedUint32Codec) IsOrdered() bool

type FixedUint64Codec

type FixedUint64Codec struct{}

FixedUint64Codec encodes uint64 values as 8-byte big-endian integers.

func (FixedUint64Codec) Compare

func (u FixedUint64Codec) Compare(v1, v2 protoreflect.Value) int

func (FixedUint64Codec) ComputeBufferSize

func (u FixedUint64Codec) ComputeBufferSize(protoreflect.Value) (int, error)

func (FixedUint64Codec) Decode

func (FixedUint64Codec) Encode

func (u FixedUint64Codec) Encode(value protoreflect.Value, w io.Writer) error

func (FixedUint64Codec) FixedBufferSize

func (u FixedUint64Codec) FixedBufferSize() int

func (FixedUint64Codec) IsOrdered

func (u FixedUint64Codec) IsOrdered() bool

type Int32Codec

type Int32Codec struct{}

Int32Codec encodes 32-bit integers as big-endian unsigned 32-bit integers by adding the maximum value of int32 (2147583647) + 1 before encoding so that these values can be used for ordered iteration.

func (Int32Codec) Compare

func (i Int32Codec) Compare(v1, v2 protoreflect.Value) int

func (Int32Codec) ComputeBufferSize

func (i Int32Codec) ComputeBufferSize(protoreflect.Value) (int, error)

func (Int32Codec) Decode

func (i Int32Codec) Decode(r Reader) (protoreflect.Value, error)

func (Int32Codec) Encode

func (i Int32Codec) Encode(value protoreflect.Value, w io.Writer) error

func (Int32Codec) FixedBufferSize

func (i Int32Codec) FixedBufferSize() int

func (Int32Codec) IsOrdered

func (i Int32Codec) IsOrdered() bool

type Int64Codec

type Int64Codec struct{}

Int64Codec encodes 64-bit integers as big-endian unsigned 64-bit integers by adding the maximum value of int32 (9223372036854775807) + 1 before encoding so that these values can be used for ordered iteration.

func (Int64Codec) Compare

func (i Int64Codec) Compare(v1, v2 protoreflect.Value) int

func (Int64Codec) ComputeBufferSize

func (i Int64Codec) ComputeBufferSize(protoreflect.Value) (int, error)

func (Int64Codec) Decode

func (i Int64Codec) Decode(r Reader) (protoreflect.Value, error)

func (Int64Codec) Encode

func (i Int64Codec) Encode(value protoreflect.Value, w io.Writer) error

func (Int64Codec) FixedBufferSize

func (i Int64Codec) FixedBufferSize() int

func (Int64Codec) IsOrdered

func (i Int64Codec) IsOrdered() bool

type NonTerminalBytesCodec

type NonTerminalBytesCodec struct{}

NonTerminalBytesCodec encodes bytes as raw bytes length prefixed by a single byte. It errors if the byte array is longer than 255 bytes.

func (NonTerminalBytesCodec) Compare

func (b NonTerminalBytesCodec) Compare(v1, v2 protoreflect.Value) int

func (NonTerminalBytesCodec) ComputeBufferSize

func (b NonTerminalBytesCodec) ComputeBufferSize(value protoreflect.Value) (int, error)

ComputeBufferSize returns the bytes size of the value plus the length of the varint length-prefix.

func (NonTerminalBytesCodec) Decode

func (NonTerminalBytesCodec) Encode

func (NonTerminalBytesCodec) FixedBufferSize

func (b NonTerminalBytesCodec) FixedBufferSize() int

func (NonTerminalBytesCodec) IsOrdered

func (b NonTerminalBytesCodec) IsOrdered() bool

type NonTerminalStringCodec

type NonTerminalStringCodec struct{}

NonTerminalStringCodec encodes strings as null-terminated raw bytes. Null values within strings will produce an error.

func (NonTerminalStringCodec) Compare

func (s NonTerminalStringCodec) Compare(v1, v2 protoreflect.Value) int

func (NonTerminalStringCodec) ComputeBufferSize

func (s NonTerminalStringCodec) ComputeBufferSize(value protoreflect.Value) (int, error)

func (NonTerminalStringCodec) Decode

func (NonTerminalStringCodec) Encode

func (NonTerminalStringCodec) FixedBufferSize

func (s NonTerminalStringCodec) FixedBufferSize() int

func (NonTerminalStringCodec) IsOrdered

func (s NonTerminalStringCodec) IsOrdered() bool

type Reader

type Reader interface {
	io.Reader
	io.ByteReader
}

type StringCodec

type StringCodec struct{}

StringCodec encodes strings as raw bytes.

func (StringCodec) Compare

func (s StringCodec) Compare(v1, v2 protoreflect.Value) int

func (StringCodec) ComputeBufferSize

func (s StringCodec) ComputeBufferSize(value protoreflect.Value) (int, error)

func (StringCodec) Decode

func (s StringCodec) Decode(r Reader) (protoreflect.Value, error)

func (StringCodec) Encode

func (s StringCodec) Encode(value protoreflect.Value, w io.Writer) error

func (StringCodec) FixedBufferSize

func (s StringCodec) FixedBufferSize() int

func (StringCodec) IsOrdered

func (s StringCodec) IsOrdered() bool

type TimestampCodec

type TimestampCodec struct{}

TimestampCodec encodes google.protobuf.Timestamp values with the following encoding: - nil is encoded as []byte{0xFF} - seconds (which can range from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z) is encoded as 5 fixed bytes - nanos (which can range from 0 to 999,999,999) is encoded as:

  • []byte{0x0} for zero nanos
  • 4 fixed bytes with the bit mask 0xC0 applied to the first byte

When iterating over timestamp indexes, nil values will always be ordered last.

Values for seconds and nanos outside the ranges specified by google.protobuf.Timestamp will be rejected.

func (TimestampCodec) Compare

func (t TimestampCodec) Compare(v1, v2 protoreflect.Value) int

func (TimestampCodec) ComputeBufferSize

func (t TimestampCodec) ComputeBufferSize(protoreflect.Value) (int, error)

func (TimestampCodec) Decode

func (t TimestampCodec) Decode(r Reader) (protoreflect.Value, error)

func (TimestampCodec) Encode

func (t TimestampCodec) Encode(value protoreflect.Value, w io.Writer) error

func (TimestampCodec) FixedBufferSize

func (t TimestampCodec) FixedBufferSize() int

func (TimestampCodec) IsOrdered

func (t TimestampCodec) IsOrdered() bool

type TimestampV0Codec

type TimestampV0Codec struct{}

TimestampV0Codec encodes a google.protobuf.Timestamp value as 12 bytes using Int64Codec for seconds followed by Int32Codec for nanos. This type does not encode nil values correctly, but is retained in order to allow users of the previous encoding to successfully migrate from this encoding to the new encoding specified by TimestampCodec.

func (TimestampV0Codec) Compare

func (t TimestampV0Codec) Compare(v1, v2 protoreflect.Value) int

func (TimestampV0Codec) ComputeBufferSize

func (t TimestampV0Codec) ComputeBufferSize(protoreflect.Value) (int, error)

func (TimestampV0Codec) Decode

func (TimestampV0Codec) Encode

func (t TimestampV0Codec) Encode(value protoreflect.Value, w io.Writer) error

func (TimestampV0Codec) FixedBufferSize

func (t TimestampV0Codec) FixedBufferSize() int

func (TimestampV0Codec) IsOrdered

func (t TimestampV0Codec) IsOrdered() bool

Jump to

Keyboard shortcuts

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