Top.Mail.Ru
package decoder — KubFly SDK for Go

KubFly SDK for Go / decoder

package decoder

import "kubfly.io/sdk/decoder"

Package decoder reads the KubFly format at its lowest level — segments, record frames, the references of bodies and the envelope of the cipher: the kubfly-sdk-decoder module of the Java SDK. Its constants and the nested entities are of the package format. The collector writes with it, the reflector reads with it (sdk/spec/format.md).

Constants

const (
	// AttachmentPackVersion is the version of a pack of attachments.
	AttachmentPackVersion = 1
	// AttachmentPackHead is the bytes a reader asks for first: the header, with room for many recipients.
	AttachmentPackHead = 16 * 1024
)
const (
	// EnvelopeFingerprint is the size of the fingerprint of a recipient: the first bytes of the SHA-256 of its key.
	EnvelopeFingerprint = 16
	// EnvelopePublicKeySize is the size of a public key: ML-KEM-1024, then the point of P-384 uncompressed.
	EnvelopePublicKeySize = 1665
	// EnvelopePrivateKeySize is the size of a private key: a seed.
	EnvelopePrivateKeySize = 32
	// EnvelopeEnc is the size of an encapsulated key: the ciphertext of the KEM.
	EnvelopeEnc = 1665
	// EnvelopeWrapped is the size of a wrapped data key: 32 bytes and the tag.
	EnvelopeWrapped = 48
	// EnvelopeRecipientSize is the size of a recipient in a header.
	EnvelopeRecipientSize = EnvelopeFingerprint + EnvelopeEnc + EnvelopeWrapped
	// EnvelopeTag is the size of a tag of AES-GCM.
	EnvelopeTag = 16
	// EnvelopeKEM is the KEM identifier of HPKE: MLKEM1024-P384.
	EnvelopeKEM = 0x0051
	// EnvelopePublicPEM is the label of a PEM block of a public key: the KEM identifier, two bytes, then the key.
	EnvelopePublicPEM = "KUBFLY PUBLIC KEY"
	// EnvelopePrivatePEM is the label of a PEM block of a private key: the KEM identifier, two bytes, then the seed.
	EnvelopePrivatePEM = "KUBFLY PRIVATE KEY"
)

The envelope of an encrypted segment (format.md §11, decisions 40 and 71): a random AES-256 data key per segment, wrapped for every recipient by HPKE (RFC 9180) in its base mode — the post-quantum hybrid KEM MLKEM1024-P384 (0x0051), HKDF-SHA384, AES-256-GCM, info "kubfly-segment-v1" — and the blocks and the table sealed by AES-256-GCM with the data key: the nonce is 8 zero bytes and the block number big-endian, the AAD the header without its CRC. There is no other suite: the envelope is always post-quantum.

const CatalogName = "catalog.kfl"

CatalogName is the name of the catalog of the metrics of a process beside start-*.kfl of its instance.

const CatalogVersion = 1

CatalogVersion is the version of the catalog this reader knows.

const CodeMost = 64 << 20

CodeMost are the most bytes of an inflated body: a damaged or hostile object does not take the memory.

const CodeSourcesFileMost = 1 << 20

CodeSourcesFileMost are the most bytes of a file taken into the code of a build.

const CodeSourcesMost = 48 << 20

CodeSourcesMost are the most bytes of the texts of a build.

const CodeStream = "code/v1/"

CodeStream is the prefix of the stream of the code of the builds: code/v1/.

const CodeVersion = 1

CodeVersion is the version of the code of a build this reader and writer know.

Functions

func AttachmentBlockSize

func AttachmentBlockSize(header []byte, attachment *api.Attachment) int

AttachmentBlockSize is the size of the block of an attachment in its pack: the content, and the tag with the envelope.

func AttachmentPackHeaderLength

func AttachmentPackHeaderLength(head []byte) (int, error)

AttachmentPackHeaderLength is the length of the header of a pack, read from its first bytes; more than the bytes given — ask for that many.

