Documentation ¶
Overview ¶
Package ion implements a subset of the Amazon ion binary format: https://amzn.github.io/ion-docs/
Index ¶
- Variables
- func Contents(msg []byte) ([]byte, []byte)
- func Equal(a, b Datum) bool
- func HeaderSizeOf(msg []byte) int
- func IsBVM(buf []byte) bool
- func Marshal(st *Symtab, dst *Buffer, src any) error
- func MinimumID(str string) int
- func NopPadding(dst []byte, padsize int) (int, int)
- func ReadBool(msg []byte) (bool, []byte, error)
- func ReadBytes(msg []byte) ([]byte, []byte, error)
- func ReadBytesShared(msg []byte) ([]byte, []byte, error)
- func ReadCoerceFloat64(msg []byte) (float64, []byte, error)
- func ReadFloat32(msg []byte) (float32, []byte, error)
- func ReadFloat64(msg []byte) (float64, []byte, error)
- func ReadInt(msg []byte) (int64, []byte, error)
- func ReadIntMagnitude(msg []byte) (uint64, []byte, error)
- func ReadString(msg []byte) (string, []byte, error)
- func ReadStringShared(msg []byte) ([]byte, []byte, error)
- func ReadTime(msg []byte) (date.Time, []byte, error)
- func ReadUint(msg []byte) (uint64, []byte, error)
- func SizeOf(msg []byte) int
- func ToJSON(w io.Writer, r *bufio.Reader) (int, error)
- func Unmarshal(st *Symtab, data []byte, v any) ([]byte, error)
- func UnpackList(body []byte, fn func([]byte) error) (rest []byte, err error)
- func UnpackStruct(st *Symtab, body []byte, fn func(string, []byte) error) (rest []byte, err error)
- func UnpackStructBody(st *Symtab, body []byte, fn func(string, []byte) error) (rest []byte, err error)
- func UnpackTyped[T FieldSetter](d Datum, fn func(typ string) (T, bool)) (T, error)
- func UnsafeAppendTag(dst []byte, tag Type, size uint) []byte
- func UnsafeWriteTag(dst []byte, tag Type, size uint) int
- func UnsafeWriteUVarint(dst []byte, uv uint) int
- func Uvsize(value uint) int
- type Bag
- func (b *Bag) Add(st *Symtab, raw []byte) error
- func (b *Bag) AddDatum(d Datum)
- func (b *Bag) AddList(d Datum) error
- func (b *Bag) Append(src *Bag)
- func (b *Bag) Clone() Bag
- func (b *Bag) Each(fn func(d Datum) bool)
- func (b *Bag) EachPair(x *Bag, fn func(b, x Datum) bool)
- func (b *Bag) Encode(dst *Buffer, st *Symtab)
- func (b *Bag) Equals(o *Bag) bool
- func (b *Bag) Len() int
- func (b *Bag) Raw() []byte
- func (b *Bag) Reset()
- func (b *Bag) Size() int
- func (b *Bag) Transcoder(st *Symtab) func(dst *Buffer, src Datum)
- func (b *Bag) Writer() io.Writer
- type Buffer
- func (b *Buffer) BeginAnnotation(labels int)
- func (b *Buffer) BeginField(sym Symbol)
- func (b *Buffer) BeginList(hint int)
- func (b *Buffer) BeginStruct(hint int)
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) EndAnnotation()
- func (b *Buffer) EndList()
- func (b *Buffer) EndStruct()
- func (b *Buffer) Ok() bool
- func (b *Buffer) Reset()
- func (b *Buffer) Set(p []byte)
- func (b *Buffer) Size() int
- func (b *Buffer) StartChunk(symtab *Symtab)
- func (b *Buffer) UnsafeAppend(buf []byte)
- func (b *Buffer) UnsafeAppendFields(buf []byte)
- func (b *Buffer) WriteBlob(p []byte)
- func (b *Buffer) WriteBool(n bool)
- func (b *Buffer) WriteCanonicalFloat(f float64)
- func (b *Buffer) WriteFloat32(f float32)
- func (b *Buffer) WriteFloat64(f float64)
- func (b *Buffer) WriteInt(i int64)
- func (b *Buffer) WriteList(st *Symtab, items []Datum)
- func (b *Buffer) WriteNull()
- func (b *Buffer) WriteString(s string)
- func (b *Buffer) WriteStringBytes(s []byte)
- func (b *Buffer) WriteStruct(st *Symtab, f []Field)
- func (b *Buffer) WriteSymbol(s Symbol)
- func (b *Buffer) WriteTime(t date.Time)
- func (b *Buffer) WriteTo(w io.Writer) (int64, error)
- func (b *Buffer) WriteTruncatedTime(t date.Time, trunc TimeTrunc)
- func (b *Buffer) WriteUint(u uint64)
- type Chunker
- func (c *Chunker) CheckSize() error
- func (c *Chunker) Commit() error
- func (c *Chunker) FastForward(n int)
- func (c *Chunker) Flush() error
- func (c *Chunker) ReadFrom(r io.Reader, cons []Field) (int64, error)
- func (c *Chunker) Reset()
- func (c *Chunker) Set(b []byte)
- func (c *Chunker) SetTimeRange(p []string, min, max date.Time)
- func (c *Chunker) Write(block []byte) (int, error)
- type Datum
- func Annotation(st *Symtab, label string, val Datum) Datum
- func Blob(b []byte) Datum
- func Bool(b bool) Datum
- func Float(f float64) Datum
- func FromJSON(st *Symtab, d *json.Decoder) (Datum, error)
- func Int(i int64) Datum
- func Interned(st *Symtab, s string) Datum
- func NewString(s string) Datum
- func ReadDatum(st *Symtab, buf []byte) (Datum, []byte, error)
- func String(s string) Datum
- func Timestamp(t date.Time) Datum
- func Uint(u uint64) Datum
- func (d Datum) Annotation() (string, Datum, error)
- func (d Datum) Blob() ([]byte, error)
- func (d Datum) BlobShared() ([]byte, error)
- func (d Datum) Bool() (bool, error)
- func (d Datum) Clone() Datum
- func (d Datum) CloneInto(dst *Datum)
- func (d Datum) CoerceFloat() (float64, error)
- func (d Datum) DecodeRelated(b []byte) (Datum, error)
- func (d Datum) Encode(dst *Buffer, st *Symtab)
- func (d Datum) Equal(x Datum) bool
- func (d Datum) Field(name string) Datum
- func (d Datum) Float() (float64, error)
- func (d Datum) Int() (int64, error)
- func (d Datum) IsAnnotation() bool
- func (d Datum) IsBlob() bool
- func (d Datum) IsBool() bool
- func (d Datum) IsEmpty() bool
- func (d Datum) IsFloat() bool
- func (d Datum) IsInt() bool
- func (d Datum) IsList() bool
- func (d Datum) IsNull() bool
- func (d Datum) IsString() bool
- func (d Datum) IsStruct() bool
- func (d Datum) IsSymbol() bool
- func (d Datum) IsTimestamp() bool
- func (d Datum) IsUint() bool
- func (d Datum) Iterator() (Iterator, error)
- func (d Datum) JSON() string
- func (d Datum) LessImprecise(x Datum) bool
- func (d Datum) List() (List, error)
- func (d Datum) Null() error
- func (d Datum) Raw() []byte
- func (d Datum) String() (string, error)
- func (d Datum) StringShared() ([]byte, error)
- func (d Datum) Struct() (Struct, error)
- func (d Datum) Symbol() (Symbol, error)
- func (d Datum) Timestamp() (date.Time, error)
- func (d Datum) Type() Type
- func (d Datum) Uint() (uint64, error)
- func (d Datum) UnpackList(fn func(Datum) error) error
- func (d Datum) UnpackStruct(fn func(Field) error) error
- type Decoder
- type Field
- func (f Field) Annotation() (string, Datum, error)
- func (f Field) Blob() ([]byte, error)
- func (f Field) BlobShared() ([]byte, error)
- func (f Field) Bool() (bool, error)
- func (f Field) Clone() Field
- func (f *Field) Encode(dst *Buffer, st *Symtab)
- func (f *Field) Equal(f2 *Field) bool
- func (f Field) Float() (float64, error)
- func (f Field) Int() (int64, error)
- func (f Field) Iterator() (Iterator, error)
- func (f Field) List() (List, error)
- func (f Field) Null() error
- func (f Field) String() (string, error)
- func (f Field) StringShared() ([]byte, error)
- func (f Field) Struct() (Struct, error)
- func (f Field) Symbol() (Symbol, error)
- func (f Field) Timestamp() (date.Time, error)
- func (f Field) Uint() (uint64, error)
- func (f Field) UnpackList(fn func(Datum) error) error
- func (f Field) UnpackStruct(fn func(Field) error) error
- type FieldSetter
- type Flusher
- type Iterator
- func (i *Iterator) Blob() ([]byte, error)
- func (i *Iterator) Bool() (bool, error)
- func (i *Iterator) Done() bool
- func (i *Iterator) Float() (float64, error)
- func (i *Iterator) Int() (int64, error)
- func (i *Iterator) List() (List, error)
- func (i *Iterator) Next() (Datum, error)
- func (i *Iterator) String() (string, error)
- func (i *Iterator) Struct() (Struct, error)
- func (i *Iterator) Symbol() (Symbol, error)
- func (i *Iterator) Timestamp() (date.Time, error)
- func (i *Iterator) Uint() (uint64, error)
- type JSONWriter
- type List
- type Ranges
- type Struct
- func (s Struct) Datum() Datum
- func (s Struct) Each(fn func(Field) error) error
- func (s Struct) Encode(dst *Buffer, st *Symtab)
- func (s Struct) Equal(s2 Struct) bool
- func (s Struct) Field(x Symbol) (Field, bool)
- func (s Struct) FieldByName(name string) (Field, bool)
- func (s Struct) Fields(fields []Field) []Field
- func (s *Struct) IsEmpty() bool
- func (s Struct) Len() int
- func (s Struct) WithField(f Field) Struct
- type Symbol
- type Symbuf
- type Symtab
- func (s *Symtab) CloneInto(o *Symtab)
- func (s *Symtab) Contains(inner *Symtab) bool
- func (s *Symtab) Equal(o *Symtab) bool
- func (s *Symtab) Get(x Symbol) string
- func (s *Symtab) Intern(x string) Symbol
- func (s *Symtab) InternBytes(buf []byte) Symbol
- func (s *Symtab) Lookup(x Symbol) (string, bool)
- func (s *Symtab) Marshal(dst *Buffer, withBVM bool)
- func (s *Symtab) MarshalPart(dst *Buffer, starting Symbol)
- func (s *Symtab) MaxID() int
- func (s *Symtab) Merge(o *Symtab) (modified bool, ok bool)
- func (s *Symtab) Reset()
- func (s *Symtab) String() string
- func (s *Symtab) Symbolize(x string) (Symbol, bool)
- func (s *Symtab) SymbolizeBytes(x []byte) (Symbol, bool)
- func (s *Symtab) Truncate(max int)
- func (s *Symtab) Unmarshal(src []byte) ([]byte, error)
- type TimeTrunc
- type Type
- type TypeError
Constants ¶
This section is empty.
Variables ¶
var ( False = Datum{/* contains filtered or unexported fields */} True = Datum{/* contains filtered or unexported fields */} )
var Empty = Datum{}
Empty is the zero value of a Datum.
var (
ErrTooLarge = errors.New("ion: object size exceeds max size")
)
var ErrUnexpectedEnd = errors.New("unexpected end of list")
ErrUnexpectedEnd is returned if Iterator.Next is called after the list has been exhausted.
var Null = Datum{/* contains filtered or unexported fields */}
Null is the untyped null datum.
var Stop = errors.New("stop early")
Stop can be returned by the function passed to List.Each and Struct.Each to stop iterating and return early.
Functions ¶
func Contents ¶
Contents parses the TLV descriptor at the beginning of 'msg' and returns the bytes that correspond to the non-descriptor bytes of the object, plus the remaining bytes in the buffer as the second return value. The returned []byte will be nil if the encoded object size does not fit into 'msg'. (Note that a returned slice that is zero-length but non-nil means something different than a nil slice.)
func HeaderSizeOf ¶
HeaderSizeOf returns the size of the next ION object's header. The function counts TLV byte and the size of the optional Length field.
NOTE: This function only counts bytes, it doesn't return the real size of the value.
func IsBVM ¶
IsBVM returns whether or not the next 4 bytes of the message are a 4-byte ion BVM marker.
func Marshal ¶
Marshal encodes src into dst, updating the symbol table as necessary for new symbols that are introduced as part of encoding.
func MinimumID ¶
MinimumID returns the lowest ID that a string could be symbolized as.
System symbols have IDs less than 10; all other symbols have and ID of at least 10.
func NopPadding ¶
NopPadding writes a header for Ion NOP operation for given padsize. It returns the size of header and the number of pad bytes that have to be written after the header.
FIXME: it's not possible to produce exact padding for all possible padsize. The procedure never returns values that would exceed the required padding.
func ReadBool ¶
ReadBool reads a boolean value and returns it along with the subsequent message bytes
func ReadBytes ¶
ReadBytes reads an ion blob from message. The returned slice does not alias msg. See also: ReadBytesShared.
func ReadBytesShared ¶
ReadBytesShared read a []byte (as an ion 'blob') and returns the blob and the subsequent message bytes. Note that the returned []byte aliases the input message, so the caller must copy those bytes into a new buffer if the original buffer is expected to be clobbered.
func ReadFloat32 ¶
ReadFloat32 reads an ion float as a float32 and returns the value and the subsequent message bytes.
func ReadFloat64 ¶
ReadFloat64 reads an ion float as a float64 and returns the value and the subsequent message bytes.
func ReadIntMagnitude ¶
ReadIntMagnitude reads magnitude of an integer (either signed or unsigned) and returns the subsequent message bytes
func ReadString ¶
ReadString reads a string from 'msg' and returns the string and the subsequent message bytes.
func ReadStringShared ¶
ReadStringShared reads a string from 'msg' and returns the string and the subsequent message bytes. The returned slice containing the string contents aliases the input slice.
func SizeOf ¶
SizeOf returns the size of the next ion object, including the beginning TLV descriptor bytes.
The return value of SizeOf is unspecified when msg is not a valid ion object.
func ToJSON ¶
ToJSON reads a stream of ion objects from 'r' and writes them to 'w'. Each top-level object in the stream of objects is written on its own line. (See also: jsonlines.org, ndjson.org)
Ion structures are written as json objects, lists and sexps are written as arrays, symbols, strings and timestamps are written as strings, blobs and clobs are written as base64-encoded strings, numbers are written as numbers (using as many characters as are necessary to preserve precision upon decoding the numbers), and null objects are written as JSON nulls.
Symbol tables present in the stream of objects are decoded and used to print symbols and structure fields. Per the ion binary specification, a BVM marker flushes the current symbol table. (Annotation objects and padding objects do not produce any JSON output.)
ToJSON returns the number of bytes written to w and the first error encountered (if any).
func Unmarshal ¶
Unmarshal unmarshals data from a raw slice into the value v using the provided symbol table.
func UnpackList ¶
UnpackList calls fn for each item in a list, returning the remaining bytes.
func UnpackStruct ¶
UnpackStruct calls fn for each field in a struct, returning the remaining bytes.
func UnpackStructBody ¶
func UnpackStructBody(st *Symtab, body []byte, fn func(string, []byte) error) (rest []byte, err error)
UnpackStructBody calls fn for each field in a struct, assuming that `body` is an already extracted record content, without an Ion header (the TLV byte and object size).
func UnpackTyped ¶
func UnpackTyped[T FieldSetter](d Datum, fn func(typ string) (T, bool)) (T, error)
UnpackTyped iterates the fields in a struct to find a string field named "type" which is passed to fn to resolve to a concrete type. The other fields are passed to SetField on the returned object.
fn should return true to indicate that the type was resolved, and false to indicate that the type is not supported.
If d is not a struct or the "type" field is not present, this returns an error.
func UnsafeAppendTag ¶
UnsafeAppendTag appends a type+length tag of the given type and size to dst and returns the extended buffer.
func UnsafeWriteTag ¶
UnsafeWriteTag writes the header of an Ion object having size. Returns the number of stored bytes
It's required that dst has enough room for the encoded header.
func UnsafeWriteUVarint ¶
UnsafeWriteUVarint encodes uv as a uvarint number. Returns the number of stored bytes.
It's required that dst has enough room for the encoded number (i.e., len(buf) >= Uvsize(uv)).
Types ¶
type Bag ¶
type Bag struct {
// contains filtered or unexported fields
}
Bag is a (possibly empty) sequence of ion datums. A bag is stored efficiently in memory so as to reduce the CPU and memory footprint of the constituent data elements.
func (*Bag) Add ¶
Add adds zero or more raw ion datums from a buffer and an associated symbol table.
func (*Bag) AddList ¶
AddList adds the contents of a list to the bag. If d is not a list, this returns an error.
func (*Bag) Each ¶
Each iterates each item in the bag and calls fn() on it. If fn returns false, then Each returns early.
func (*Bag) EachPair ¶
EachPair iterates b and x up to min(b.Len(), x.Len()) and returns the corresponding values in each bag at each position.
func (*Bag) Equals ¶
Equals compares two bags and returns true if they are equivalent.
Note that Equals is sensitive to the order of items in each Bag.
func (*Bag) Raw ¶
Raw returns the raw encoded datums. The caller must not alter the contents of the returned slice.
func (*Bag) Transcoder ¶
Transcoder returns a function that can be used to efficiently transcode datums from within the bag to a different symbol table. The returned function is only valid for use with Datum objects returned from b.Each.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer buffers ion objects.
The contents of Buffer can be inspected directly with Buffer.Bytes() or written to an io.Writer with Buffer.WriteTo.
func (*Buffer) BeginAnnotation ¶
BeginAnnotation begins an annotation object. 'labels' should indicate the number annotation fields before the wrapped object, and must be greater than zero.
func (*Buffer) BeginField ¶
BeginField begins a field of a structure or a label of an annotation. BeginField will panic if the buffer is not in an appropriate structure field context
func (*Buffer) BeginList ¶
BeginList begins a list object. Subsequent calls to the Buffer.Write* methods will write list elements until Buffer.EndList is called.
func (*Buffer) BeginStruct ¶
BeginStruct begins a structure. Fields of the structure should be written with paired calls to BeginField and one of the Write* methods, followed by Buffer.EndStruct.
func (*Buffer) EndAnnotation ¶
func (b *Buffer) EndAnnotation()
EndAnnotation ends an annotation object.
func (*Buffer) EndList ¶
func (b *Buffer) EndList()
EndList ends a list object.
If EndList is not paried with a corresponding BeginList call, it will panic.
func (*Buffer) EndStruct ¶
func (b *Buffer) EndStruct()
EndStruct ends a structure.
If EndStruct is not paired with a corresponding BeginStruct call, it will panic.
func (*Buffer) Ok ¶
Ok returns false if there are any open calls to BeginStruct or BeginList that have not been paired with EndStruct or EndList, respectively.
func (*Buffer) Set ¶
Set sets the buffer used by 'b' and resets the state of the buffer. Subsequent calls to Write* functions on 'b' will append to the given buffer.
func (*Buffer) StartChunk ¶
StartChunk writes BVM marker and symtab.
func (*Buffer) UnsafeAppend ¶
UnsafeAppend appends arbitrary data to the buffer. If the buffer is currently in List, Struct, or Annotation context, then the contents of buf should be exactly one ion datum.
func (*Buffer) UnsafeAppendFields ¶
UnsafeAppendFields appends an encoded field list as an ion structure. The data must be zero or more encoded (uvarint, field) pairs with the fields sorted in ascending symbol ID order.
func (*Buffer) WriteCanonicalFloat ¶
func (*Buffer) WriteFloat32 ¶
WriteFloat32 writes an ion float32 to the buffer
func (*Buffer) WriteFloat64 ¶
WriteFloat64 writes an ion float64 to the buffer
func (*Buffer) WriteNull ¶
func (b *Buffer) WriteNull()
WriteNull writes an ion NULL value into the buffer
func (*Buffer) WriteString ¶
WriteString writes a string as an ion string into a Buffer
func (*Buffer) WriteStringBytes ¶
WriteStringBytes works identically to WriteString, but it uses a []byte as the string contents rather than a string.
func (*Buffer) WriteStruct ¶
func (*Buffer) WriteSymbol ¶
WriteSymbol writes an ion symbol value to the buffer.
func (*Buffer) WriteTime ¶
WriteTime writes a date.Date as an ion timestamp object.
WriteTime only supports microsecond-precision timestamps.
func (*Buffer) WriteTruncatedTime ¶
WriteTruncatedTime writes a date.Date as an ion timestamp object and lets the caller decide how precise the output is.
type Chunker ¶
type Chunker struct { // Buffer is the current // buffered data. Buffer // Symbols is the current symbol table. Symbols Symtab // Align is the alignment of output data. // (Align should not be modified once the // data has begun being committed to the Chunker.) Align int // RangeAlign is the alignment // at which ranges are flushed to W. RangeAlign int // W is the output io.Writer. // All writes to W will have length equal to Align. // // If W implements Flusher, then Flush is called // immediately after ranges are written, which // should occur at most once every RangeAlign bytes. W io.Writer // Ranges stores field ranges for the current // chunk. Ranges Ranges // WalkTimeRanges is the list of time ranges // that is automatically scanned during // Chunker.Write. WalkTimeRanges [][]string // contains filtered or unexported fields }
Chunker is a wrapper for a Buffer and Symtab that allows objects to be written to an output stream on aligned boundaries with padding.
In order to use a Chunker, populate its Align and W fields with the target alignment and destination of the ion output. Then, write objects to Buffer (optionally updating Symbols) and call Commit after each object has been written. After the complete object stream has been written, call Flush to flush any remaining buffer contents.
func (*Chunker) CheckSize ¶
CheckSize checks that the current number of un-commited bytes will fit within c.Align. If the object would not fit, it returns an error immediately.
func (*Chunker) Commit ¶
Commit commits an object to the state buffer, taking care to flush it if we would exceed the block alignment.
Note that Commit will refuse to commit objects that do not fit in the target output alignment.
Commit should be called after each complete object has been written to a chunker.
func (*Chunker) FastForward ¶
FastForward changes the initial values for the number of flushed bytes to c.W and the contents of the chunker ranges. c.Symbols should be set to whatever the "current" symbol table is expected to be.
func (*Chunker) Flush ¶
Flush flushes the output of the chunker, regardless of whether or not the current buffer is approaching the target alignment. (The output to c.W will still be padded to the appropriate alignment.)
Flush must always be preceded by a call to Commit unless zero objects have been written to c.Buffer.
func (*Chunker) ReadFrom ¶
ReadFrom reads ion from r and re-encodes it into the chunker by reading objects one-at-a-time. If cons is provided, these fields will be added to each structure.
BUGS: ReadFrom only indexes data from the top-level of each structure.
func (*Chunker) Reset ¶
func (c *Chunker) Reset()
Reset resets c to its initial state. This should only be used between benchmark runs to avoid allocation overhead.
func (*Chunker) Set ¶
Set sets the buffer used by c to b and resets c to its initial state. This should only be used between benchmark runs to avoid allocation overhead.
func (*Chunker) SetTimeRange ¶
SetTimeRange clobbers the currently-stored time range values
type Datum ¶
type Datum struct {
// contains filtered or unexported fields
}
Datum represents any Ion datum.
The Marshal and Unmarshal functions natively understand that Datum can be constructed and re-encoded from any ion value.
A Datum should be a value returned by
Float, Int, Uint, Struct, List, Bool, BigInt, Timestamp, Annotation, ..., or ReadDatum.
func Annotation ¶
Annotation objects represent ion annotation datums.
func Interned ¶
Interned returns a Datum that represents an interned string (a Symbol). Interned is always encoded as an ion symbol.
func ReadDatum ¶
ReadDatum reads the next datum from buf and returns it. ReadDatum does not return symbol tables directly; instead it unmarshals them into st and continues reading. It may return a nil datum if buf points to a symbol table followed by zero bytes of actual ion data.
Any Symbol datums in buf are translated into Interned datums rather than Symbol datums, as this makes the returned Datum safe to re-encode with a new symbol table.
The returned datum will share memory with buf and so the caller must guarantee that the contents of buf will not be modified until it is no longer needed.
func (Datum) BlobShared ¶
BlobShared returns a []byte aliasing the contents of this Datum and should be copied as necessary to avoid issues that may arise from retaining aliased bytes.
func (Datum) CoerceFloat ¶
func (Datum) DecodeRelated ¶
DecodeRelated attempts to decode a datum that was encoded using the same symbol table as this datum, for example when a struct contains a blob holding the compressed encoded form of another composite object.
This method only works with lists and structs. Calling this method on any other data type will result in an error.
func (Datum) Field ¶
Field returns the value associated with the field with the given name if d is a struct. If d is not a struct or the field is not present, this returns Empty.
func (Datum) IsAnnotation ¶
func (Datum) IsTimestamp ¶
func (Datum) LessImprecise ¶
LessImprecise compares the raw Ion bytes.
This method does not order correctly equal values having different binary representation. For instance a string can be saved literally, as a sequence of UTF-8 bytes, or be a symbol, that is a reference to the symbol table.
func (Datum) Raw ¶
Raw returns the raw byte slice underlying d. The returned slice aliases the contents of d, so care should be taken when retaining or modifying the returned slice.
func (Datum) StringShared ¶
StringShared returns a []byte aliasing the contents of this Datum and should be copied as necessary to avoid issues that may arise from retaining aliased bytes.
Unlike String, this method will not work with a symbol datum.
func (Datum) UnpackList ¶
UnpackList calls d.List and calls UnpackList on the result.
type Decoder ¶
type Decoder struct { // Symtab is the current symbol table. // Calls to Decoder.Decode will update // the symbol table as symbol table annotations // are encountered in the source data stream. Symbols Symtab // ExtraAnnotations holds additional values // that will be Unmarshal()'ed into when the // associated annotation label occurs at the top // level in the stream. In other words, if the stream // contains // label::{foo: "bar"} // then the Decoder will look up "label" in ExtraAnnotations // and Unmarshal the {foo: "bar"} value into the associated // Go value. ExtraAnnotations map[string]any // contains filtered or unexported fields }
Decoder is a stateful decoder of streams of ion objects. A Decoder wraps an io.Reader so that a sequence of ion records can be read via Decoder.Decode.
See also: Unmarshal.
func NewDecoder ¶
NewDecoder constructs a decoder that reads objects from r up to the given maximum size.
type Field ¶
Field is a structure field in a Struct or Annotation datum
func (Field) BlobShared ¶
BlobShared returns a []byte aliasing the contents of this Field and should be copied as necessary to avoid issues that may arise from retaining aliased bytes.
func (Field) StringShared ¶
StringShared returns a []byte aliasing the contents of this Field and should be copied as necessary to avoid issues that may arise from retaining aliased bytes.
Unlike String, this method will not work with a symbol datum.
func (Field) UnpackList ¶
UnpackList calls f.List and calls UnpackList on the result.
type FieldSetter ¶
type FieldSetter interface { // SetField is called for each structure field. SetField(Field) error }
FieldSetter is an object which can accept fields from an ion struct.
type Flusher ¶
type Flusher interface {
Flush() error
}
Flusher is an interface optionally implemented by io.Writers that would like to be notified when ranges have been flushed.
See ion.Chunker.W.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
An Iterator can be used to iterate over items in a list.
func (*Iterator) Done ¶
Done returns whether the iterator has reached the end of the list. If Done returns false, the next call to Next will not return
func (*Iterator) Next ¶
Next returns the next item in the list. The caller should check Done first to ensure that there are still items in the list.
If Next is called after reaching the the end of the list, this returns ErrUnexpectedEnd. If there is an error decoding the next item in the list, that error is returned.
type JSONWriter ¶
type JSONWriter struct { // W is the output io.Writer into which // the JSON data is written. W io.Writer // ShowAnnotations causes top-level annotation // objects to be displayed. // // An ion annotation x::y is encoded // as a JSON structure like // {"$ion_annotation$x":y} // where x is the annotation label and // y is the annotation value. // Annotation structures will always have // exactly one field, and that fields name // will always begin with "$ion_annotation$" // followed by the annotation label. ShowAnnotations bool // contains filtered or unexported fields }
JSONWriter is an io.WriteCloser that performs inline translation of chunks of ion data into JSON objects. See NewJSONWriter.
func NewJSONWriter ¶
func NewJSONWriter(w io.Writer, sep byte) *JSONWriter
NewJSONWriter creates a new JSON writer which writes either NDJSON or a JSON array depending on the value of sep:
If sep is '\n', then the returned JSONWriter writes NDJSON lines from each input object, and the Close method is a no-op. If sep is ',', then the return JSONWriter writes a JSON array containing all the ion values passed to Write. The call to Close writes the final ']' byte.
NewJSONWriter will panic if sep is not one of the recognized bytes.
func (*JSONWriter) Close ¶
func (w *JSONWriter) Close() error
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is an ion list datum
func (List) Each ¶
Each iterates over each datum in the list and calls fn on each datum in order. Each returns when it encounters an internal error (due to malformed ion) or when fn returns a non-nil error.
type Ranges ¶
type Ranges struct {
// contains filtered or unexported fields
}
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct is an ion structure datum
func (Struct) Each ¶
Each calls fn for each field in the struct. If fn returns Stop, Each stops and returns nil. If fn returns any other non-nil error, Each stops and returns that error. If Each encounters a malformed field while unpacking the struct, Each returns a non-nil error.
type Symbol ¶
type Symbol uint
Symbol represents an ion Symbol
func ReadAnnotation ¶
ReadAnnotation reads an annotation and returns the associated label, the contents of the annotation, and the remaining bytes in buf (in that order).
func ReadLabel ¶
ReadLabel reads a symbol preceding a structure field and returns the subsequent message bytes.
func ReadSymbol ¶
ReadSymbol reads an ion symbol from msg and returns the subsequent message bytes, or an error if one is encountered.
type Symbuf ¶
type Symbuf []byte
Symbuf is an encoded list of symtab indices.
type Symtab ¶
type Symtab struct {
// contains filtered or unexported fields
}
Symtab is an ion symbol table
func (*Symtab) CloneInto ¶
CloneInto performs a deep copy of s into o. CloneInto takes care to use some of the existing storage in o in order to reduce the copying overhead.
func (*Symtab) Contains ¶
Contains returns true if s is a superset of the symbols within inner, and all of the symbols in inner have the same symbol ID in s.
If x.Contains(y), then x is a semantically equivalent substitute for y.
func (*Symtab) Get ¶
Get gets the string associated with the given interned symbol, or returns the empty string when there is no symbol with the given association.
func (*Symtab) Intern ¶
Intern interns the given string if it is not already interned and returns the associated Symbol
func (*Symtab) InternBytes ¶
InternBytes is identical to Intern, except that it accepts a []byte instead of a string as an argument.
func (*Symtab) Lookup ¶
Lookup gets the string associated with the given interned symbol. This returns ("", false) when the symbol is not present in the table.
func (*Symtab) Marshal ¶
Marshal marshals the Symtab into 'dst' optionally with a BVM prefix.
If withBVM is false and the symbol table is empty, then no data is written to dst.
func (*Symtab) MarshalPart ¶
MarshalPart writes a symbol table to dst with all the symbols starting at starting. If there are no symbols above starting, then MarshalPart does not write any data.
Callers can use a previous result of s.MaxID plus MarshalPart to write incremental changes to symbol tables to an ion stream.
func (*Symtab) MaxID ¶
MaxID returns the total number of interned symbols. Note that ion defines ten symbols that are automatically interned, so an "empty" symbol table has MaxID() of 10.
func (*Symtab) Merge ¶
Merge adds new symbols from symtab `o` providing that the common symbols of the both symtabs are the same.
Returns whether merge was OK. If it was, return if new symbols were added.
func (*Symtab) Reset ¶
func (s *Symtab) Reset()
Reset resets a symbol table so that it no longer contains any symbols (except for the ion pre-defined symbols).
func (*Symtab) Symbolize ¶
Symbolize returns the symbol associated with the string 'x' in the symbol table, or (0, false) if the string has not been interned.
func (*Symtab) SymbolizeBytes ¶
SymbolizeBytes works identically to Symbolize, except that it accepts a []byte.
func (*Symtab) Truncate ¶
Truncate truncates the symbol table to the number of symbols indicated by max. Truncate can be used to restore a Symtab to its previous state as indicated by s.MaxID(). Truncate panics if max is below the number of pre-interned "system" symbols (10).
func (*Symtab) Unmarshal ¶
Unmarshal unmarshals a symbol table from 'src' into 's'. If 'src' begins with a BVM (see IsBVM), then any contents of the symbol table will be cleared before interning the new symbol values. Otherwise, the new symbols will be interned with IDs above the presently-interned symbols.
BUGS: Support for ion "shared" symbol tables is not yet implemented.
type Type ¶
type Type byte
Type is one of the ion datatypes
func Peek ¶
Peek peeks at the type and size of the next object in 'r'.
The returned size can be used to read only the next object from the buffer. For example:
t, s, _ := Peek(r) buf := make([]byte, s) io.ReadFull(r, buf)
func (Type) Composite ¶
Composite returns whether or not the type is an object containing other objects.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package blockfmt implements routines for reading and writing compressed and aligned ion blocks to/from backing storage.
|
Package blockfmt implements routines for reading and writing compressed and aligned ion blocks to/from backing storage. |
Package versify implements an ion "versifier:" code that performs procedural data generation based on example input.
|
Package versify implements an ion "versifier:" code that performs procedural data generation based on example input. |
Package zion implements a "zipped" ion encoding that compresses streams of ion structures in a manner such that fields within structures in the stream can be decompressed without decompressing the entire input stream.
|
Package zion implements a "zipped" ion encoding that compresses streams of ion structures in a manner such that fields within structures in the stream can be decompressed without decompressing the entire input stream. |
iguana
Package iguana implements a Lizard-derived compression/decompression pipeline
|
Package iguana implements a Lizard-derived compression/decompression pipeline |
zll
Package zll exposes types and procedures related to low-level zion decoding.
|
Package zll exposes types and procedures related to low-level zion decoding. |