pb

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package pb provides native binary encoding for badger protobuf types. This implementation replaces protobuf with direct binary encoding for reduced dependencies and faster serialization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(m Marshaler) ([]byte, error)

Marshal marshals a Marshaler to bytes.

func Size

func Size(m Sizer) int

Size returns the encoded size of a Sizer.

func Unmarshal

func Unmarshal(data []byte, m Unmarshaler) error

Unmarshal unmarshals bytes into an Unmarshaler.

Types

type Checksum

type Checksum struct {
	Algo Checksum_Algorithm
	Sum  uint64
}

Checksum represents a checksum with algorithm.

func (*Checksum) GetAlgo

func (c *Checksum) GetAlgo() Checksum_Algorithm

func (*Checksum) GetSum

func (c *Checksum) GetSum() uint64

func (*Checksum) Marshal

func (c *Checksum) Marshal() ([]byte, error)

Marshal encodes Checksum to binary format.

func (*Checksum) Reset

func (c *Checksum) Reset()

func (*Checksum) Size

func (c *Checksum) Size() int

Size returns the encoded size of Checksum. Format: [algo:4][sum:8]

func (*Checksum) String

func (c *Checksum) String() string

func (*Checksum) Unmarshal

func (c *Checksum) Unmarshal(data []byte) error

Unmarshal decodes Checksum from binary format.

type Checksum_Algorithm

type Checksum_Algorithm int32

Checksum_Algorithm defines checksum algorithm type.

const (
	Checksum_CRC32C   Checksum_Algorithm = 0
	Checksum_XXHash64 Checksum_Algorithm = 1
)

type DataKey

type DataKey struct {
	KeyId     uint64
	Data      []byte
	Iv        []byte
	CreatedAt int64
}

DataKey represents an encryption data key.

func (*DataKey) GetCreatedAt

func (d *DataKey) GetCreatedAt() int64

func (*DataKey) GetData

func (d *DataKey) GetData() []byte

func (*DataKey) GetIv

func (d *DataKey) GetIv() []byte

func (*DataKey) GetKeyId

func (d *DataKey) GetKeyId() uint64

func (*DataKey) Marshal

func (d *DataKey) Marshal() ([]byte, error)

Marshal encodes DataKey to binary format.

func (*DataKey) Reset

func (d *DataKey) Reset()

func (*DataKey) Size

func (d *DataKey) Size() int

Size returns the encoded size of DataKey. Format: [keyId:8][dataLen:4][data][ivLen:4][iv][createdAt:8]

func (*DataKey) String

func (d *DataKey) String() string

func (*DataKey) Unmarshal

func (d *DataKey) Unmarshal(data []byte) error

Unmarshal decodes DataKey from binary format.

type EncryptionAlgo

type EncryptionAlgo int32

EncryptionAlgo defines encryption algorithm type.

const (
	EncryptionAlgo_aes EncryptionAlgo = 0
)

type KV

type KV struct {
	Key        []byte
	Value      []byte
	UserMeta   []byte
	Version    uint64
	ExpiresAt  uint64
	Meta       []byte
	StreamId   uint32
	StreamDone bool
}

KV represents a key-value pair.

func (*KV) Clone

func (k *KV) Clone() *KV

Clone returns a deep copy of KV.

func (*KV) GetExpiresAt

func (k *KV) GetExpiresAt() uint64

func (*KV) GetKey

func (k *KV) GetKey() []byte

func (*KV) GetMeta

func (k *KV) GetMeta() []byte

func (*KV) GetStreamDone

func (k *KV) GetStreamDone() bool

func (*KV) GetStreamId

func (k *KV) GetStreamId() uint32

func (*KV) GetUserMeta

func (k *KV) GetUserMeta() []byte

func (*KV) GetValue

func (k *KV) GetValue() []byte

func (*KV) GetVersion

func (k *KV) GetVersion() uint64

func (*KV) Marshal

func (k *KV) Marshal() ([]byte, error)

Marshal encodes KV to binary format.

func (*KV) MarshalToSizedBuffer

func (k *KV) MarshalToSizedBuffer(buf []byte) (int, error)

MarshalToSizedBuffer marshals KV to a pre-allocated buffer.

func (*KV) Reset

func (k *KV) Reset()

func (*KV) Size

func (k *KV) Size() int

Size returns the encoded size of KV. Format: [keyLen:4][key][valueLen:4][value][userMetaLen:4][userMeta]

[version:8][expiresAt:8][metaLen:4][meta][streamId:4][streamDone:1]

func (*KV) String

func (k *KV) String() string

func (*KV) Unmarshal

func (k *KV) Unmarshal(data []byte) error

Unmarshal decodes KV from binary format.

type KVList

type KVList struct {
	Kv       []*KV
	AllocRef uint64
}

KVList represents a list of KV pairs.

func (*KVList) GetAllocRef