func AttachmentPackKey

func AttachmentPackKey(namespace, service, pod, container string, instance uuid.UUID, pack int64) string

AttachmentPackKey is the key of a pack of attachments (format.md §10d): the blobs, the images and the long strings of the events of an instance, laid into a half of the buffer of attachments of its output and put by one request — attachments/v1/<ns>/<service>/<pod>/<container>/<instance>/<pack>.kfb, the number of ten digits, as AttachmentPack.key of the Java SDK.

func BodiesException

func BodiesException(cursor *format.Cursor, refs Refs)

BodiesException walks an exception: class, message, stack, flags, [cause], suppressed.

func BodiesString

func BodiesString(cursor *format.Cursor, refs Refs)

BodiesString walks a string of the dictionary: id << 1 — a number, length << 1 | 1 — the text in place.

func BodiesStrings

func BodiesStrings(cursor *format.Cursor, refs Refs, count int)

BodiesStrings walks the levels of a path: strings of the dictionary.

func BodiesTags

func BodiesTags(cursor *format.Cursor, refs Refs)

BodiesTags walks tags: their number, then a key (a string of the dictionary) and a value (a string) each.

func BodiesValue

func BodiesValue(cursor *format.Cursor, refs Refs)

BodiesValue walks a value: its kind byte (| 0x80 — null), then its encoding (§4.3).

func BodiesWalk

func BodiesWalk(typ int, cursor *format.Cursor, refs Refs) (err error)

BodiesWalk walks the body of a record (format.md §4) to its end and reports what it refers to — the strings of the dictionary, the stack traces, the metrics — without decoding the values or allocating: the collector uses it when it releases records into a segment (the definitions each segment must carry), and it checks every record on the way. A body that does not end where its record does is a *format.Error.

func CodeCommit

func CodeCommit(dir string) string

CodeCommit is the short SHA of the commit checked out in a directory of a repository of Git; "" — unknown (no Git, out of a repository, any failure) — as CodeRevision.commit of the Java SDK.

func CodeFileValid

func CodeFileValid(path string) bool

CodeFileValid tells whether a path is one of the code: relative, its levels separated by /, none empty, . or .., no \ — as CodeFile.valid of the Java SDK.

func CodeKey

func CodeKey(build string) string

CodeKey is the key of the code of a build in the bucket (of its stand): code/v1/<build>.kfc.

func CodeRef

func CodeRef(dir string) string

CodeRef is the branch checked out, else — a detached head, as CI checks out — the tag of the commit; "" — unknown — as CodeRevision.ref of the Java SDK.

func CodeTaken

func CodeTaken(path string) bool

CodeTaken tells whether a path from the root of the sources is taken: no hidden level, no node_modules, a file of code by its extension (in any case) or of the build by its name. The build tools take the files by it too.

func Crc32c

func Crc32c(data []byte) uint32

Crc32c is the CRC32C of bytes.

func EncryptAttachment

func EncryptAttachment(header *AttachmentPackHeader, body []byte, offset int, size int) error

EncryptAttachment encrypts a block of the body of a pack in place: its content, then the tag in the EnvelopeTag bytes after it (the slice has room for them) — its number is its offset, the header its additional data.

func EnvelopeCipher

func EnvelopeCipher(dataKey []byte) (cipher.AEAD, error)

EnvelopeCipher is the AES-256-GCM of a data key, made once for a segment and kept for its blocks (EnvelopeSeal).

func EnvelopeDecrypt

func EnvelopeDecrypt(dataKey []byte, index uint32, aad []byte, stored []byte) ([]byte, error)

EnvelopeDecrypt opens a block (or the table, TableBlock) with the data key; a tag that does not match is a *format.Error: damaged, swapped or another key.

func EnvelopeEncrypt

func EnvelopeEncrypt(dataKey []byte, index uint32, aad []byte, plain []byte) ([]byte, error)

EnvelopeEncrypt seals a block (or the table, TableBlock) with the data key.

