Documentation ¶
Index ¶
- func GetObjectsInUse() uint64
- func IsFloat64ValueFitsIntoField(f *Field, float64Src float64) bool
- type Buffer
- func (b *Buffer) Append(name string, toAppend interface{})
- func (b *Buffer) ApplyJSONAndToBytes(jsonBytes []byte) (res []byte, nilled []string, err error)
- func (b *Buffer) ApplyMap(data map[string]interface{}) error
- func (b *Buffer) ApplyMapBuffer(jsonMap []byte) error
- func (b *Buffer) CommitChanges() error
- func (b *Buffer) Get(name string) interface{}
- func (b *Buffer) GetBool(name string) (bool, bool)
- func (b *Buffer) GetBoolArray(name string) IBoolArray
- func (b *Buffer) GetByField(f *Field) interface{}
- func (b *Buffer) GetByte(name string) (byte, bool)
- func (b *Buffer) GetByteArray(name string) IByteArray
- func (b *Buffer) GetBytes() []byte
- func (b *Buffer) GetFloat32(name string) (float32, bool)
- func (b *Buffer) GetFloat32Array(name string) IFloat32Array
- func (b *Buffer) GetFloat64(name string) (float64, bool)
- func (b *Buffer) GetFloat64Array(name string) IFloat64Array
- func (b *Buffer) GetInt32(name string) (int32, bool)
- func (b *Buffer) GetInt32Array(name string) IInt32Array
- func (b *Buffer) GetInt64(name string) (int64, bool)
- func (b *Buffer) GetInt64Array(name string) IInt64Array
- func (b *Buffer) GetString(name string) (string, bool)
- func (b *Buffer) GetStringArray(name string) IStringArray
- func (b *Buffer) HasValue(name string) bool
- func (b *Buffer) IsModified() bool
- func (b *Buffer) IsNil() bool
- func (b *Buffer) IterateFields(names []string, callback func(name string, value interface{}) bool)
- func (b *Buffer) MarshalJSONObject(enc *gojay.Encoder)
- func (b *Buffer) NKeys() int
- func (b *Buffer) Release()
- func (b *Buffer) Reset(bytes []byte)
- func (b *Buffer) Set(name string, value interface{})
- func (b *Buffer) ToBytes() ([]byte, error)
- func (b *Buffer) ToBytesNilled() (res []byte, nilledFields []string, err error)
- func (b *Buffer) ToBytesWithBuilder(builder *flatbuffers.Builder) error
- func (b *Buffer) ToJSON() []byte
- func (b *Buffer) ToJSONMap() map[string]interface{}
- func (b *Buffer) UnmarshalJSONObject(dec *gojay.Decoder, fn string) (err error)
- type Field
- type FieldType
- type IBoolArray
- type IByteArray
- type IFloat32Array
- type IFloat64Array
- type IInt32Array
- type IInt64Array
- type IStringArray
- type ObjectArray
- type Scheme
- func (s *Scheme) AddArray(name string, elementType FieldType, isMandatory bool) *Scheme
- func (s *Scheme) AddField(name string, ft FieldType, isMandatory bool) *Scheme
- func (s *Scheme) AddFieldC(name string, ft FieldType, nested *Scheme, isMandatory bool, IsArray bool) *Scheme
- func (s *Scheme) AddNested(name string, nested *Scheme, isMandatory bool) *Scheme
- func (s *Scheme) AddNestedArray(name string, nested *Scheme, isMandatory bool) *Scheme
- func (s *Scheme) GetNestedScheme(nestedObjectField string) *Scheme
- func (s *Scheme) MarshalYAML() (interface{}, error)
- func (s *Scheme) UnmarshalYAML(unmarshal func(interface{}) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetObjectsInUse ¶
func GetObjectsInUse() uint64
GetObjectsInUse returns pooled objects amount which are currently in use, i.e. not released useful for testing and metrics accounting
func IsFloat64ValueFitsIntoField ¶
IsFloat64ValueFitsIntoField checks if target type of field enough to fit float64 value e.g. float64(1) could be applied to any numeric field, float64(256) to any numeric except FieldTypeByte etc Useful to check float64 values came from JSON
Types ¶
type Buffer ¶
type Buffer struct { Scheme *Scheme // contains filtered or unexported fields }
Buffer is wrapper for FlatBuffers
func ReadBuffer ¶
ReadBuffer creates Buffer from bytes using provided Scheme
func (*Buffer) Append ¶
Append appends an array field. toAppend could be a single value or an array of values Value for byte array field could be base64 string or []byte Rewrites previous modifications made by Set, Append, ApplyJSONAndToBytes, ApplyMapBuffer, ApplyMap `Get()` will not consider modifications made by Set, Append, ApplyJSONAndToBytes, ApplyMapBuffer, ApplyMap Nil or empty array is provided -> equals to unset the field
func (*Buffer) ApplyJSONAndToBytes ¶
ApplyJSONAndToBytes sets field values described by provided json and returns new FlatBuffer byte array with inital + applied data See `ApplyMapBuffer` for details
func (*Buffer) ApplyMap ¶
ApplyMap sets field values described by provided map[string]interface{} Resulting buffer has no value (or has nil value) for a mandatory field -> error Value type and field type are incompatible (e.g. string for numberic field) -> error Value and field types differs but value fits into field -> no error. Examples:
255 fits into float, double, int, long, byte; 256 does not fit into byte math.MaxInt64 does not fit into int32
Unexisting field is provided -> error Byte arrays could be base64 strings or []byte Array element is nil -> error (not supported) Note: float is provided for an int field -> error, whereas no error on ApplyJSONAndToBytes() (gojay feature) `Get()` will not consider modifications made by Set, Append, ApplyJSONAndToBytes, ApplyMapBuffer, ApplyMap Rewrites previous modifications made by Set, Append, ApplyJSONAndToBytes, ApplyMapBuffer, ApplyMap Non-empty array is applied over an existing array -> incomming array is appended to the existing Nil or empty array is applied over an existing array -> existing array is unset
func (*Buffer) ApplyMapBuffer ¶
ApplyMapBuffer modifies Buffer with JSON specified by jsonMap ToBytes() will return byte array with initial + applied data float is provided for an int field -> no error, integer part only is used (gojay feature), whereas is an error on ApplyMap() Values for byte arrays are expected to be base64 strings `Get()` will not consider modifications made by Set, Append, ApplyJSONAndToBytes, ApplyMapBuffer, ApplyMap Rewrites previous modifications made by Set, Append, ApplyJSONAndToBytes, ApplyMapBuffer, ApplyMap
func (*Buffer) CommitChanges ¶
applies all current modifications to the underlying byte array and clears all modifications note: takes one byte array allocation
func (*Buffer) Get ¶
Get returns stored field value by name. field is scalar -> scalar is returned field is an array of scalars -> []T is returned field is a nested object -> *dynobuffers.Buffer is returned. field is an array of nested objects -> *dynobuffers.ObjectArray is returned. field is not set, set to nil or no such field in the Scheme -> nil `Get()` will not consider modifications made by Set, Append, ApplyJSONAndToBytes, ApplyMapBuffer, ApplyMap
func (*Buffer) GetBool ¶
GetBool returns bool value by name and if the Scheme contains the field and if the value was set to non-nil
func (*Buffer) GetBoolArray ¶
func (b *Buffer) GetBoolArray(name string) IBoolArray
func (*Buffer) GetByField ¶
GetByField is an analogue of Get() but accepts a known Field
func (*Buffer) GetByte ¶
GetByte returns byte value by name and if the Scheme contains the field and if the value was set to non-nil
func (*Buffer) GetByteArray ¶
func (b *Buffer) GetByteArray(name string) IByteArray
func (*Buffer) GetBytes ¶
GetBytes is an alias for ToBytes(). Simply returns underlying buffer if no modifications. Returns nil on error
func (*Buffer) GetFloat32 ¶
GetFloat32 returns float32 value by name and if the Scheme contains the field and if the value was set to non-nil
func (*Buffer) GetFloat32Array ¶
func (b *Buffer) GetFloat32Array(name string) IFloat32Array
func (*Buffer) GetFloat64 ¶
GetFloat64 returns float64 value by name and if the Scheme contains the field and if the value was set to non-nil
func (*Buffer) GetFloat64Array ¶
func (b *Buffer) GetFloat64Array(name string) IFloat64Array
func (*Buffer) GetInt32 ¶
GetInt32 returns int32 value by name and if the Scheme contains the field and the value was set to non-nil
func (*Buffer) GetInt32Array ¶
func (b *Buffer) GetInt32Array(name string) IInt32Array
func (*Buffer) GetInt64 ¶
GetInt64 returns int64 value by name and if the Scheme contains the field and if the value was set to non-nil
func (*Buffer) GetInt64Array ¶
func (b *Buffer) GetInt64Array(name string) IInt64Array
func (*Buffer) GetString ¶
GetString returns string value by name and if the Scheme contains the field and if the value was set to non-nil
func (*Buffer) GetStringArray ¶
func (b *Buffer) GetStringArray(name string) IStringArray
func (*Buffer) HasValue ¶
HasValue returns if specified field exists in the scheme and its value is set to non-nil
func (*Buffer) IsModified ¶
func (*Buffer) IsNil ¶
IsNil returns if current buffer means nothing need to comply to gojay.MarshalerJSONObject
func (*Buffer) IterateFields ¶
IterateFields calls `callback` for each fields which has a value. `names` empty -> calback is called for all fields which has a value `names` not empty -> callback is called for each specified name if according field has a value callbeck returns false -> iteration stops
func (*Buffer) MarshalJSONObject ¶
MarshalJSONObject encodes current Buffer into JSON using gojay. Complies to gojay.MarshalerJSONObject interface
func (*Buffer) NKeys ¶
NKeys returns Schemes's root fields amount. Conforms to gojay.UnmarshalerJSONObject interface
func (*Buffer) Release ¶
func (b *Buffer) Release()
Release returns used Buffer into pool Note: Buffer instance itself, result of ToBytes() must not be used after Release()
func (*Buffer) Reset ¶
Reset sets current underlying byte array and clears modified fields. Useful for *Buffer instance reuse Note: bytes must match the Buffer's scheme
func (*Buffer) Set ¶
Set sets field value by name. Call ToBytes() to get modified byte array Value for byte array field could be base64 string or []byte `Get()` will not consider modifications made by Set, Append, ApplyJSONAndToBytes, ApplyMapBuffer, ApplyMap Rewrites previous modifications made by Set, Append, ApplyJSONAndToBytes, ApplyMapBuffer, ApplyMap
func (*Buffer) ToBytes ¶
ToBytes returns new FlatBuffer byte array with fields modified by Set() and fields which initially had values Note: initial byte array and current modifications are kept
func (*Buffer) ToBytesNilled ¶
ToBytesNilled constructs resulting byte array (nil values are not stored) and list of field names which were nilled using Set, ApplyJSON, ApplyMap useful in cases when we should know which fields were null on load from map or JSON nilled fields of nested objects are not considered
func (*Buffer) ToBytesWithBuilder ¶
func (b *Buffer) ToBytesWithBuilder(builder *flatbuffers.Builder) error
ToBytesWithBuilder same as ToBytes but uses builder builder.Reset() is invoked
func (*Buffer) ToJSONMap ¶
ToJSONMap returns map[string]interface{} representation of the buffer compatible to json result map is built using inital data + current modifications numeric field types are kept (not float64 as json.Unmarshal() does) nested object, array, array element is empty or nil -> skip empty buffer -> empty map is returned
type Field ¶
type Field struct { Name string Ft FieldType Order int IsMandatory bool FieldScheme *Scheme // != nil for FieldTypeObject only IsArray bool // contains filtered or unexported fields }
Field describes a Scheme field
func (*Field) QualifiedName ¶
QualifiedName returns ownerScheme.fieldName
type FieldType ¶
type FieldType int
FieldType s.e.
const ( // FieldTypeUnspecified - wrong type FieldTypeUnspecified FieldType = iota // FieldTypeObject field is nested Scheme FieldTypeObject // FieldTypeInt32 int32 FieldTypeInt32 // FieldTypeInt64 int64 FieldTypeInt64 // FieldTypeFloat32 float32 FieldTypeFloat32 // FieldTypeFloat64 float64 FieldTypeFloat64 // FieldTypeString variable length FieldTypeString // FieldTypeBool bool FieldTypeBool // FieldTypeByte byte FieldTypeByte )
type IBoolArray ¶
type IByteArray ¶
type IByteArray interface {
Bytes() []byte
}
type IFloat32Array ¶
type IFloat64Array ¶
type IInt32Array ¶
type IInt64Array ¶
type IStringArray ¶
type ObjectArray ¶
ObjectArray used to iterate over array of nested objects ObjectArray.Buffer should be used for reading only
func (*ObjectArray) Next ¶
func (oa *ObjectArray) Next() bool
Next proceeds to a next nested object in the array. If true then .Buffer represents the next element
func (*ObjectArray) Release ¶
func (oa *ObjectArray) Release()
Release returns used ObjectArray instance to the pool. Releases also ObjectArray.Buffer Note: ObjectArray instance itself, ObjectArray.Buffer, result of ObjectArray.Buffer.ToBytes() must not be used after Release()
func (*ObjectArray) Value ¶
func (oa *ObjectArray) Value() interface{}
Value returns *dynobuffers.Buffer instance as current element
type Scheme ¶
Scheme describes fields and theirs order in byte array
func MapSliceToScheme ¶
MapSliceToScheme s.e.
func YamlToScheme ¶
YamlToScheme creates Scheme by provided yaml `fieldName: yamlFieldType` Field types:
- `int` -> `int32`
- `long` -> `int64`
- `float` -> `float32`
- `double` -> `float64`
- `bool` -> `bool`
- `string` -> `string`
- `byte` -> `byte`
Field name starts with the capital letter -> field is mandatory Field name ends with `..` -> field is an array See [dynobuffers_test.go](dynobuffers_test.go) for examples
func (*Scheme) AddFieldC ¶
func (s *Scheme) AddFieldC(name string, ft FieldType, nested *Scheme, isMandatory bool, IsArray bool) *Scheme
AddFieldC adds new finely-tuned field
func (*Scheme) AddNestedArray ¶
AddNestedArray adds array of nested objects field
func (*Scheme) GetNestedScheme ¶
GetNestedScheme returns Scheme of nested object if the field has FieldTypeObject type, nil otherwise
func (*Scheme) MarshalYAML ¶
MarshalYAML marshals Scheme to yaml. Needs to conform to yaml.Marshaler interface
func (*Scheme) UnmarshalYAML ¶
UnmarshalYAML unmarshals Scheme from yaml. Conforms to yaml.Unmarshaler interface fields will be replaced with the ones came from the yaml