func (l *KVList) GetAllocRef() uint64

func (*KVList) GetKv

func (l *KVList) GetKv() []*KV

func (*KVList) Marshal

func (l *KVList) Marshal() ([]byte, error)

Marshal encodes KVList to binary format.

func (*KVList) Reset

func (l *KVList) Reset()

func (*KVList) Size

func (l *KVList) Size() int

Size returns the encoded size of KVList.

func (*KVList) String

func (l *KVList) String() string

func (*KVList) Unmarshal

func (l *KVList) Unmarshal(data []byte) error

Unmarshal decodes KVList from binary format.

type ManifestChange

type ManifestChange struct {
	Id             uint64
	Op             ManifestChange_Operation
	Level          uint32
	KeyId          uint64
	EncryptionAlgo EncryptionAlgo
	Compression    uint32
}

ManifestChange represents a change to the manifest.

func (*ManifestChange) GetCompression

func (m *ManifestChange) GetCompression() uint32

func (*ManifestChange) GetEncryptionAlgo

func (m *ManifestChange) GetEncryptionAlgo() EncryptionAlgo

func (*ManifestChange) GetId

func (m *ManifestChange) GetId() uint64

func (*ManifestChange) GetKeyId

func (m *ManifestChange) GetKeyId() uint64

func (*ManifestChange) GetLevel

func (m *ManifestChange) GetLevel() uint32

func (*ManifestChange) GetOp

func (*ManifestChange) Marshal

func (m *ManifestChange) Marshal() ([]byte, error)

Marshal encodes ManifestChange to binary format.

func (*ManifestChange) Reset

func (m *ManifestChange) Reset()

func (*ManifestChange) Size

func (m *ManifestChange) Size() int

Size returns the encoded size of ManifestChange. Format: [id:8][op:4][level:4][keyId:8][encryptionAlgo:4][compression:4]

func (*ManifestChange) String

func (m *ManifestChange) String() string

func (*ManifestChange) Unmarshal

func (m *ManifestChange) Unmarshal(data []byte) error

Unmarshal decodes ManifestChange from binary format.

type ManifestChangeSet

type ManifestChangeSet struct {
	Changes []*ManifestChange
}

ManifestChangeSet represents a set of manifest changes.

func (*ManifestChangeSet) GetChanges

func (m *ManifestChangeSet) GetChanges() []*ManifestChange

func (*ManifestChangeSet) Marshal

func (m *ManifestChangeSet) Marshal() ([]byte, error)

Marshal encodes ManifestChangeSet to binary format.

func (*ManifestChangeSet) Reset

func (m *ManifestChangeSet) Reset()

func (*ManifestChangeSet) Size

func (m *ManifestChangeSet) Size() int

Size returns the encoded size of ManifestChangeSet.

func (*ManifestChangeSet) String

func (m *ManifestChangeSet) String() string

func (*ManifestChangeSet) Unmarshal

func (m *ManifestChangeSet) Unmarshal(data []byte) error

Unmarshal decodes ManifestChangeSet from binary format.

type ManifestChange_Operation

type ManifestChange_Operation int32

ManifestChange_Operation defines manifest change operations.

const (
	ManifestChange_CREATE ManifestChange_Operation = 0
	ManifestChange_DELETE ManifestChange_Operation = 1
)

type MarshalOptions

type MarshalOptions struct{}

MarshalOptions provides options for marshaling (compatibility with protobuf API).

func (MarshalOptions) MarshalAppend

func (MarshalOptions) MarshalAppend(b []byte, m Marshaler) ([]byte, error)

MarshalAppend appends the marshaled form to the provided buffer.

type Marshaler

type Marshaler interface {
	Marshal() ([]byte, error)
}

Marshaler is the interface for types that can marshal themselves.

type Match

type Match struct {
	Prefix      []byte
	IgnoreBytes string
}

Match represents a match pattern.

func (*Match) GetIgnoreBytes

func (m *Match) GetIgnoreBytes() string

func (*Match) GetPrefix

func (m *Match) GetPrefix() []byte

func (*Match) Marshal

func (m *Match) Marshal() ([]byte, error)

Marshal encodes Match to binary format.

func (*Match) Reset

func (m *Match) Reset()

func (*Match) Size

func (m *Match) Size() int

Size returns the encoded size of Match. Format: [prefixLen:4][prefix][ignoreBytesLen:4][ignoreBytes]

func (*Match) String

func (m *Match) String() string

func (*Match) Unmarshal

func (m *Match) Unmarshal(data []byte) error

Unmarshal decodes Match from binary format.

type Sizer

type Sizer interface {
	Size() int
}

Sizer is the interface for types that can report their encoded size.

type Unmarshaler

type Unmarshaler interface {
	Unmarshal([]byte) error
}

Unmarshaler is the interface for types that can unmarshal themselves.

Jump to

Keyboard shortcuts

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