func EnvelopeFingerprintOf

func EnvelopeFingerprintOf(publicKey []byte) [EnvelopeFingerprint]byte

EnvelopeFingerprintOf is the fingerprint of a public key: the first 16 bytes of its SHA-256.

func EnvelopeSeal

func EnvelopeSeal(aead cipher.AEAD, dst []byte, index uint32, aad []byte, plain []byte) []byte

EnvelopeSeal encrypts a block or the table (TableBlock) with the cipher of the data key into a slice of the caller, appended to dst[:0]: the bytes, then the tag — no allocation while dst has room — EnvelopeEncrypt without making the cipher anew.

func EnvelopeUnwrap

func EnvelopeUnwrap(recipient EnvelopeRecipient, key *RecipientKey) ([]byte, error)

EnvelopeUnwrap unwraps the data key of a recipient with its private key.

func OpenObject

func OpenObject(data []byte, keys []*RecipientKey, version byte, what string, most int) (body []byte, err error)

OpenObject opens a sealed object: checks its header, its version and its CRC32C, decrypts and inflates its body, at most the bytes given; what names the object in the failures ("catalog of metrics"). A failure tells the rule and the offset, never the text — as Sealed.open of the Java SDK.

func ReadAttachment

func ReadAttachment(header []byte, block []byte, keys []*RecipientKey, attachment *api.Attachment) (content []byte,
	err error)

ReadAttachment is the content of an attachment from the header of its pack, whole, and its block, checked against what the record of its event says of it: the size and the SHA-256. A failure tells the rule, never the content — AttachmentPack.read of the Java SDK.

func SealObject

func SealObject(version byte, body []byte, keys []*RecipientPublicKey, level int) ([]byte, error)

SealObject seals a body (format.md §10, §10c) — the catalog of a process, the code of a build: in the open "KFLY", u8 version, u8 cipher (0 — none, 1 — the envelope of §11) and, with the envelope, varint recipients and each of them; then the body deflated (raw deflate) at the level and, with the envelope, encrypted with a new data key as block 0, the header its additional data; last a u32 CRC32C of the bytes before it — as Sealed.seal of the Java SDK.

func WriteCode

func WriteCode(code *Code, keys []*RecipientPublicKey, level int) ([]byte, error)

WriteCode is the object of the code of a build (format.md §10c), sealed (SealObject): the body — the commit, the ref and the version of the build, varint of the files left out, varint of the files, each its path, the 32 bytes of the SHA-256 of its text and its text (strings — varint length, UTF-8), by their paths — as Code.write of the Java SDK.

func WriteCodeArchive

func WriteCodeArchive(sources []CodeSource, out io.Writer) error

WriteCodeArchive writes the archive of the sources: the entries in the order of the sources, one time for all of them — the same sources, the same archive (as CodeArchive.write of the Java SDK).

Types

type AttachmentPackHeader

type AttachmentPackHeader struct {
	// Bytes are the header: "KFAT", u8 version, u8 cipher, [varint recipients and the recipients].
	Bytes []byte
	// DataKey is the data key of the pack, nil without a cipher.
	DataKey []byte
}

AttachmentPackHeader is the header of a pack and its data key (nil without a cipher).

func NewAttachmentPackHeader

func NewAttachmentPackHeader(keys []*RecipientPublicKey) (*AttachmentPackHeader, error)

NewAttachmentPackHeader is the header of a new pack: with keys a new data key, wrapped for each recipient — AttachmentPack.header of the Java SDK.

type Catalog

type Catalog struct {
	// Metrics are the metrics, by their paths.
	Metrics []CatalogMetric
	// Fields are the texts of the fields of STATUS, by their types and their names; empty — none (an older SDK).
	Fields []CatalogField
	// Params are the parameters, by their paths and names; empty — none (an older SDK).
	Params []CatalogParam
}

Catalog is the catalog of a process (catalog.kfl, ReadCatalog): its metrics, the texts of the fields of STATUS and the descriptions of the parameters.

