Documentation
¶
Overview ¶
CRC: crc-MessageBatcher.md Spec: protocol.md
CRC: crc-ProtocolHandler.md Spec: protocol.md
Package protocol implements the Variable Protocol message handling. CRC: crc-ProtocolHandler.md Spec: protocol.md
Index ¶
- type BackendLookup
- type BatchWrapper
- type CreateMessage
- type DestroyMessage
- type ErrorMessage
- type GetMessage
- type GetObjectsMessage
- type GetObjectsResponse
- type GetResponse
- type Handler
- func (h *Handler) HandleMessage(connectionID string, msg *Message) (*Response, error)
- func (h *Handler) Log(level int, format string, args ...interface{})
- func (h *Handler) SendError(connectionID string, varID int64, description string) error
- func (h *Handler) SetBackendLookup(lookup BackendLookup)
- func (h *Handler) SetPathVariableHandler(handler PathVariableHandler)
- func (h *Handler) SetPendingQueuer(pending PendingQueuer)
- type Message
- type MessageBatcher
- func (b *MessageBatcher) Flush() []*Message
- func (b *MessageBatcher) FlushJSON() ([]byte, error)
- func (b *MessageBatcher) IsEmpty() bool
- func (b *MessageBatcher) QueueProperties(varID int64, properties map[string]string)
- func (b *MessageBatcher) QueueProperty(varID int64, propertyName, value string)
- func (b *MessageBatcher) QueueValue(varID int64, value json.RawMessage, priority Priority)
- type MessageSender
- type MessageType
- type ObjectData
- type PathVariableHandler
- type PendingChange
- type PendingQueuer
- type PollMessage
- type Priority
- type Response
- type UpdateMessage
- type VariableData
- type WatchMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackendLookup ¶
type BackendLookup interface {
// GetBackendForConnection returns the backend for a connection.
// Returns nil if connection is not associated with a session.
GetBackendForConnection(connectionID string) backend.Backend
}
BackendLookup provides per-connection backend lookup. Used by the protocol handler to route watch operations to the correct session's backend.
type BatchWrapper ¶ added in v0.16.0
BatchWrapper wraps a batch of messages with a userEvent flag. Spec: protocol.md - Frontend sends batches with userEvent flag for immediate/debounced response
type CreateMessage ¶
type CreateMessage struct {
ID int64 `json:"id"`
ParentID int64 `json:"parentId,omitempty"`
Value json.RawMessage `json:"value,omitempty"`
Properties map[string]string `json:"properties,omitempty"`
NoWatch bool `json:"nowatch,omitempty"`
Unbound bool `json:"unbound,omitempty"`
}
CreateMessage represents a create variable request. Spec: protocol.md - create(id, parentId, value, properties, nowatch?, unbound?)
type DestroyMessage ¶
type DestroyMessage struct {
VarID int64 `json:"varId"`
}
DestroyMessage represents a destroy variable request.
type ErrorMessage ¶
type ErrorMessage struct {
VarID int64 `json:"varId,omitempty"`
Code string `json:"code"` // One-word error code (e.g., "path-failure", "not-found", "unauthorized")
Description string `json:"description"` // Human-readable error description
}
ErrorMessage represents an error response. Spec: protocol.md - error(varId, code, description)
type GetMessage ¶
type GetMessage struct {
VarIDs []int64 `json:"varIds"`
}
GetMessage represents a get variables request.
type GetObjectsMessage ¶
type GetObjectsMessage struct {
ObjIDs []int64 `json:"objIds"`
}
GetObjectsMessage represents a get objects by ID request.
type GetObjectsResponse ¶
type GetObjectsResponse struct {
Objects []ObjectData `json:"objects"`
}
GetObjectsResponse contains object data.
type GetResponse ¶
type GetResponse struct {
Variables []VariableData `json:"variables"`
}
GetResponse contains variable values.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler processes protocol messages.
func NewHandler ¶
func NewHandler(cfg *config.Config, sender MessageSender) *Handler
NewHandler creates a new protocol handler.
func (*Handler) HandleMessage ¶
HandleMessage processes an incoming protocol message.
func (*Handler) SetBackendLookup ¶
func (h *Handler) SetBackendLookup(lookup BackendLookup)
SetBackendLookup sets the backend lookup for per-session watch operations.
func (*Handler) SetPathVariableHandler ¶
func (h *Handler) SetPathVariableHandler(handler PathVariableHandler)
SetPathVariableHandler sets the handler for path-based frontend creates.
func (*Handler) SetPendingQueuer ¶
func (h *Handler) SetPendingQueuer(pending PendingQueuer)
SetPendingQueuer sets the pending queue manager.
type Message ¶
type Message struct {
Type MessageType `json:"type"`
Data json.RawMessage `json:"data,omitempty"`
}
Message is the base protocol message structure.
func NewMessage ¶
func NewMessage(msgType MessageType, data interface{}) (*Message, error)
NewMessage creates a new message with the given type and data.
func ParseMessage ¶
ParseMessage parses a raw JSON message into a typed message.
func ParseMessages ¶ added in v0.9.0
ParseMessages parses raw JSON that may be a single message, batched array, or batch wrapper. Returns messages and userEvent flag (true if user-triggered, false otherwise). Spec: protocol.md - Messages can be sent individually or batched with userEvent flag
type MessageBatcher ¶
type MessageBatcher struct {
// contains filtered or unexported fields
}
MessageBatcher batches protocol messages by priority.
func NewMessageBatcher ¶
func NewMessageBatcher() *MessageBatcher
NewMessageBatcher creates a new message batcher.
func (*MessageBatcher) Flush ¶
func (b *MessageBatcher) Flush() []*Message
Flush builds and returns the batched messages, clearing pending state. Returns nil if no changes are pending.
func (*MessageBatcher) FlushJSON ¶
func (b *MessageBatcher) FlushJSON() ([]byte, error)
FlushJSON returns the batch as a JSON array or single message. Returns nil if no changes are pending.
func (*MessageBatcher) IsEmpty ¶
func (b *MessageBatcher) IsEmpty() bool
IsEmpty returns true if no changes are pending.
func (*MessageBatcher) QueueProperties ¶
func (b *MessageBatcher) QueueProperties(varID int64, properties map[string]string)
QueueProperties queues multiple property changes.
func (*MessageBatcher) QueueProperty ¶
func (b *MessageBatcher) QueueProperty(varID int64, propertyName, value string)
QueueProperty queues a property change. Property name can include priority suffix (e.g., "viewdefs:high").
func (*MessageBatcher) QueueValue ¶
func (b *MessageBatcher) QueueValue(varID int64, value json.RawMessage, priority Priority)
QueueValue queues a value change with the given priority.
type MessageSender ¶
type MessageSender interface {
Send(connectionID string, msg *Message) error
Broadcast(sessionID string, msg *Message) error
}
MessageSender is an interface for sending messages to a connection.
type MessageType ¶
type MessageType string
MessageType identifies the type of protocol message.
const ( // Relayed messages (frontend <-> UI server <-> backend) MsgCreate MessageType = "create" MsgDestroy MessageType = "destroy" MsgUpdate MessageType = "update" MsgWatch MessageType = "watch" MsgUnwatch MessageType = "unwatch" // Server-response messages MsgError MessageType = "error" // UI server-handled messages (not relayed) MsgGet MessageType = "get" MsgGetObjects MessageType = "getObjects" MsgPoll MessageType = "poll" )
type ObjectData ¶
type ObjectData struct {
ID int64 `json:"obj"`
Value json.RawMessage `json:"value"`
}
ObjectData contains an object's data.
type PathVariableHandler ¶
type PathVariableHandler interface {
// HandleFrontendCreate handles a path-based variable create from frontend.
// The id is provided by the frontend (frontend-vended IDs).
// Returns the resolved value and properties.
HandleFrontendCreate(sessionID string, id int64, parentID int64, properties map[string]string) error
// HandleFrontendUpdate handles an update to a path-based variable from frontend.
// Updates the backend object via the variable's path and returns error if any.
HandleFrontendUpdate(sessionID string, varID int64, value json.RawMessage, properties map[string]string) error
}
PathVariableHandler handles frontend-created path variables.
type PendingChange ¶
type PendingChange struct {
VarID int64
Value json.RawMessage
ValuePriority Priority
HasValue bool
Properties map[string]string // property name -> value
PropPriorities map[string]Priority // property name -> priority
}
PendingChange represents a queued change for a variable.
type PendingQueuer ¶
type PendingQueuer interface {
Enqueue(connectionID string, msg *Message)
Poll(connectionID string, wait time.Duration) []*Message
}
PendingQueuer is an interface for pending message queues.
type PollMessage ¶
type PollMessage struct {
Wait string `json:"wait,omitempty"` // Duration string for long-polling
}
PollMessage represents a poll for pending responses request.
type Priority ¶
type Priority int
Priority levels for batching
func ParsePrioritySuffix ¶
ParsePrioritySuffix extracts priority from property name suffix. Returns base property name and priority. Examples: "viewdefs:high" -> ("viewdefs", PriorityHigh)
"name" -> ("name", PriorityMedium)
type Response ¶
type Response struct {
Result interface{} `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
Response wraps handler responses (primarily for error reporting).
type UpdateMessage ¶
type UpdateMessage struct {
VarID int64 `json:"varId"`
Value json.RawMessage `json:"value,omitempty"`
Properties map[string]string `json:"properties,omitempty"`
}
UpdateMessage represents an update variable request.
type VariableData ¶
type VariableData struct {
ID int64 `json:"id"`
Value json.RawMessage `json:"value,omitempty"`
Properties map[string]string `json:"properties,omitempty"`
}
VariableData contains a variable's data for get responses.
type WatchMessage ¶
type WatchMessage struct {
VarID int64 `json:"varId"`
}
WatchMessage represents a watch/unwatch request.