json

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(a, b Json) bool

func EscapePointerSeg

func EscapePointerSeg(ptr string) string

escapePointerSeg escapes a string to be safe string for a path segment.

func Extract

func Extract(json interface{}, ptr string) (interface{}, error)

Extract returns a value from an JSON document as per RFC 6901 pointer string.

The function returns an error if no element found (to separate from the case value being a nil). That is, it is up to the caller to determine the exact semantics of no element found.

func IsBJson

func IsBJson(data []byte) bool

IsBJson checks header: watch out for {/t,/n,/r} (valid json)

func IsJSON

func IsJSON(bs []byte) bool

func IsNull

func IsNull(value Json) bool

func Marshal

func Marshal(j Json) ([]byte, error)

Marshal serializes the JSON to a single binary snapshot.

func NewPointer

func NewPointer(segs []string) string

NewPointer constructs a JSON pointer from its segments.

func ParsePointer

func ParsePointer(ptr string) ([]string, error)

ParsePointer parses a JSON pointer, returning its segments.

func PathSegments

func PathSegments(path string) []string

PathSegments returns the path segments of the path.

func UnescapePointerSeg

func UnescapePointerSeg(ptr string) string

unescapePointerSeg unescapes a path segment.

func Unmarshal

func Unmarshal(data Json, v interface{}) error

Unmarshal stores the JSON data in the value pointed to by v.

func UnmarshalUseNumber

func UnmarshalUseNumber(data Json, v interface{}) error

UnmarshalUseNumber stores the JSON data in the value pointed to by v. Numbers are stored as json.Number

Types

type Array

type Array interface {
	Json
	Iterable

	Append(element ...File) Array
	AppendSingle(element File) (Array, bool)
	Slice(i, j int) Array
	Value(i int) Json

	WriteI(w io.Writer, i int, written *int64) error
	// contains filtered or unexported methods
}

Array represents a JSON array.

func NewArray

func NewArray(elements []File, cap int) Array

func NewArrayCompactStrings

func NewArrayCompactStrings(elements []File, cap int) Array

type ArrayBinary

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

func (ArrayBinary) AST

func (a ArrayBinary) AST() ast.Value

func (ArrayBinary) Append

func (a ArrayBinary) Append(elements ...File) Array

func (ArrayBinary) AppendSingle

func (a ArrayBinary) AppendSingle(element File) (Array, bool)

func (ArrayBinary) Clone

func (a ArrayBinary) Clone(bool) File

func (ArrayBinary) Compare

func (a ArrayBinary) Compare(other Json) int

func (ArrayBinary) Contents

func (a ArrayBinary) Contents() interface{}

func (ArrayBinary) Extract

func (a ArrayBinary) Extract(ptr string) (Json, error)

func (ArrayBinary) Iterate

func (a ArrayBinary) Iterate(i int) Json

func (ArrayBinary) JSON

func (a ArrayBinary) JSON() interface{}

func (ArrayBinary) Len

func (a ArrayBinary) Len() int

func (ArrayBinary) RemoveIdx

func (a ArrayBinary) RemoveIdx(i int) Json

func (ArrayBinary) SetIdx

func (a ArrayBinary) SetIdx(i int, value File) Json

func (ArrayBinary) Slice

func (a ArrayBinary) Slice(i int, j int) Array

func (ArrayBinary) String

func (a ArrayBinary) String() string

func (ArrayBinary) Value

func (a ArrayBinary) Value(i int) Json

func (ArrayBinary) WriteI

func (a ArrayBinary) WriteI(w io.Writer, i int, written *int64) error

func (ArrayBinary) WriteTo

func (a ArrayBinary) WriteTo(w io.Writer) (int64, error)

type ArraySlice

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

func (*ArraySlice) AST

func (a *ArraySlice) AST() ast.Value

func (*ArraySlice) Append

func (a *ArraySlice) Append(elements ...File) Array

func (*ArraySlice) AppendSingle

func (a *ArraySlice) AppendSingle(element File) (Array, bool)

func (*ArraySlice) Clone

func (a *ArraySlice) Clone(deepCopy bool) File