func ReadCatalog

func ReadCatalog(data []byte, keys []*RecipientKey) (catalog *Catalog, err error)

ReadCatalog reads the catalog of a process, catalog.kfl beside start-*.kfl of its instance (format.md §10): every metric it defined, by their paths, without values, the labels and the hints of the fields of STATUS and the descriptions of the parameters in the language of the process — "KFLY", u8 version, u8 cipher, [recipients]; the body deflated and, with the envelope, encrypted; a CRC32C. A catalog of an older SDK has no fields or no parameters. The body may go on after the parameters — the sections of a later catalog: this reader skips them. One of the private keys opens an encrypted catalog. A failure tells the rule and the offset, never the text — as Catalog of the Java SDK.

type CatalogField

type CatalogField struct {
	// Type is the type, as in sdk/spec/entities.tsv: Status, status.api.State.
	Type string
	// Field is the name of the field.
	Field string
	// Label is the label, short.
	Label string
	// Hint is the hint: what the value is, in a line.
	Hint string
}

CatalogField is the texts of a field of STATUS in a catalog (catalog.kfl, ReadCatalog): its label and its hint for people, in the language of the process.

type CatalogMetric

type CatalogMetric struct {
	// Project is the first level of the path.
	Project string
	// Module is the second level of the path: a module of the build of the project.
	Module string
	// Area is the third level.
	Area string
	// System is the fourth level.
	System string
	// Component is the component.
	Component string
	// Measure is what is measured.
	Measure string
	// Scale are the decimal digits after the point.
	Scale int8
	// Units are the units.
	Units string
	// Description is what it measures, for people, in the language of the process; empty — none.
	Description string
	// Scoped tells whether a scope defined it.
	Scoped bool
}

CatalogMetric is a metric of the catalog of a process (catalog.kfl, ReadCatalog): its path, scale, units, description and whether a scope defined it — no values.

func (CatalogMetric) Path

func (m CatalogMetric) Path() string

Path is the path of the metric: project/module/area/system/component/measure.

type CatalogParam

type CatalogParam struct {
	// Name is the name: the variable of the environment that sets it.
	Name string
	// Path is the path: project/module/area/system.
	Path string
	// Units are the units, empty — none.
	Units string
	// Description is what it sets.
	Description string
}

CatalogParam is a parameter of the process in a catalog (catalog.kfl, ReadCatalog): its path, its units and its description for people, in the language of the process; its value is in START, STATUS and FINISH.

type Code

type Code struct {
	// Commit is the commit of the build, "" — unknown.
	Commit string
	// Ref is the branch or tag of the build, "" — unknown.
	Ref string
	// Version is the version of the application, "" — unknown.
	Version string
	// Skipped are the files the writer left out: too large, not text, over the limit of the object.
	Skipped int
	// Files are the files, by their paths.
	Files []CodeFile
}

Code is the code of a build (format.md §10c): the sources the build was made of, once in the bucket for every instance of it — code/v1/<build>.kfc, the build its KUBFLY_BUILD; the files by their paths in the order of their UTF-8 bytes (Go strings compare so). The first writer of a build wins: the object is never replaced.

func NewCode

func NewCode(commit, ref, version string, skipped int, files []CodeFile) (*Code, error)

NewCode is the code of a build, its files taken by their paths; two files of one path, a path that is not valid or a negative count of the files left out is a failure.

func ReadCode

func ReadCode(data []byte, keys []*RecipientKey) (code *Code, err error)

ReadCode reads the code of a build; one of the private keys opens an encrypted object. A damaged object, a newer version, a text that does not match its SHA-256 or a path out of its order is a failure that tells the rule and the offset, never a path or a text — as Code.read of the Java SDK.

func ReadCodeArchive

func ReadCodeArchive(data []byte, commit, ref, version string) (*Code, error)

