recobj

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package recobj is the format of a record object: the one object an ingest batch becomes, as docs/reference/bucket-contract.md specifies it.

The body is newline-delimited JSON, zstd-compressed, and each line is

{"hash":"<hex sha256>","record":{...}}

where record is the profile's copy in its canonical form (RFC 8785 over the protobuf JSON mapping) and hash is the SHA-256 of exactly that encoding. The object's own SHA-256 and its record count are metadata, so that a reader needs a listing and a HEAD and never a body.

The writer builds objects here and every reader takes them apart here, so the format has one definition in the code as it has one in the contract.

Index

Constants

View Source
const (
	ContentType = "application/x-ndjson"
	Encoding    = "zstd"
)

ContentType and Encoding are what an object is stored as.

Variables

This section is empty.

Functions

func CheckMetadata

func CheckMetadata(meta map[string]string, stored []byte, lines int) []string

CheckMetadata compares what an object's metadata says with the object: the format, the sha256 of the stored bytes and the number of records. Every disagreement is returned, so that a report can say all of them.

func Encode

func Encode(lines [][]byte) (body []byte, metadata map[string]string)

Encode builds an object's stored bytes and metadata from its lines.

func EncodeLine

func EncodeLine(canonical []byte) []byte

EncodeLine makes the line for a record already in canonical form. The bytes are embedded as they are, so that the hash is over what is on the line.

func Hash

func Hash(canonical []byte) string

Hash is the hash of a record: the hex SHA-256 of its canonical encoding.

func Metadata

func Metadata(stored []byte, count int) map[string]string

Metadata is the metadata an object of these stored bytes and this many records carries.

func SHA256

func SHA256(stored []byte) string

SHA256 is the hex SHA-256 of an object's stored bytes, which is what the sha256 metadata holds.

Types

type Line

type Line struct {
	// Hash is what the line claims for its record.
	Hash string `json:"hash"`
	// Record is the record as written, canonical.
	Record json.RawMessage `json:"record"`
}

Line is one record of an object, as the object has it.

func Decode

func Decode(stored []byte) ([]Line, error)

Decode decompresses an object and reads its lines. It does not check any hash: Verify does, and a reader that only wants the records does not pay for it.

func (Line) Decoded

func (l Line) Decoded() (*record.Record, error)

Decoded reads the record of a line.

func (Line) Verify

func (l Line) Verify() error

Verify checks that a line's hash is the hash of its record: the record is put in canonical form, so a line written by another implementation with other whitespace still checks, and hashed.

Jump to

Keyboard shortcuts

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