func (*ArraySlice) Compare

func (a *ArraySlice) Compare(other Json) int

func (*ArraySlice) Contents

func (a *ArraySlice) Contents() interface{}

func (*ArraySlice) Extract

func (a *ArraySlice) Extract(ptr string) (Json, error)

func (*ArraySlice) Iterate

func (a *ArraySlice) Iterate(i int) Json

func (*ArraySlice) JSON

func (a *ArraySlice) JSON() interface{}

func (*ArraySlice) Len

func (a *ArraySlice) Len() int

func (*ArraySlice) RemoveIdx

func (a *ArraySlice) RemoveIdx(i int) Json

func (*ArraySlice) SetIdx

func (a *ArraySlice) SetIdx(i int, j File) Json

func (*ArraySlice) Slice

func (a *ArraySlice) Slice(i, j int) Array

func (*ArraySlice) String

func (a *ArraySlice) String() string

func (*ArraySlice) Value

func (a *ArraySlice) Value(i int) Json

func (*ArraySlice) WriteI

func (a *ArraySlice) WriteI(w io.Writer, i int, written *int64) error

func (*ArraySlice) WriteTo

func (a *ArraySlice) WriteTo(w io.Writer) (int64, error)

type ArraySliceCompact

type ArraySliceCompact[T indexable] struct {
	// contains filtered or unexported fields
}

ArraySliceCompact is a compact implementation of the arrays with at most 32 elements.

func (*ArraySliceCompact[T]) AST

func (a *ArraySliceCompact[T]) AST() ast.Value

func (*ArraySliceCompact[T]) Append

func (a *ArraySliceCompact[T]) Append(elements ...File) Array

func (*ArraySliceCompact[T]) AppendSingle

func (a *ArraySliceCompact[T]) AppendSingle(element File) (Array, bool)

func (*ArraySliceCompact[T]) Clone

func (a *ArraySliceCompact[T]) Clone(deepCopy bool) File

func (*ArraySliceCompact[T]) Compare

func (a *ArraySliceCompact[T]) Compare(other Json) int

func (*ArraySliceCompact[T]) Contents

func (a *ArraySliceCompact[T]) Contents() interface{}

func (*ArraySliceCompact[T]) Extract

func (a *ArraySliceCompact[T]) Extract(ptr string) (Json, error)

func (*ArraySliceCompact[T]) Iterate

func (a *ArraySliceCompact[T]) Iterate(i int) Json

func (*ArraySliceCompact[T]) JSON

func (a *ArraySliceCompact[T]) JSON() interface{}

func (*ArraySliceCompact[T]) Len

func (a *ArraySliceCompact[T]) Len() int

func (*ArraySliceCompact[T]) RemoveIdx

func (a *ArraySliceCompact[T]) RemoveIdx(i int) Json

func (*ArraySliceCompact[T]) SetIdx

func (a *ArraySliceCompact[T]) SetIdx(i int, j File) Json

func (*ArraySliceCompact[T]) Slice

func (a *ArraySliceCompact[T]) Slice(i, j int) Array

func (*ArraySliceCompact[T]) String

func (a *ArraySliceCompact[T]) String() string

func (*ArraySliceCompact[T]) Value

func (a *ArraySliceCompact[T]) Value(i int) Json

func (*ArraySliceCompact[T]) WriteI

func (a *ArraySliceCompact[T]) WriteI(w io.Writer, i int, written *int64) error

func (*ArraySliceCompact[T]) WriteTo

func (a *ArraySliceCompact[T]) WriteTo(w io.Writer) (int64, error)

type ArraySliceCompactStrings

type ArraySliceCompactStrings[T indexableStrings] struct {
	// contains filtered or unexported fields
}

ArraySliceCompactStrings is a compact implementation of the string arrays with at most 32 elements.

func (*ArraySliceCompactStrings[T]) AST

func (a *ArraySliceCompactStrings[T]) AST() ast.Value

func (*ArraySliceCompactStrings[T]) Append

func (a *ArraySliceCompactStrings[T]) Append(elements ...File) Array

