Documentation
¶
Index ¶
Constants ¶
const ( DefaultDocTag uint64 = 60000 // wraps a whole packed document DefaultTableTag uint64 = 60001 // wraps a single packed [cols, rows] table DefaultMinRows = 8 DefaultMinFill = 0.5 )
Defaults for the packed layout.
The tag numbers are application-private: they are NOT registered with IANA. They only need to be stable between the writer and the reader, and both are configurable so they can be moved if they ever collide with something else in your pipeline.
Variables ¶
This section is empty.
Functions ¶
func IsPacked ¶ added in v0.4.0
func IsPacked(v any, o PackOptions) bool
IsPacked reports whether a decoded document carries the packed document tag.
func Pack ¶ added in v0.4.0
func Pack(v any, o PackOptions) any
Pack applies the configured transforms and wraps the result in the document tag so that Unpack (and any other reader) can identify it.
Types ¶
type CBORProcessor ¶
type CBORProcessor struct {
// contains filtered or unexported fields
}
CBORProcessor processes messages by decoding CBOR data, displaying the decoded content, and re-encoding it.
func NewProcessor ¶
func NewProcessor(operatorStr string, opts ...Option) (*CBORProcessor, error)
func (*CBORProcessor) Close ¶
func (cp *CBORProcessor) Close(ctx context.Context) error
Close implements the service.Processor interface.
func (*CBORProcessor) Process ¶
func (cp *CBORProcessor) Process(ctx context.Context, m *service.Message) (service.MessageBatch, error)
Process implements the service.Processor interface.
type Option ¶ added in v0.4.0
type Option func(*CBORProcessor)
Option customises a CBORProcessor at construction time.
func WithPackOptions ¶ added in v0.4.0
func WithPackOptions(o PackOptions) Option
WithPackOptions overrides the layout options used by the pack/unpack operators. It has no effect on to_json/from_json.
type PackOptions ¶ added in v0.4.0
type PackOptions struct {
// OmitZero drops map entries whose value is null, false, 0, "" or an empty
// container before encoding.
//
// This is lossy: it collapses "absent", "null" and "zero" into a single
// state, exactly like proto3 field presence. Consumers must treat a missing
// key as the zero value. Off by default.
OmitZero bool
// AllowSparse permits packing arrays whose elements do not all share the
// same key set, by taking the union of keys and writing null in the cells
// that have no value.
//
// This is lossy: a key that was absent from a row round-trips as an explicit
// null, because CBOR "undefined" decodes to Go nil and cannot be told apart
// from null through a generic any. Off by default, which makes packing
// strictly lossless at the cost of skipping heterogeneous arrays.
AllowSparse bool
// MinRows is the shortest array worth packing. Below this the column header
// costs more than the repeated keys save.
MinRows int
// MinFill is the minimum ratio of populated cells (0..1) required before a
// sparse array is packed. Only consulted when AllowSparse is set.
MinFill float64
// DocTag and TableTag are the CBOR tag numbers used to mark a packed
// document and a packed table respectively.
DocTag uint64
TableTag uint64
}
PackOptions controls the schema-agnostic size optimisations applied by the "pack" operator.
None of these require knowing the shape of the data up front: the column names are derived from the values at encode time and travel inside the payload, so "unpack" can reverse the transform with no configuration.
func DefaultPackOptions ¶ added in v0.4.0
func DefaultPackOptions() PackOptions
DefaultPackOptions returns the lossless defaults.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
bento-cbor
command
Example build to include bento-cbor with all bento components
|
Example build to include bento-cbor with all bento components |