Documentation
¶
Overview ¶
CRC: crc-VariableStore.md Spec: protocol.md, data-models.md
Package variable implements the Variable Protocol System. CRC: crc-Variable.md, crc-VariableStore.md, crc-WatchManager.md Spec: protocol.md
Index ¶
- func GetObjectReferenceID(value json.RawMessage) (int64, bool)
- func IsObjectReference(value json.RawMessage) bool
- type CreateOptions
- type ObjectReference
- type Store
- func (s *Store) Count() int
- func (s *Store) Create(opts CreateOptions) (int64, error)
- func (s *Store) Destroy(id int64) error
- func (s *Store) Get(id int64) (*Variable, bool)
- func (s *Store) GetAll() []*Variable
- func (s *Store) GetByName(name string) (*Variable, bool)
- func (s *Store) GetChildren(parentID int64) []*Variable
- func (s *Store) Log(level int, format string, args ...interface{})
- func (s *Store) RegisterStandardVariable(name string, id int64) error
- func (s *Store) ResolveObjectReference(ref json.RawMessage) (json.RawMessage, error)
- func (s *Store) Update(id int64, value json.RawMessage, properties map[string]string) error
- func (s *Store) WatchProperty(varID int64, property string, callback func(value interface{}))
- type Variable
- func (v *Variable) GetID() int64
- func (v *Variable) GetProperties() map[string]string
- func (v *Variable) GetProperty(name string) string
- func (v *Variable) GetStoredValue() interface{}
- func (v *Variable) GetValue() interface{}
- func (v *Variable) GetWrapperInstance() interface{}
- func (v *Variable) GetWrapperTypeName() string
- func (v *Variable) HasWrapper() bool
- func (v *Variable) IsObjectReference() bool
- func (v *Variable) IsStandardVariable() bool
- func (v *Variable) IsUnbound() bool
- func (v *Variable) SetProperties(props map[string]string)
- func (v *Variable) SetProperty(name, value string)
- func (v *Variable) SetStoredValue(value interface{})
- func (v *Variable) SetValue(value interface{})
- func (v *Variable) SetWrapperInstance(wrapper interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetObjectReferenceID ¶
func GetObjectReferenceID(value json.RawMessage) (int64, bool)
GetObjectReferenceID extracts the object ID from an object reference.
func IsObjectReference ¶
func IsObjectReference(value json.RawMessage) bool
IsObjectReference checks if a JSON value is an object reference.
Types ¶
type CreateOptions ¶
type CreateOptions struct {
ID int64 // If non-zero, use this ID instead of generating one
ParentID int64
Value json.RawMessage
Properties map[string]string
NoWatch bool
Unbound bool
}
CreateOptions holds options for creating a variable.
type ObjectReference ¶
type ObjectReference struct {
Obj int64 `json:"obj"`
}
ObjectReference represents a reference to another object.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages all variables and their relationships.
func (*Store) Create ¶
func (s *Store) Create(opts CreateOptions) (int64, error)
Create creates a new variable and returns its ID.
func (*Store) GetChildren ¶
GetChildren returns all variables with the given parent ID.
func (*Store) RegisterStandardVariable ¶
RegisterStandardVariable associates @NAME with a variable ID.
func (*Store) ResolveObjectReference ¶
func (s *Store) ResolveObjectReference(ref json.RawMessage) (json.RawMessage, error)
ResolveObjectReference gets object data for {obj: ID} references.
func (*Store) WatchProperty ¶
WatchProperty registers a callback for when a property changes on a variable. This implements the VariableUpdater interface for Lua runtime integration.
type Variable ¶
type Variable struct {
ID int64 `json:"id"`
ParentID int64 `json:"parentId,omitempty"`
Value interface{} `json:"value,omitempty"` // Raw value from path resolution
MonitoredValue interface{} `json:"-"` // For change detection (shallow copy for arrays)
StoredValue interface{} `json:"-"` // Can be the wrapper instance itself
WrapperInstance interface{} `json:"-"` // Internal wrapper object (if wrapper property set)
Properties map[string]string `json:"properties,omitempty"`
Unbound bool `json:"unbound,omitempty"`
// contains filtered or unexported fields
}
Variable represents a single variable in the variable tree. Supports dual value architecture: monitored value for change detection, stored value for frontend (which can be a wrapper instance).
func NewVariable ¶
NewVariable creates a new Variable with the given ID.
func (*Variable) GetID ¶
GetID returns the variable's unique identifier. Implements WrapperVariable interface.
func (*Variable) GetProperties ¶
GetProperties returns a copy of all properties.
func (*Variable) GetProperty ¶
GetProperty returns a property value (empty string if unset).
func (*Variable) GetStoredValue ¶
func (v *Variable) GetStoredValue() interface{}
GetStoredValue returns the stored value (sent to frontend). This is the wrapper instance if it exists, or the raw value otherwise.
func (*Variable) GetValue ¶
func (v *Variable) GetValue() interface{}
GetValue returns the current value.
func (*Variable) GetWrapperInstance ¶
func (v *Variable) GetWrapperInstance() interface{}
GetWrapperInstance returns the internal wrapper instance (nil if none).
func (*Variable) GetWrapperTypeName ¶
GetWrapperTypeName returns the wrapper type name from properties (empty string if unset).
func (*Variable) HasWrapper ¶
HasWrapper checks if a wrapper instance is stored internally.
func (*Variable) IsObjectReference ¶
IsObjectReference checks if the value is {obj: ID} form.
func (*Variable) IsStandardVariable ¶
IsStandardVariable checks if this is registered with @NAME pattern.
func (*Variable) SetProperties ¶
SetProperties sets multiple properties at once, handling priority suffixes.
func (*Variable) SetProperty ¶
SetProperty sets a property value. Empty string removes the property.
func (*Variable) SetStoredValue ¶
func (v *Variable) SetStoredValue(value interface{})
SetStoredValue sets the stored value.
func (*Variable) SetValue ¶
func (v *Variable) SetValue(value interface{})
SetValue updates the value.
func (*Variable) SetWrapperInstance ¶
func (v *Variable) SetWrapperInstance(wrapper interface{})
SetWrapperInstance stores the wrapper instance internally. Called during variable creation when wrapper property is set.