func (*ArraySliceCompactStrings[T]) AppendSingle

func (a *ArraySliceCompactStrings[T]) AppendSingle(element File) (Array, bool)

func (*ArraySliceCompactStrings[T]) Clone

func (a *ArraySliceCompactStrings[T]) Clone(deepCopy bool) File

func (*ArraySliceCompactStrings[T]) Compare

func (a *ArraySliceCompactStrings[T]) Compare(other Json) int

func (*ArraySliceCompactStrings[T]) Contents

func (a *ArraySliceCompactStrings[T]) Contents() interface{}

func (*ArraySliceCompactStrings[T]) Extract

func (a *ArraySliceCompactStrings[T]) Extract(ptr string) (Json, error)

func (*ArraySliceCompactStrings[T]) Iterate

func (a *ArraySliceCompactStrings[T]) Iterate(i int) Json

func (*ArraySliceCompactStrings[T]) JSON

func (a *ArraySliceCompactStrings[T]) JSON() interface{}

func (*ArraySliceCompactStrings[T]) Len

func (a *ArraySliceCompactStrings[T]) Len() int

func (*ArraySliceCompactStrings[T]) RemoveIdx

func (a *ArraySliceCompactStrings[T]) RemoveIdx(i int) Json

func (*ArraySliceCompactStrings[T]) SetIdx

func (a *ArraySliceCompactStrings[T]) SetIdx(i int, j File) Json

func (*ArraySliceCompactStrings[T]) Slice

func (a *ArraySliceCompactStrings[T]) Slice(i, j int) Array

func (*ArraySliceCompactStrings[T]) String

func (a *ArraySliceCompactStrings[T]) String() string

func (*ArraySliceCompactStrings[T]) Value

func (a *ArraySliceCompactStrings[T]) Value(i int) Json

func (*ArraySliceCompactStrings[T]) WriteI

func (a *ArraySliceCompactStrings[T]) WriteI(w io.Writer, i int, written *int64) error

func (*ArraySliceCompactStrings[T]) WriteTo

func (a *ArraySliceCompactStrings[T]) WriteTo(w io.Writer) (int64, error)

type Blob

type Blob interface {
	File
	Value() []byte
}

Blob represents a binary blob.

func NewBlob

func NewBlob(data []byte) Blob

type Bool

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

Bool represents a JSON boolean value.

func NewBool

func NewBool(value bool) Bool

func (Bool) AST

func (b Bool) AST() ast.Value

func (Bool) Clone

func (b Bool) Clone(bool) File

func (Bool) Compare

func (b Bool) Compare(other Json) int

func (Bool) Contents

func (b Bool) Contents() interface{}

func (Bool) Extract

func (b Bool) Extract(ptr string) (Json, error)

func (Bool) JSON

func (b Bool) JSON() interface{}

func (Bool) String

func (b Bool) String() string

func (Bool) Value

func (b Bool) Value() bool

func (Bool) WriteTo

func (b Bool) WriteTo(w io.Writer) (int64, error)

type Collections

type Collections interface {
	// Resource returns resource meta data for a particular resource. Returns nil if no resource matches the name.
	Resource(name string) Resource

	// Collections returns all JSON collections available.
	Collections() []string

	// Walk executes a depth-first search over the snapshot, stopping the recursion (but not the entire walk) if the callback returns false.
	Walk(func(resource Resource) bool)

	// Diff computes a binary diff against collections provided and returns a reader for consuming the computed diff together with the number of bytes available. Boolean value is true
	// if the diff is empty.
	Diff(other Collections) (*utils.BytesReader, int64, bool, error)

	// Writable returns a writable copy of the collections.
	Writable() WritableCollections

	// Len returns the # of bytes in binary level representation.
	Len() int64

	// Reader returns a binary level reader for the entire collection.
	Reader() *utils.MultiReader

	// DeltaReader returns a binary level reader for the delta of the collection, if a delta collection.
	DeltaReader() *utils.MultiReader

	io.WriterTo

	// Objects returns the storage objects below. 	If a snapshot based collection, the slice will hold only one entry, the snapshot object. If a
	// delta based collection, the first entity will be the delta object and the second for the snapshot. Note the meta data may be nil, if it was not provided at the construction time.
	Objects() []interface{}

	// WriteBlob replaces the contents of a binary resource.
	WriteBlob(name string, blob Blob)

	// WriteJSON replaces the contents of a JSON resource.
	WriteJSON(name string, j Json)

	// PatchJSON applies a patch to a JSON resource.
	PatchJSON(name string, patch Patch) (bool, error)

	// WriteDirectory creates a directory.
	WriteDirectory(name string)

	// Remove removes a resource. It returns true if found and successfully removed. It does not remove a directory if it's not empty.
	Remove(name string) bool

	// Writes a meta key-value pair for a resource, returning if successful. Note, the resource has to exist this to take effect.
	WriteMeta(name string, key string, value string) bool
}

