serialization

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Protocol Buffer Code Generation Guide

Status: internal and not wired to the tracker. This package lives under internal/ so that it is not part of the module's public API. Nothing in the tracker reads or writes these messages yet, and the schema predates two changes to the data structure, so revise it before using it:

  • Buckets are placed with SipHash-2-4 under a 128-bit key. The schema still describes MURMURHASH_32 with a 32-bit seed.
  • A bucket's last-update time is a signed count of milliseconds since its structure was built, not an unsigned wall-clock timestamp.

This package provides serialization and deserialization APIs for the FairStruct Protocol Buffer message. The Go code (v1.pb.go) is generated from the Protocol Buffer definition (v1.proto).

Creating and Managing pb.go Files

Use the project Makefile from the root directory:

# Generate Protocol Buffer code
make proto

make build, make test and make all use the checked-in v1.pb.go and do not regenerate it. Run make proto only after changing v1.proto, with protoc 3.20.3 and protoc-gen-go v1.36.10: CI compares the checked-in file byte for byte, and other versions produce different output, starting with the version header.

Manual Setup (Optional)

If you prefer to generate proto files manually:

Step 1: Install Prerequisites
# Install Protocol Buffer compiler
# See installation guide: https://protobuf.dev/downloads/
# 
# CI pins protoc 3.20.3. A package manager usually installs a newer release,
# whose output differs in the version header and fails the CI check.
# Quick install options:
# - macOS: brew install protobuf
# - Ubuntu/Debian: apt install protobuf-compiler
# - Windows: Download from releases or use chocolatey: choco install protoc

# Install the Go Protocol Buffer plugin at the version CI pins
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.10

# Verify installation
protoc --version
which protoc-gen-go
Step 2: Generate Go Code from Proto Files
protoc --go_out=. --go_opt=paths=source_relative v1.proto

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LevelSquashingFunction_name = map[int32]string{
		0: "LEVEL_SQUASHING_FUNCTION_MIN",
		1: "LEVEL_SQUASHING_FUNCTION_MEAN",
	}
	LevelSquashingFunction_value = map[string]int32{
		"LEVEL_SQUASHING_FUNCTION_MIN":  0,
		"LEVEL_SQUASHING_FUNCTION_MEAN": 1,
	}
)

Enum value maps for LevelSquashingFunction.

View Source
var (
	Algorithm_name = map[int32]string{
		0: "MURMURHASH_32",
	}
	Algorithm_value = map[string]int32{
		"MURMURHASH_32": 0,
	}
)

Enum value maps for Algorithm.

Functions

This section is empty.

Types

type AlgoParams

type AlgoParams struct {
	Algorithm  Algorithm `protobuf:"varint,1,opt,name=algorithm,proto3,enum=fair.data.v1.Algorithm" json:"algorithm,omitempty"`
	MurmurSeed uint32    `protobuf:"varint,2,opt,name=murmur_seed,json=murmurSeed,proto3" json:"murmur_seed,omitempty"`
	// contains filtered or unexported fields
}

AlgoParams holds the choice of Algorithm and the relevant parameters

func (*AlgoParams) Descriptor deprecated

func (*AlgoParams) Descriptor() ([]byte, []int)

Deprecated: Use AlgoParams.ProtoReflect.Descriptor instead.

func (*AlgoParams) GetAlgorithm

func (x *AlgoParams) GetAlgorithm() Algorithm

func (*AlgoParams) GetMurmurSeed

func (x *AlgoParams) GetMurmurSeed() uint32

func (*AlgoParams) ProtoMessage

func (*AlgoParams) ProtoMessage()

func (*AlgoParams) ProtoReflect

func (x *AlgoParams) ProtoReflect() protoreflect.Message

func (*AlgoParams) Reset

func (x *AlgoParams) Reset()

func (*AlgoParams) String

func (x *AlgoParams) String() string

type Algorithm

type Algorithm int32
const (
	Algorithm_MURMURHASH_32 Algorithm = 0
)

func (Algorithm) Descriptor

func (Algorithm) Descriptor() protoreflect.EnumDescriptor

func (Algorithm) Enum

func (x Algorithm) Enum() *Algorithm

func (Algorithm) EnumDescriptor deprecated