ReadCodeArchive is the code of a build from a .zip of its sources in memory — the archive a build tool puts into the application — by the rules of ReadCodeSources. As the stream of the Java SDK, the files are read in the order of the archive and held up to CodeMost bytes: the files after are counted.

func ReadCodeSources

func ReadCodeSources(source string, commit, ref, version string) (*Code, error)

ReadCodeSources is the code of a build from its sources — a directory, or a .zip or .jar of them (format.md §10c): the files of code and of the build (CodeTaken); a file over CodeSourcesFileMost bytes, one that is not UTF-8 text or holds a NUL, and the files after the texts reach CodeSourcesMost bytes are left out and counted — in the order of their paths, so the same sources give the same code; the same rules as CodeSources of the Java SDK.

func (*Code) File

func (c *Code) File(path string) (CodeFile, bool)

File is the file of a path; false if the code has none.

func (*Code) Paths

func (c *Code) Paths() []string

Paths are the paths of the files, in their order.

func (*Code) String

func (c *Code) String() string

String is the counts, never a path or a text.

func (*Code) Text

func (c *Code) Text(path string) (string, bool)

Text is the text of the file of a path; false if the code has none.

type CodeFile

type CodeFile struct {
	// Path is the path: relative, its levels separated by / (src/main/java/shop/Orders.java).
	Path string
	// Text is the text, UTF-8 in the object.
	Text string
}

CodeFile is a file of the code of a build (Code): its path from the root of the sources and its text.

func (CodeFile) Digest

func (f CodeFile) Digest() [32]byte

Digest is the SHA-256 of the text, as the object holds it.

func (CodeFile) String

func (f CodeFile) String() string

String is the path and the size, never the text.

type CodeSource

type CodeSource struct {
	// Path is the path from the top.
	Path string
	// File is the file on the disk.
	File string
}

CodeSource is a file of the sources of a build for its archive: its path from the top of the project, levels separated by /, and its file.

func CollectCodeSources

func CollectCodeSources(top string, roots, files []string) ([]CodeSource, error)

CollectCodeSources are the files of the sources of a build for the archive a build tool puts into the application (format.md §10c): those CodeTaken takes under the roots and among the files of the build, by their paths from the top, in the order of their paths. Hidden directories and node_modules are not entered, links are passed over, files outside the top are left out; missing roots and files are passed over — as CodeArchive.collect of the Java SDK.

type EnvelopeRecipient

type EnvelopeRecipient struct {
	// Fingerprint is the first 16 bytes of the SHA-256 of the public key.
	Fingerprint [EnvelopeFingerprint]byte
	// Enc is the encapsulated key: the ciphertext of the KEM.
	Enc [EnvelopeEnc]byte
	// Wrapped is the data key sealed for the recipient.
	Wrapped [EnvelopeWrapped]byte
}

EnvelopeRecipient is a recipient of a segment in its header: the fingerprint of its public key, the encapsulated key and the wrapped data key.

func EnvelopeWrap

func EnvelopeWrap(publicKey *RecipientPublicKey, dataKey []byte) (EnvelopeRecipient, error)

EnvelopeWrap wraps a data key for a recipient.

type Order

type Order uint8

Order is the order of reading by time: the two orders of the direct index level of the keys.

const (
	// OrderDirect is by ascending time: the oldest first.
	OrderDirect Order = iota
	// OrderReverse is by descending time: the newest first.
	OrderReverse
)

The orders.

func (Order) String

func (o Order) String() string

String is the name of the order, as Java names its constants.

type RecipientKey

type RecipientKey struct {
	// contains filtered or unexported fields
}

RecipientKey is a private key of a recipient of encrypted segments, MLKEM1024-P384: derived from its seed of 32 bytes, with its public key and its fingerprint computed once. Its text is the fingerprint, never the key.

func GenerateRecipientKey

func GenerateRecipientKey() (*RecipientKey, error)

GenerateRecipientKey is a new key from a random seed.

func NewRecipientKey

func NewRecipientKey(seed []byte) (*RecipientKey, error)