Collections represents a logical snapshot of hierarchical resources coming from a single data source. Internally it is binary encoded, and it may use delta encoding for compact representation.

func NewCollectionsFromReaders

func NewCollectionsFromReaders(snapshotReader *utils.MultiReader, slen int64, dr *utils.MultiReader, dlen int64, objects ...interface{}) (collections Collections, err error)

type Decoder

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

Decoder mimics the golang JSON decoder: reading a JSON object out of a byte stream. For simplicity, the Decode() implementation returns the constructed object, instead of taking a pointer as a parameter as the standard package.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func NewStringDecoder

func NewStringDecoder(s string) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode() (Json, error)

func (*Decoder) UnmarshalArray

func (decoder *Decoder) UnmarshalArray(f func(decoder *Decoder) error) error

func (*Decoder) UnmarshalObject

func (decoder *Decoder) UnmarshalObject(f func(property string, decoder *Decoder) error) error

func (*Decoder) UnmarshalString

func (decoder *Decoder) UnmarshalString() (string, error)

type File

type File interface {
	io.WriterTo
	Contents() interface{}

	// Clone returns a (deep) copy of the file.
	Clone(deepCopy bool) File
}

File is the interface all files (structured or unstructured) stored to the snapshot implement. It is for accessing the contents of the file only; the metadata is to be accessed over the Resource interface (which represents a single entity in the namespace).

type Float

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

Float represents a JSON float value.

func Max

func Max(a, b Float) Float

func Min

func Min(a, b Float) Float

func NewFloat

func NewFloat(value gojson.Number) Float

func NewFloatInt

func NewFloatInt(i int64) Float

func (Float) AST

func (f Float) AST() ast.Value

func (Float) Add

func (f Float) Add(addition Float) Float

func (Float) Clone

func (f Float) Clone(bool) File

func (Float) Compare

func (f Float) Compare(other Json) int

func (Float) Contents

func (f Float) Contents() interface{}

func (Float) Divide

func (f Float) Divide(divisor Float) Float

func (Float) Extract

func (f Float) Extract(ptr string) (Json, error)

func (Float) JSON

func (f Float) JSON() interface{}

func (Float) Multiply

func (f Float) Multiply(multiplier Float) Float

func (Float) String

func (f Float) String() string

func (Float) Sub

func (f Float) Sub(decrement Float) Float

func (Float) Value

func (f Float) Value() gojson.Number

func (Float) WriteTo

func (f Float) WriteTo(w io.Writer) (int64, error)

type Iterable

type Iterable interface {
	Len() int
	Iterate(i int) Json

	RemoveIdx(i int) Json
	SetIdx(i int, j File) Json
	// contains filtered or unexported methods
}

Iterable is implemented by both Arrays and Objects.

type Json

type Json interface {
	File
	fmt.Stringer

	// JSON returns Go JSON object. This is same as File.Contents().
	JSON() interface{}

	// AST return OPA ast.Value.
	AST() ast.Value

	// Extract returns the JSON element the provided JSON pointer (RFC 6901) refers to. The function returns an error if no element found.
	Extract(ptr string) (Json, error)

	// Compare compares this JSON node ('a') to another JSON ('b'), returning -1, 0, 1 if 'a' is less than 'b', 'a' equals to 'b', or 'a' is more than 'b', respectively.
	Compare(other Json) int
	// contains filtered or unexported methods
}

