serialize

package
v19.10.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 5 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PropertyTypeRegistry = struct{ propertyTypeRegistry }{/* contains filtered or unexported fields */}

PropertyTypeRegistry ...

Functions

func FromJSON

func FromJSON(buf []byte, data interface{}) error

FromJSON reads json code and restores data

func ToJSON

func ToJSON(data interface{}) ([]byte, error)

ToJSON serializes data into JSON

Types

type JSONProperties

type JSONProperties struct {
	Properties jsonProperties
	// This lock is used to make sure addition or removal of keys in JSonProperties won't collide in go routines
	sync.Mutex
	// contains filtered or unexported fields
}

JSONProperties ...

func NewJSONProperties

func NewJSONProperties(module string) *JSONProperties

NewJSONProperties creates a new JSonProperties instance

func (*JSONProperties) LockForRead

func (x *JSONProperties) LockForRead(key string) *SyncedJSONProperty

LockForRead is used to lock an extension for read Returns a pointer to LockedEncodedExtension, on which can be applied method 'Use()' If no extension exists corresponding to the key, an empty extension is created (in other words, this call cannot fail because a key doesn't exist).

func (*JSONProperties) LockForWrite

func (x *JSONProperties) LockForWrite(key string) *SyncedJSONProperty

LockForWrite is used to lock an extension for write Returns a pointer to LockedEncodedExtension, on which can be applied method 'Use()' If no extension exists corresponding to the key, an empty one is created (in other words, this call cannot fail because a key doesn't exist).

func (*JSONProperties) Lookup

func (x *JSONProperties) Lookup(key string) bool

Lookup tells if a key is present in JSonProperties

func (*JSONProperties) MarshalJSON

func (x *JSONProperties) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaller Note: DO NOT LOCK property here, deadlock risk

func (*JSONProperties) SetModule

func (x *JSONProperties) SetModule(module string)

SetModule allows to change the module of the JSONProperties (used to "contextualize" Property Types)

func (*JSONProperties) UnmarshalJSON

func (x *JSONProperties) UnmarshalJSON(b []byte) error

UnmarshalJSON implement json.Unmarshaller Note: DO NOT LOCK property here, deadlock risk

type Property

type Property interface {
	// Content allows to access real data from property
	Content() interface{}
	// Clone allows to duplicate Property
	Clone() Property
	// Replace allows to replace Property with data from source
	Replace(Property) Property
}

Property is the interface each Property must satisfy

type Serializable

type Serializable interface {
	Serialize() ([]byte, error)
	Deserialize([]byte) error
}

Serializable is the interface allowing the conversion of satisfying struct to []byte (Serialize()) and reverse operation (Unserialize())

type SyncedJSONProperty

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

SyncedJSONProperty is used to manipulate jsonProperty with type of lock asked (as returns by JSONProperties.LockBy<x>)

func (SyncedJSONProperty) MarshalJSON

func (jp SyncedJSONProperty) MarshalJSON() ([]byte, error)

MarshalJSON (json.Marshaller interface)

func (*SyncedJSONProperty) ThenUse

func (sp *SyncedJSONProperty) ThenUse(apply func(interface{}) error) (err error)

ThenUse allows to run a function with 'key' decoded content passed as parameter after a call to JSonProperties.LockForRead() or JSonProperties.LockForWrite(). If the extension is locked for write, changes to the decoded data are encoded back into the extension on 'apply' success. If the extension is locked for read, no change will be encoded into the extension. The lock applied on the extension is automatically released on exit.

Jump to

Keyboard shortcuts

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