NewRecipientKey is the key of a seed of 32 bytes; the seed is copied.

func RecipientKeyFromPEM

func RecipientKeyFromPEM(text string) (*RecipientKey, error)

RecipientKeyFromPEM is the key of a PEM block KUBFLY PRIVATE KEY, or of its body.

func (*RecipientKey) Fingerprint

func (k *RecipientKey) Fingerprint() [EnvelopeFingerprint]byte

Fingerprint is the fingerprint of the public key, as the headers of segments name recipients.

func (*RecipientKey) PEM

func (k *RecipientKey) PEM() string

PEM is the private key as a PEM block: the seed. Whoever has it reads the segments — keep it as a secret.

func (*RecipientKey) PublicKey

func (k *RecipientKey) PublicKey() *RecipientPublicKey

PublicKey is the public key, for KUBFLY_OUTPUT_BUCKET_KEYS: its PEM.

func (*RecipientKey) String

func (k *RecipientKey) String() string

String is the fingerprint, never the key.

type RecipientPublicKey

type RecipientPublicKey struct {
	// contains filtered or unexported fields
}

RecipientPublicKey is a public key of a recipient of encrypted segments, MLKEM1024-P384: 1665 bytes — the key of ML-KEM-1024, then the point of P-384 uncompressed — checked once, with the fingerprint the headers of segments name the recipient by. The collector encrypts for these keys; the private key stays with the recipient (RecipientKey). Its text is the fingerprint.

func NewRecipientPublicKey

func NewRecipientPublicKey(key []byte) (*RecipientPublicKey, error)

NewRecipientPublicKey is the key of its bytes; they are copied and checked.

func RecipientPublicKeyFromPEM

func RecipientPublicKeyFromPEM(text string) (*RecipientPublicKey, error)

RecipientPublicKeyFromPEM is the key of a PEM block KUBFLY PUBLIC KEY, or of its body — base64 on one line, as in KUBFLY_OUTPUT_BUCKET_KEYS, or on several.

func RecipientPublicKeyFromPEMAll

func RecipientPublicKeyFromPEMAll(text string) ([]*RecipientPublicKey, error)

RecipientPublicKeyFromPEMAll are the keys of every PEM block KUBFLY PUBLIC KEY of a text, as in KUBFLY_OUTPUT_BUCKET_KEYS_FILE, in their order; none when there is no block.

func (*RecipientPublicKey) Bytes

func (k *RecipientPublicKey) Bytes() []byte

Bytes is a copy of the key, 1665 bytes.

func (*RecipientPublicKey) Equal

func (k *RecipientPublicKey) Equal(other *RecipientPublicKey) bool

Equal is whether another is the same key.

func (*RecipientPublicKey) Fingerprint

func (k *RecipientPublicKey) Fingerprint() [EnvelopeFingerprint]byte

Fingerprint is the first 16 bytes of the SHA-256 of the key, as the headers of segments name recipients.

func (*RecipientPublicKey) PEM

func (k *RecipientPublicKey) PEM() string

PEM is the key as a PEM block, for KUBFLY_OUTPUT_BUCKET_KEYS and its file.

func (*RecipientPublicKey) String

func (k *RecipientPublicKey) String() string

String is the fingerprint.

type Refs

type Refs interface {
	// String is a string of the dictionary used.
	String(id int)
	// Trace is a stack trace used.
	Trace(id int)
	// Metric is a metric used.
	Metric(id int)
	// Stack is a node of the tree of stacks used: by a row of a profile, or as the parent of a node (0 — none, the
	// others: never reported).
	Stack(id int)
}

Refs receives the references a record makes to the definitions of its segment, as BodiesWalk walks it: the strings of the dictionary, the stack traces, the metrics and the nodes of the stacks of profiles. No allocation: numbers only.

type SegmentBlock