Json is the interface every element within the document implements.

func MustNew

func MustNew(value interface{}) Json

MustNew constructs a JSON object out of go native types. It supports the struct tags. It panics if the provided value does not convert to JSON.

func New

func New(value interface{}) (Json, error)

New constructs a JSON object out of go native types. It supports the struct tags.

func NewFromBinary

func NewFromBinary(data []byte) (Json, error)

NewFromBinary reads a JSON snapshot.

func UnionObjects

func UnionObjects(a, b Json) Json

type JsonPatchSpec

type JsonPatchSpec []map[string]interface{}

type JsonPatchTestFailed

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

func (JsonPatchTestFailed) Error

func (e JsonPatchTestFailed) Error() string

type Kind

type Kind uint
const (
	Invalid Kind = iota
	Directory
	Unstructured // Unstructured is reserved for binary resource.
	JSON
)

type Null

type Null struct{}

Null represents a JSON nil value.

func NewNull

func NewNull() Null

func (Null) AST

func (n Null) AST() ast.Value

func (Null) Clone

func (n Null) Clone(bool) File

func (Null) Compare

func (n Null) Compare(other Json) int

func (Null) Contents

func (n Null) Contents() interface{}

func (Null) Extract

func (n Null) Extract(ptr string) (Json, error)

func (Null) JSON

func (n Null) JSON() interface{}

func (Null) String

func (n Null) String() string

func (Null) WriteTo

func (n Null) WriteTo(w io.Writer) (int64, error)

type Object

type Object interface {
	Json

	Names() []string
	Set(name string, value Json) (Object, bool)

	Value(name string) Json

	Remove(name string) Object
	Serialize(cache *encodingCache, buffer *bytes.Buffer, base int32) (int32, error)
	Union(other Json) Json

	Iterable
	// contains filtered or unexported methods
}

Object represents JSON object.

func Debug

func Debug(c Collections) Object

func NewObject

func NewObject(properties map[string]File) Object

func NewObjectMapCompact

func NewObjectMapCompact(properties map[string]File, interning map[interface{}]*[]string) Object

func NewObjectMapCompactStrings

func NewObjectMapCompactStrings(properties map[string]File, interning map[interface{}]*[]string) Object

type Object2

type Object2 interface {
	Json
	Insert(k, v Json) Object2

	Get(k Json) (Json, bool)

	Iter(iter func(key, value Json) (bool, error)) error

	Iter2(iter func(key, value interface{}) (bool, error)) error
	Equal(other Object2) bool
	Diff(other Object2) Object2
	Len() int
	Hash() uint64
	AST() ast.Value
	Union(other Object2) Object2
	// contains filtered or unexported methods
}

func NewObject2

func NewObject2(n int) Object2

type ObjectBinary

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

func (ObjectBinary) AST

func (o ObjectBinary) AST() ast.Value

func (ObjectBinary) Clone

func (o ObjectBinary) Clone(bool) File

func (ObjectBinary) Compare

func (o ObjectBinary) Compare(other Json) int

func (ObjectBinary) Contents

func (o ObjectBinary) Contents() interface{}

func (ObjectBinary) Extract

func (o ObjectBinary) Extract(ptr string) (Json, error)

func (ObjectBinary) Iterate

func (o ObjectBinary) Iterate(i int) Json

func (ObjectBinary) JSON

func (o ObjectBinary) JSON() interface{}

func (ObjectBinary) Len

func (o ObjectBinary) Len() int

func (ObjectBinary) Names

func (o ObjectBinary) Names() []string

func (ObjectBinary) NamesIndex

func (o ObjectBinary) NamesIndex(i int) string

func (ObjectBinary) Remove

func (o ObjectBinary) Remove(name string) Object

func (ObjectBinary) RemoveIdx

func (o ObjectBinary) RemoveIdx(i int) Json

func (ObjectBinary) Serialize

func (o ObjectBinary) Serialize(cache *encodingCache, buffer *bytes.Buffer, base int32) (int32, error)