func (Algorithm) EnumDescriptor() ([]byte, []int)

Deprecated: Use Algorithm.Descriptor instead.

func (Algorithm) Number

func (x Algorithm) Number() protoreflect.EnumNumber

func (Algorithm) String

func (x Algorithm) String() string

func (Algorithm) Type

type Bucket

type Bucket struct {
	Probability       float64 `protobuf:"fixed64,1,opt,name=probability,proto3" json:"probability,omitempty"`
	LastUpdatedTimeMs uint64  `protobuf:"varint,2,opt,name=last_updated_time_ms,json=lastUpdatedTimeMs,proto3" json:"last_updated_time_ms,omitempty"`
	// contains filtered or unexported fields
}

Bucket holds the proability and the last update time

func (*Bucket) Descriptor deprecated

func (*Bucket) Descriptor() ([]byte, []int)

Deprecated: Use Bucket.ProtoReflect.Descriptor instead.

func (*Bucket) GetLastUpdatedTimeMs

func (x *Bucket) GetLastUpdatedTimeMs() uint64

func (*Bucket) GetProbability

func (x *Bucket) GetProbability() float64

func (*Bucket) ProtoMessage

func (*Bucket) ProtoMessage()

func (*Bucket) ProtoReflect

func (x *Bucket) ProtoReflect() protoreflect.Message

func (*Bucket) Reset

func (x *Bucket) Reset()

func (*Bucket) String

func (x *Bucket) String() string

type FairData

type FairData struct {
	Levels []*Level `protobuf:"bytes,1,rep,name=levels,proto3" json:"levels,omitempty"`
	// contains filtered or unexported fields
}

FairData holds the tracking data containing multiple levels (L levels)

func (*FairData) Descriptor deprecated

func (*FairData) Descriptor() ([]byte, []int)

Deprecated: Use FairData.ProtoReflect.Descriptor instead.

func (*FairData) GetLevels

func (x *FairData) GetLevels() []*Level

func (*FairData) ProtoMessage

func (*FairData) ProtoMessage()

func (*FairData) ProtoReflect

func (x *FairData) ProtoReflect() protoreflect.Message

func (*FairData) Reset

func (x *FairData) Reset()

func (*FairData) String

func (x *FairData) String() string

type FairRunParameters

type FairRunParameters struct {
	AlgoParams *AlgoParams `protobuf:"bytes,1,opt,name=algo_params,json=algoParams,proto3" json:"algo_params,omitempty"`
	// contains filtered or unexported fields
}

FairRunParameters contains the runtime params with the instance of Fair

func (*FairRunParameters) Descriptor deprecated

func (*FairRunParameters) Descriptor() ([]byte, []int)

Deprecated: Use FairRunParameters.ProtoReflect.Descriptor instead.

func (*FairRunParameters) GetAlgoParams

func (x *FairRunParameters) GetAlgoParams() *AlgoParams

func (*FairRunParameters) ProtoMessage

func (*FairRunParameters) ProtoMessage()

func (*FairRunParameters) ProtoReflect

func (x *FairRunParameters) ProtoReflect() protoreflect.Message

func (*FairRunParameters) Reset

func (x *FairRunParameters) Reset()

func (*FairRunParameters) String

func (x *FairRunParameters) String() string

type FairRuntimeData

type FairRuntimeData struct {
	Runtime *FairRunParameters `protobuf:"bytes,1,opt,name=runtime,proto3" json:"runtime,omitempty"`
	Data    *FairData          `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

Holds the parameters and the associated data

func (*FairRuntimeData) Descriptor deprecated

func (*FairRuntimeData) Descriptor() ([]byte, []int)

Deprecated: Use FairRuntimeData.ProtoReflect.Descriptor instead.

func (*FairRuntimeData) GetData

func (x *FairRuntimeData) GetData() *FairData

func (*FairRuntimeData) GetRuntime

func (x *FairRuntimeData) GetRuntime() *FairRunParameters

func (*FairRuntimeData) ProtoMessage

func (*FairRuntimeData) ProtoMessage()

func (*FairRuntimeData) ProtoReflect

func (x *FairRuntimeData) ProtoReflect() protoreflect.Message

func (*FairRuntimeData) Reset

func (x *FairRuntimeData) Reset()

func (*FairRuntimeData) String

func (x *FairRuntimeData) String() string

type FairStruct

type FairStruct struct {
	Cfg  *TrackerCfg      `protobuf:"bytes,1,opt,name=cfg,proto3" json:"cfg,omitempty"`
	Data *FairRuntimeData `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	Meta *HostMeta        `protobuf:"bytes,3,opt,name=meta,proto3" json:"meta,omitempty"`
	// contains filtered or unexported fields
}