type SegmentBlock struct {
	// Offset is the offset of the block in the segment.
	Offset int64
	// Stored is the length stored.
	Stored int
	// Compressed tells whether the block is compressed.
	Compressed bool
	// Raw is the length uncompressed.
	Raw int
	// FirstStart is the offset of the first start of a record in the block, -1 — none.
	FirstStart int
	// Time is the time before the first record of the block.
	Time int64
	// ID is the number before the first record of the block.
	ID int64
	// CRC is the CRC32C of the stored bytes, without a cipher.
	CRC uint32
}

SegmentBlock is a block of the table.

type SegmentHeader

type SegmentHeader struct {
	// Major is the major version.
	Major int
	// Minor is the minor version.
	Minor int
	// SDK is the version of the SDK that wrote the segment.
	SDK util.Version
	// Stream is the stream: Events, Metrics, Alerts, Health, Traffic.
	Stream int
	// Compression is the compression: CompressionNone, CompressionDeflate.
	Compression int
	// Cipher is the cipher: CipherNone, CipherEnvelope.
	Cipher int
	// Language is the language of the texts of the process (English for an identifier this reader does not know).
	Language language.Language
	// Instance is the instance of the process.
	Instance uuid.UUID
	// Number is the number of the segment in the stream of the instance, from 0, in a row.
	Number int64
	// BlockSize is the size of the blocks, uncompressed.
	BlockSize int
	// Recipients are the recipients of the data key.
	Recipients []EnvelopeRecipient
	// Length is the length of the header with its CRC.
	Length int
}

SegmentHeader is the header of a segment.

type SegmentReader

type SegmentReader struct {
	// contains filtered or unexported fields
}

SegmentReader reads a segment (format.md §3): the header from the start, the trailer and the table from the end, the blocks on demand — forward from the first, backward from the last — so a reader of a remote object asks only for the ranges it needs. Not safe for concurrent use.

func NewSegmentReader

func NewSegmentReader(source SegmentSource, keys []*RecipientKey) (reader *SegmentReader, err error)

NewSegmentReader opens a segment: reads its header, takes the data key with the first private key it is wrapped for, reads the trailer and the table.

func (*SegmentReader) Block

func (r *SegmentReader) Block(index int) ([]byte, error)

Block reads a block, uncompressed.

func (*SegmentReader) Blocks

func (r *SegmentReader) Blocks() []SegmentBlock

Blocks are the blocks.

func (*SegmentReader) Definitions

func (r *SegmentReader) Definitions(visitor Visitor) (err error)

Definitions gives the copy of all definitions of the segment, from the table.

func (*SegmentReader) ForEach

func (r *SegmentReader) ForEach(order Order, visitor Visitor) (err error)

ForEach gives the records in an order: forward from the first block, or backward from the last, reading each block once and only when it is reached.

func (*SegmentReader) Header

func (r *SegmentReader) Header() SegmentHeader

Header is the header.

func (*SegmentReader) Size

func (r *SegmentReader) Size() int64

Size is the bytes of all records, uncompressed.

func (*SegmentReader) Summary

func (r *SegmentReader) Summary() SegmentSummary

Summary is the summary.

type SegmentSource

type SegmentSource interface {
	// Size is the size of the segment.
	Size() (int64, error)
	// Read is a range of the segment.
	Read(offset int64, length int) ([]byte, error)
}

SegmentSource are the bytes of a segment: a file, a slice, the ranges of an object.

func SourceOf

func SourceOf(data []byte) SegmentSource

SourceOf is a segment in a slice.

type SegmentSummary

type SegmentSummary struct {
	// Begin is the time of the first record.
	Begin int64
	// End is the time of the last record.
	End int64
	// LastID is the number of the last record.
	LastID int64
	// Counts are the counters of the stream (format.md §12).
	Counts []int64
	// Dropped are the records dropped.
	Dropped int64
	// Late are the records late.
	Late int64
}

SegmentSummary is the summary of the table.

type Visitor

type Visitor func(typ int, late int64, time int64, id int64, body []byte)

Visitor receives the records of a segment: the type, the delay of a late record, the absolute time and number, the body — valid only during the call.