func (ObjectBinary) Set

func (o ObjectBinary) Set(name string, value Json) (Object, bool)

func (ObjectBinary) SetIdx

func (o ObjectBinary) SetIdx(i int, value File) Json

func (ObjectBinary) String

func (o ObjectBinary) String() string

func (ObjectBinary) Union

func (o ObjectBinary) Union(other Json) Json

func (ObjectBinary) Value

func (o ObjectBinary) Value(name string) Json

func (ObjectBinary) WriteTo

func (o ObjectBinary) WriteTo(w io.Writer) (int64, error)

type ObjectMap

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

func (*ObjectMap) AST

func (o *ObjectMap) AST() ast.Value

func (*ObjectMap) Clone

func (o *ObjectMap) Clone(deepCopy bool) File

func (*ObjectMap) Compare

func (o *ObjectMap) Compare(other Json) int

func (*ObjectMap) Contents

func (o *ObjectMap) Contents() interface{}

func (*ObjectMap) Extract

func (o *ObjectMap) Extract(ptr string) (Json, error)

func (*ObjectMap) Iterate

func (o *ObjectMap) Iterate(i int) Json

func (*ObjectMap) JSON

func (o *ObjectMap) JSON() interface{}

func (*ObjectMap) Len

func (o *ObjectMap) Len() int

func (*ObjectMap) Names

func (o *ObjectMap) Names() []string

func (*ObjectMap) Remove

func (o *ObjectMap) Remove(name string) Object

func (*ObjectMap) RemoveIdx

func (o *ObjectMap) RemoveIdx(i int) Json

func (*ObjectMap) Serialize

func (o *ObjectMap) Serialize(cache *encodingCache, buffer *bytes.Buffer, base int32) (int32, error)

func (*ObjectMap) Set

func (o *ObjectMap) Set(name string, value Json) (Object, bool)

func (*ObjectMap) SetIdx

func (o *ObjectMap) SetIdx(i int, j File) Json

func (*ObjectMap) String

func (o *ObjectMap) String() string

func (*ObjectMap) Union

func (o *ObjectMap) Union(other Json) Json

func (*ObjectMap) Value

func (o *ObjectMap) Value(name string) Json

func (*ObjectMap) WriteTo

func (o *ObjectMap) WriteTo(w io.Writer) (int64, error)

type ObjectMapCompact

type ObjectMapCompact[T indexable] struct {
	// contains filtered or unexported fields
}

ObjectMapCompact is a compact implementation of the object map for objects with at most 32 keys.

func (*ObjectMapCompact[T]) AST

func (o *ObjectMapCompact[T]) AST() ast.Value

func (*ObjectMapCompact[T]) Clone

func (o *ObjectMapCompact[T]) Clone(deepCopy bool) File

func (*ObjectMapCompact[T]) Compare

func (o *ObjectMapCompact[T]) Compare(other Json) int

func (*ObjectMapCompact[T]) Contents

func (o *ObjectMapCompact[T]) Contents() interface{}

func (*ObjectMapCompact[T]) Extract

func (o *ObjectMapCompact[T]) Extract(ptr string) (Json, error)

func (*ObjectMapCompact[T]) Iterate

func (o *ObjectMapCompact[T]) Iterate(i int) Json

func (*ObjectMapCompact[T]) JSON

func (o *ObjectMapCompact[T]) JSON() interface{}

func (*ObjectMapCompact[T]) Len

func (o *ObjectMapCompact[T]) Len() int

func (*ObjectMapCompact[T]) Names

func (o *ObjectMapCompact[T]) Names() []string

func (*ObjectMapCompact[T]) Remove

func (o *ObjectMapCompact[T]) Remove(name string) Object

func (*ObjectMapCompact[T]) RemoveIdx

func (o *ObjectMapCompact[T]) RemoveIdx(i int) Json

func (*ObjectMapCompact[T]) Serialize

func (o *ObjectMapCompact[T]) Serialize(cache *encodingCache, buffer *bytes.Buffer, base int32) (int32, error)

func (*ObjectMapCompact[T]) Set

