Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyMapBuffer(jsonMap []byte) error
- type Buffer
- func (b *Buffer) Append(name string, toAppend interface{})
- func (b *Buffer) ApplyJSONAndToBytes(jsonBytes []byte) ([]byte, error)
- func (b *Buffer) ApplyMap(data map[string]interface{}) error
- func (b *Buffer) Builder() *flatbuffers.Builder
- func (b *Buffer) Get(name string) interface{}
- func (b *Buffer) GetBool(name string) (bool, bool)
- func (b *Buffer) GetByIndex(name string, index int) interface{}
- func (b *Buffer) GetByte(name string) (byte, bool)
- func (b *Buffer) GetBytes() []byte
- func (b *Buffer) GetDouble(name string) (float64, bool)
- func (b *Buffer) GetFloat(name string) (float32, bool)
- func (b *Buffer) GetInt(name string) (int32, bool)
- func (b *Buffer) GetLong(name string) (int64, bool)
- func (b *Buffer) GetNames() []string
- func (b *Buffer) GetString(name string) (string, bool)
- func (b *Buffer) HasValue(name string) bool
- func (b *Buffer) Release()
- func (b *Buffer) ReleaseFields()
- func (b *Buffer) Reset(bytes []byte)
- func (b *Buffer) Set(name string, value interface{})
- func (b *Buffer) ToBytes() ([]byte, error)
- func (b *Buffer) ToBytesWithBuilder(builder *flatbuffers.Builder) ([]byte, error)
- func (b *Buffer) ToJSON() []byte
- func (b *Buffer) ToJSONMap() map[string]interface{}
- type BuffersSlice
- type Field
- type FieldType
- type ObjectArray
- type OffsetSlice
- type Scheme
- func (s *Scheme) AddArray(name string, elementType FieldType, isMandatory bool)
- func (s *Scheme) AddField(name string, ft FieldType, isMandatory bool)
- func (s *Scheme) AddFieldC(name string, ft FieldType, nested *Scheme, isMandatory bool, IsArray bool)
- func (s *Scheme) AddNested(name string, nested *Scheme, isMandatory bool)
- func (s *Scheme) AddNestedArray(name string, nested *Scheme, isMandatory bool)
- func (s *Scheme) GetNestedScheme(nestedObjectField string) *Scheme
- func (s *Scheme) MarshalYAML() (interface{}, error)
- func (s *Scheme) UnmarshalYAML(unmarshal func(interface{}) error) error
- type StringsSlice
- type UOffsetSlice
Constants ¶
const DefaultBufferSize = 10
Variables ¶
var BufferPool = sync.Pool{ New: func() interface{} { return &Buffer{ builder: flatbuffers.NewBuilder(0), modifiedFields: make([]*modifiedField, DefaultBufferSize), } }, }
var BuffersPool = sync.Pool{ New: func() interface{} { return &BuffersSlice{ Slice: make([]*Buffer, DefaultBufferSize), } }, }
var BuilderPool = sync.Pool{ New: func() interface{} { return flatbuffers.NewBuilder(0) }, }
var OffsetPool = sync.Pool{ New: func() interface{} { return &OffsetSlice{ Slice: make([]offset, DefaultBufferSize), } }, }
var StringsPool = sync.Pool{ New: func() interface{} { return &StringsSlice{ Slice: make([]string, DefaultBufferSize), } }, }
var UOffsetPool = sync.Pool{ New: func() interface{} { return &UOffsetSlice{ Slice: make([]flatbuffers.UOffsetT, DefaultBufferSize), } }, }
Functions ¶
func ApplyMapBuffer ¶
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) ApplyJSONAndToBytes ¶
ApplyJSONAndToBytes sets field values described by provided json and returns new FlatBuffer byte array See `ApplyMap` for details
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
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) GetByIndex ¶
GetByIndex returns array field element by its index no such field, index out of bounds, array field is not set or unset -> nil
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) GetDouble ¶
GetDouble returns float64 value by name and if the Scheme contains the field and if the value was set to non-nil
func (*Buffer) GetFloat ¶
GetFloat returns float32 value by name and if the Scheme contains the field and if the value was set to non-nil
func (*Buffer) GetInt ¶
GetInt returns int32 value by name and if the Scheme contains the field and the value was set to non-nil
func (*Buffer) GetLong ¶
GetLong returns int64 value by name and if the Scheme contains the field and if the value was set to non-nil
func (*Buffer) GetNames ¶
GetNames returns list of field names which values are non-nil in current buffer Set() fields are not considered fields of nested objects are not considered
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) HasValue ¶
HasValue returns if specified field exists in the scheme and its value is set to non-nil
func (*Buffer) ReleaseFields ¶
func (b *Buffer) ReleaseFields()
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. Underlying byte array is not modified. Call ToBytes() to get modified byte array
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) ToBytesWithBuilder ¶
func (b *Buffer) ToBytesWithBuilder(builder *flatbuffers.Builder) ([]byte, error)
ToBytesWithBuilder same as ToBytes but uses builder builder.Reset() is invoked
type BuffersSlice ¶
type BuffersSlice struct {
Slice []*Buffer
}
type Field ¶
type Field struct { Name string Ft FieldType 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 // FieldTypeInt int32 FieldTypeInt // FieldTypeLong int64 FieldTypeLong // FieldTypeFloat float32 FieldTypeFloat // FieldTypeDouble float64 FieldTypeDouble // FieldTypeString variable length FieldTypeString // FieldTypeBool s.e. FieldTypeBool // FieldTypeByte byte FieldTypeByte )
type ObjectArray ¶
ObjectArray used to iterate over array of nested objects
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) Value ¶
func (oa *ObjectArray) Value() interface{}
Value returns *dynobuffers.Buffer instance as current element
type OffsetSlice ¶
type OffsetSlice struct {
Slice []offset
}
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)
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. Needs to conform to yaml.Unmarshaler interface
type StringsSlice ¶
type StringsSlice struct {
Slice []string
}
type UOffsetSlice ¶
type UOffsetSlice struct {
Slice []flatbuffers.UOffsetT
}