FairStruct - wraps up the config, parameters and the data associated with a Fair Tracker

func (*FairStruct) Descriptor deprecated

func (*FairStruct) Descriptor() ([]byte, []int)

Deprecated: Use FairStruct.ProtoReflect.Descriptor instead.

func (*FairStruct) GetCfg

func (x *FairStruct) GetCfg() *TrackerCfg

func (*FairStruct) GetData

func (x *FairStruct) GetData() *FairRuntimeData

func (*FairStruct) GetMeta

func (x *FairStruct) GetMeta() *HostMeta

func (*FairStruct) ProtoMessage

func (*FairStruct) ProtoMessage()

func (*FairStruct) ProtoReflect

func (x *FairStruct) ProtoReflect() protoreflect.Message

func (*FairStruct) Reset

func (x *FairStruct) Reset()

func (*FairStruct) String

func (x *FairStruct) String() string

type HostMeta

type HostMeta struct {
	HostGuid       string `protobuf:"bytes,1,opt,name=host_guid,json=hostGuid,proto3" json:"host_guid,omitempty"`
	SerializedAtMs uint64 `protobuf:"varint,2,opt,name=serialized_at_ms,json=serializedAtMs,proto3" json:"serialized_at_ms,omitempty"`
	// contains filtered or unexported fields
}

Metadata to uniquely identify a host

func (*HostMeta) Descriptor deprecated

func (*HostMeta) Descriptor() ([]byte, []int)

Deprecated: Use HostMeta.ProtoReflect.Descriptor instead.

func (*HostMeta) GetHostGuid

func (x *HostMeta) GetHostGuid() string

func (*HostMeta) GetSerializedAtMs

func (x *HostMeta) GetSerializedAtMs() uint64

func (*HostMeta) ProtoMessage

func (*HostMeta) ProtoMessage()

func (*HostMeta) ProtoReflect

func (x *HostMeta) ProtoReflect() protoreflect.Message

func (*HostMeta) Reset

func (x *HostMeta) Reset()

func (*HostMeta) String

func (x *HostMeta) String() string

type Level

type Level struct {
	Buckets []*Bucket `protobuf:"bytes,1,rep,name=buckets,proto3" json:"buckets,omitempty"`
	// contains filtered or unexported fields
}

Each level holds an array of Buckets (M Buckets)

func (*Level) Descriptor deprecated

func (*Level) Descriptor() ([]byte, []int)

Deprecated: Use Level.ProtoReflect.Descriptor instead.

func (*Level) GetBuckets

func (x *Level) GetBuckets() []*Bucket

func (*Level) ProtoMessage

func (*Level) ProtoMessage()

func (*Level) ProtoReflect

func (x *Level) ProtoReflect() protoreflect.Message

func (*Level) Reset

func (x *Level) Reset()

func (*Level) String

func (x *Level) String() string

type LevelSquashingFunction

type LevelSquashingFunction int32

Controls how we arrive at the final probability from all the buckets at a level

const (
	LevelSquashingFunction_LEVEL_SQUASHING_FUNCTION_MIN  LevelSquashingFunction = 0
	LevelSquashingFunction_LEVEL_SQUASHING_FUNCTION_MEAN LevelSquashingFunction = 1
)

func (LevelSquashingFunction) Descriptor

func (LevelSquashingFunction) Enum

func (LevelSquashingFunction) EnumDescriptor deprecated

func (LevelSquashingFunction) EnumDescriptor() ([]byte, []int)

Deprecated: Use LevelSquashingFunction.Descriptor instead.

func (LevelSquashingFunction) Number

func (LevelSquashingFunction) String

func (x LevelSquashingFunction) String() string