func (o *ObjectMapCompact[T]) Set(name string, value Json) (Object, bool)

func (*ObjectMapCompact[T]) SetIdx

func (o *ObjectMapCompact[T]) SetIdx(i int, j File) Json

func (*ObjectMapCompact[T]) String

func (o *ObjectMapCompact[T]) String() string

func (*ObjectMapCompact[T]) Union

func (o *ObjectMapCompact[T]) Union(other Json) Json

func (*ObjectMapCompact[T]) Value

func (o *ObjectMapCompact[T]) Value(name string) Json

func (*ObjectMapCompact[T]) WriteTo

func (o *ObjectMapCompact[T]) WriteTo(w io.Writer) (int64, error)

type ObjectMapCompactStrings

type ObjectMapCompactStrings[T indexableStrings] struct {
	// contains filtered or unexported fields
}

ObjectMapCompact is a compact implementation of the object map for objects with at most 32 String values.

func (*ObjectMapCompactStrings[T]) AST

func (o *ObjectMapCompactStrings[T]) AST() ast.Value

func (*ObjectMapCompactStrings[T]) Clone

func (o *ObjectMapCompactStrings[T]) Clone(bool) File

func (*ObjectMapCompactStrings[T]) Compare

func (o *ObjectMapCompactStrings[T]) Compare(other Json) int

func (*ObjectMapCompactStrings[T]) Contents

func (o *ObjectMapCompactStrings[T]) Contents() interface{}

func (*ObjectMapCompactStrings[T]) Extract

func (o *ObjectMapCompactStrings[T]) Extract(ptr string) (Json, error)

func (*ObjectMapCompactStrings[T]) Iterate

func (o *ObjectMapCompactStrings[T]) Iterate(i int) Json

func (*ObjectMapCompactStrings[T]) JSON

func (o *ObjectMapCompactStrings[T]) JSON() interface{}

func (*ObjectMapCompactStrings[T]) Len

func (o *ObjectMapCompactStrings[T]) Len() int

func (*ObjectMapCompactStrings[T]) Names

func (o *ObjectMapCompactStrings[T]) Names() []string

func (*ObjectMapCompactStrings[T]) Remove

func (o *ObjectMapCompactStrings[T]) Remove(name string) Object

func (*ObjectMapCompactStrings[T]) RemoveIdx

func (o *ObjectMapCompactStrings[T]) RemoveIdx(i int) Json

func (*ObjectMapCompactStrings[T]) Serialize

func (o *ObjectMapCompactStrings[T]) Serialize(cache *encodingCache, buffer *bytes.Buffer, base int32) (int32, error)

func (*ObjectMapCompactStrings[T]) Set

func (o *ObjectMapCompactStrings[T]) Set(name string, value Json) (Object, bool)

func (*ObjectMapCompactStrings[T]) SetIdx

func (o *ObjectMapCompactStrings[T]) SetIdx(i int, j File) Json

func (*ObjectMapCompactStrings[T]) String

func (o *ObjectMapCompactStrings[T]) String() string

func (*ObjectMapCompactStrings[T]) Union

func (o *ObjectMapCompactStrings[T]) Union(other Json) Json

func (*ObjectMapCompactStrings[T]) Value

func (o *ObjectMapCompactStrings[T]) Value(name string) Json

func (*ObjectMapCompactStrings[T]) WriteTo

func (o *ObjectMapCompactStrings[T]) WriteTo(w io.Writer) (int64, error)

type Op

type Op struct {
	Value Json `json:"value,omitempty"`

	Op   PatchOp `json:"op"`
	Path string  `json:"path"`
	From string  `json:"from"` // Note, only marshaled if operation is either copy or move.
	// contains filtered or unexported fields
}

func (Op) ApplyTo

func (o Op) ApplyTo(file Json) (Json, error)

func (Op) MarshalJSON

func (o Op) MarshalJSON() ([]byte, error)

type Patch

type Patch []Op

func NewPatch

func NewPatch(spec JsonPatchSpec) (Patch, error)

func (Patch) ApplyTo

func (p Patch) ApplyTo(doc Json) (Json, error)

