metajson

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package metajson decodes stored event metadata without losing numbers.

The event digest covers the JSON encoding of Metadata, so whatever a store reads back has to encode to the same bytes Record hashed. encoding/json turns every number into float64 by default, and float64 holds integers exactly only up to 2^53. Past that, 9007199254740993 comes back as 9007199254740992 and the event fails verification the moment it is read.

Decoding with UseNumber alone is not the answer either. PostgreSQL's jsonb rewrites numbers on the way in (1e-07 is returned as 0.0000001), and those only round-trip today because float64 formats them back the way Go first wrote them. So a number stays float64 whenever float64 holds it exactly, which also keeps the type callers already get for small values, and only an integer float64 would round becomes int64 or uint64.

The stores in store/postgres, store/sqlite and store/redis import this package, and they are separate modules. A user can end up with this root module at a newer version than an older store module, so treat everything exported here as public API between Chronicle's own modules: add to it, but don't rename, remove or change the signature of anything an older store module might still call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte) (map[string]any, error)

Decode parses a JSON object into metadata. Empty input and JSON null both decode to a nil map.

func DecodeExact

func DecodeExact(data []byte) (map[string]any, error)

DecodeExact retains every JSON number without floating point conversion. Reliable ingestion normalizes number spelling before hashing; encrypted payloads and archive restores keep that exact representation.

Types

type Map

type Map map[string]any

Map is metadata that decodes through Decode. Stores use it as the model field type where a driver or encoding/json does the unmarshalling for them.

func (*Map) Scan

func (m *Map) Scan(src any) error

Scan implements sql.Scanner, for drivers that hand over the raw column.

func (*Map) UnmarshalJSON

func (m *Map) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

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