ormfield

package
v1.0.0-alpha.12 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 a google.protobuf.Duration value as 12 bytes using Int64Codec for seconds followed by Int32Codec for nanos. This allows for sorted iteration.

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 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 DurationCodec encodes a google.protobuf.Timestamp value as 12 bytes using Int64Codec for seconds followed by Int32Codec for nanos. This allows for sorted iteration.

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

Jump to

Keyboard shortcuts

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