func (*Patch) Unmarshal

func (p *Patch) Unmarshal(decoder *Decoder) error

func (*Patch) UnmarshalJSON

func (p *Patch) UnmarshalJSON(data []byte) error

type PatchOp

type PatchOp string
const (
	PatchOpAdd     PatchOp = "add"
	PatchOpReplace PatchOp = "replace"
	PatchOpRemove  PatchOp = "remove"
	PatchOpTest    PatchOp = "test"
	PatchOpCopy    PatchOp = "copy"
	PatchOpMove    PatchOp = "move"
	PatchOpCreate  PatchOp = "create"
)

type Resource

type Resource interface {
	// Name returns the full name.
	Name() string

	// Kind returns Invalid if the resource does not exist, otherwise Unstructured (for a binary resource), JSON (for a JSON resource), and Directory for directory.
	Kind() Kind

	// Blob returns resource meta data for a particular resource. Provided name is local and scoped to the directory. Returns nil if no resource matches the name.
	Resource(name string) Resource

	// Resources returns all resources under a directory (not recursively, though). Will panic if the name does not point to a directory resource.
	Resources() []Resource

	// File returns a file object. It's callers responsibility to determine the type.
	File() File

	// Blob returns a binary resource. Will panic if the resource is not of binary type.
	Blob() Blob

	// Collection returns a JSON collection resource. Will panic if the resource is not of JSON type.
	JSON() Json

	// Meta returns a meta value for the key, and true if it exists.
	Meta(key string) (string, bool)

	// Walk executes a depth-first search over the resource, stopping the recursion to a particular node if the callback returns false but not the entire walk.
	Walk(callback func(Resource) bool)
}

Resource captures the meta data available for a resource. It is limited to type information for now.

type Set

type Set interface {
	Json
	Add(v Json) Set

	Get(v Json) (Json, bool)
	Iter(iter func(v Json) (bool, error)) (bool, error)
	Iter2(iter func(v, vv interface{}) (bool, error)) (bool, error)
	Equal(other Set) bool
	Len() int
	Hash() uint64
	AST() ast.Value
	MergeWith(other Set) Set
	// contains filtered or unexported methods
}

func NewSet

func NewSet(n int) Set

type String

type String string

String represents a JSON string.

func NewString

func NewString(s string) *String

func (*String) AST

func (s *String) AST() ast.Value

func (*String) Clone

func (s *String) Clone(bool) File

func (*String) Compare

func (s *String) Compare(other Json) int

func (*String) Contents

func (s *String) Contents() interface{}

func (*String) Extract

func (s *String) Extract(ptr string) (Json, error)

func (*String) JSON

func (s *String) JSON() interface{}

func (*String) String

func (s *String) String() string

func (*String) Value

func (s *String) Value() string

func (*String) WriteTo

func (s *String) WriteTo(w io.Writer) (int64, error)

type T

type T = interface{}

type WritableCollections

type WritableCollections interface {
	// Blob returns resource meta data for a particular resource. Returns nil if no resource matches the name.
	Resource(name string) Resource

	// WriteBlob replaces the contents of a
	WriteBlob(name string, blob Blob)

	// WriteJSON
	WriteJSON(name string, j Json)

	// PatchJSON applies a patch to a JSON resource.
	PatchJSON(name string, patch Patch) (bool, error)

	// WriteDirectory
	WriteDirectory(name string)

	// Writes a meta key-value pair for a resource, returning if successful. Note, the resource has to exist this to take effect.
	WriteMeta(name string, key string, value string) bool

	// Prepare prepares the collection for log append. Any changes to the writable collection after this invocation are not reflected to the returned collections.
	Prepare(timestamp time.Time) Collections
}

WritableCollections is updateable logical snapshot.

func NewCollections

func NewCollections() WritableCollections

NewCollections translates a Go native collection of collections to the binary snapshot.

Directories

Path Synopsis
internal
json
Package json implements encoding and decoding of JSON as defined in RFC 7159.
Package json implements encoding and decoding of JSON as defined in RFC 7159.

Jump to

Keyboard shortcuts

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