func (LevelSquashingFunction) Type

type Serializer

type Serializer struct{}

Serializer handles serialization and deserialization of FairStruct

func NewSerializer

func NewSerializer() *Serializer

NewSerializer creates a new serializer instance

func (*Serializer) Deserialize

func (s *Serializer) Deserialize(data []byte) (ft *FairStruct, err error)

Deserialize converts bytes back to a FairStruct

func (*Serializer) DeserializeFromJSON

func (s *Serializer) DeserializeFromJSON(data []byte) (fst *FairStruct, err error)

DeserializeFromJSON converts JSON bytes back to a FairStruct

func (*Serializer) Serialize

func (s *Serializer) Serialize(fairStruct *FairStruct) (result []byte, err error)

Serialize converts a FairStruct to bytes

func (*Serializer) SerializeToJSON

func (s *Serializer) SerializeToJSON(fairStruct *FairStruct) (stuff []byte, err error)

SerializeToJSON converts a FairStruct to JSON bytes

type TrackerCfg

type TrackerCfg struct {

	// Unique ID per tracker config
	TrackerId string `protobuf:"bytes,1,opt,name=tracker_id,json=trackerId,proto3" json:"tracker_id,omitempty"`
	// Version the tracker config
	ConfigVersion uint64 `protobuf:"varint,2,opt,name=config_version,json=configVersion,proto3" json:"config_version,omitempty"`
	// Number of buckets per level
	M uint32 `protobuf:"varint,3,opt,name=m,proto3" json:"m,omitempty"`
	// Number of levels per tracker
	L uint32 `protobuf:"varint,4,opt,name=l,proto3" json:"l,omitempty"`
	// Increment probability used on failed requests
	Pi float64 `protobuf:"fixed64,5,opt,name=pi,proto3" json:"pi,omitempty"`
	// Decrement probability used on successfull requests
	Pd float64 `protobuf:"fixed64,6,opt,name=pd,proto3" json:"pd,omitempty"`
	// Deacy rate for bucket proabilities
	Lambda float64 `protobuf:"fixed64,7,opt,name=lambda,proto3" json:"lambda,omitempty"`
	// Controls how often the internal structures are rotated
	RotationFrequency *durationpb.Duration `protobuf:"bytes,8,opt,name=rotation_frequency,json=rotationFrequency,proto3" json:"rotation_frequency,omitempty"`
	// Controls the logic for arriving at the final probability from all the buckets at a level
	LevelSquashFn LevelSquashingFunction `` /* 144-byte string literal not displayed */
	// contains filtered or unexported fields
}

TrackerCfg contains all the configurations related to a tracker

func (*TrackerCfg) Descriptor deprecated

func (*TrackerCfg) Descriptor() ([]byte, []int)

Deprecated: Use TrackerCfg.ProtoReflect.Descriptor instead.

func (*TrackerCfg) GetConfigVersion

func (x *TrackerCfg) GetConfigVersion() uint64

func (*TrackerCfg) GetL

func (x *TrackerCfg) GetL() uint32

func (*TrackerCfg) GetLambda

func (x *TrackerCfg) GetLambda() float64

func (*TrackerCfg) GetLevelSquashFn

func (x *TrackerCfg) GetLevelSquashFn() LevelSquashingFunction

func (*TrackerCfg) GetM

func (x *TrackerCfg) GetM() uint32

func (*TrackerCfg) GetPd

func (x *TrackerCfg) GetPd() float64

func (*TrackerCfg) GetPi

func (x *TrackerCfg) GetPi() float64

func (*TrackerCfg) GetRotationFrequency

func (x *TrackerCfg) GetRotationFrequency() *durationpb.Duration

func (*TrackerCfg) GetTrackerId

func (x *TrackerCfg) GetTrackerId() string

func (*TrackerCfg) ProtoMessage

func (*TrackerCfg) ProtoMessage()

func (*TrackerCfg) ProtoReflect

func (x *TrackerCfg) ProtoReflect() protoreflect.Message

func (*TrackerCfg) Reset

func (x *TrackerCfg) Reset()

func (*TrackerCfg) String

func (x *TrackerCfg) String() string

Jump to

Keyboard shortcuts

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