Documentation
¶
Overview ¶
Package protocol defines the newline-delimited JSON wire format used over IPC.
Index ¶
- Constants
- Variables
- func Decode(line []byte) (interface{}, error)
- func Encode(w io.Writer, msg interface{}) error
- func EncodeWithDeadline(conn net.Conn, msg interface{}, timeout time.Duration) error
- func ReadFrame(br *bufio.Reader) ([]byte, error)
- type Bye
- type ConsumerInfo
- type Event
- type Hello
- type HelloAck
- type PreShutdownAck
- type PreShutdownCheck
- type Shutdown
- type SourceStatus
- type StatusQuery
- type StatusResponse
Constants ¶
View Source
const ( MsgTypeHello = "hello" MsgTypeHelloAck = "hello_ack" MsgTypeEvent = "event" MsgTypeBye = "bye" MsgTypePreShutdownCheck = "pre_shutdown_check" MsgTypePreShutdownAck = "pre_shutdown_ack" MsgTypeStatusQuery = "status_query" MsgTypeStatusResponse = "status_response" MsgTypeShutdown = "shutdown" MsgTypeSourceStatus = "source_status" )
View Source
const ( SourceStateConnecting = "connecting" SourceStateConnected = "connected" SourceStateDisconnected = "disconnected" SourceStateReconnecting = "reconnecting" )
View Source
const MaxFrameBytes = 1 << 20 // reject larger frames to bound reader buffer growth
View Source
const WriteTimeout = 5 * time.Second // bound writes against wedged peer kernel buffer
Variables ¶
View Source
var ErrFrameTooLarge = errors.New("protocol: frame exceeds MaxFrameBytes")
ErrFrameTooLarge is returned by ReadFrame when a single frame exceeds MaxFrameBytes.
Functions ¶
func EncodeWithDeadline ¶
Types ¶
type ConsumerInfo ¶
type Event ¶
type Event struct {
Type string `json:"type"`
EventType string `json:"event_type"`
EventID string `json:"event_id,omitempty"`
SourceTime string `json:"source_time,omitempty"` // ms-precision unix timestamp, stringified
Seq uint64 `json:"seq,omitempty"`
Payload json.RawMessage `json:"payload"`
}
Event: Seq is per-conn monotonic; gaps signal bus drop-oldest backpressure loss.
type Hello ¶
type HelloAck ¶
type HelloAck struct {
Type string `json:"type"`
BusVersion string `json:"bus_version"`
FirstForKey bool `json:"first_for_key"`
}
func NewHelloAck ¶
type PreShutdownAck ¶
func NewPreShutdownAck ¶
func NewPreShutdownAck(lastForKey bool) *PreShutdownAck
type PreShutdownCheck ¶
PreShutdownCheck atomically reserves the cleanup lock for EventKey.
func NewPreShutdownCheck ¶
func NewPreShutdownCheck(eventKey string) *PreShutdownCheck
type Shutdown ¶
type Shutdown struct {
Type string `json:"type"`
}
func NewShutdown ¶
func NewShutdown() *Shutdown
type SourceStatus ¶
type SourceStatus struct {
Type string `json:"type"`
Source string `json:"source"`
State string `json:"state"`
Detail string `json:"detail,omitempty"`
}
SourceStatus is best-effort: hub drops it when consumer's send channel is full.
func NewSourceStatus ¶
func NewSourceStatus(source, state, detail string) *SourceStatus
type StatusQuery ¶
type StatusQuery struct {
Type string `json:"type"`
}
func NewStatusQuery ¶
func NewStatusQuery() *StatusQuery
type StatusResponse ¶
type StatusResponse struct {
Type string `json:"type"`
PID int `json:"pid"`
UptimeSec int `json:"uptime_sec"`
ActiveConns int `json:"active_conns"`
Consumers []ConsumerInfo `json:"consumers"`
}
func NewStatusResponse ¶
func NewStatusResponse(pid int, uptimeSec int, activeConns int, consumers []ConsumerInfo) *StatusResponse
Click to show internal directories.
Click to hide internal directories.