Documentation
¶
Overview ¶
Package wire declares the Bitwire 0.2 access contract. It defines the shared boundary; dispatch, codecs and carriers belong to implementations. Paths are relative sequences of Unicode-scalar strings, without normalization or interpretation of dots, slashes or empty segments.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Endpoint ¶ added in v0.2.0
type Endpoint interface {
Wire
Receive(receiver Receiver) (detach func(), err error)
Close(code Code, reason string) error
}
Endpoint combines send access with receive attachment and lifecycle control. Receive attaches one owning receiver for every relative path. A second attachment is refused until the first is detached. Detach is idempotent and does not close the endpoint. Path dispatch and sharing among selected views belong to an explicit composition, not this primitive.
type Message ¶
type Message struct {
Frame ProfileFrame
Return *ReturnAddress `json:"-"`
}
Message preserves a frame, its local capability and associated received context through routing. Context is established and recognized by the runtime, not inferred from caller-supplied payloads or metadata. Keep the message's contents immutable after Send admits it; implementations may retain them.
type ProfileError ¶
type ProfileError struct {
Code string `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
ProfileError is public error data, without a runtime error dependency. Its fields do not prove that a failed send was never published. That local evidence, when required by value conversion, belongs to the admitting runtime.
type ProfileFrame ¶
type ProfileFrame struct {
Version int `json:"version"`
Kind ProfileKind `json:"kind"`
ID string `json:"id,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *ProfileError `json:"error,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Traceparent string `json:"traceparent,omitempty"`
Tracestate string `json:"tracestate,omitempty"`
Meta map[string]string `json:"meta,omitempty"`
}
ProfileFrame carries a profile frame. The Send path is the request method or event name; keeping it outside this value prevents contradictory names. Payloads retain their JSON representation, including numeric precision. A nil RawMessage means absent; the bytes "null" mean present JSON null. Only fields allowed for Kind may be populated, and Version must be 1. The profile implementation validates those conditions at its boundary.
type ProfileKind ¶
type ProfileKind string
ProfileKind is one of the profile's four frame kinds. Correlation and validation remain the peer's; a wire only carries the frame.
const ( ProfileRequest ProfileKind = "request" ProfileResponse ProfileKind = "response" ProfileEvent ProfileKind = "event" ProfileCancel ProfileKind = "cancel" )
type Receiver ¶
type Receiver struct {
Message func(path []string, message Message)
Closed func(code Code, reason string)
}
Receiver receives complete deliveries relative to its endpoint's origin, and an ending. The endpoint owns asynchronous dispatch. Receiver contains no routing policy; a dispatcher may interpret paths after delivery.
type ReturnAddress ¶
type ReturnAddress struct{ Wire Wire }
ReturnAddress is a local capability with stable pointer identity, even when its Wire implementation is not comparable. Routing must preserve the pointer and any runtime-owned context associated with it. It is never an envelope member. A runtime may use it to retain an event's received context without providing a callable reply or creating a response waiter.
type Wire ¶
Wire is send access to an origin. It grants neither receive attachment nor endpoint lifecycle control. Send returns when accepted or refused, without running a destination handler on the sender's stack or waiting for its result. Success means admission, not completion of an application effect.
Example ¶
package main
import (
"fmt"
wire "github.com/Bitspark/bitwire/wire/go"
)
// A consumer can provide access without receiver or lifecycle operations.
type sendOnly func([]string, wire.Message) error
func (send sendOnly) Send(path []string, message wire.Message) error {
return send(path, message)
}
var _ wire.Wire = sendOnly(nil)
func main() {
access := sendOnly(func(path []string, message wire.Message) error {
fmt.Println(path, message.Frame.Kind)
return nil
})
address := &wire.ReturnAddress{Wire: access}
_ = address.Wire.Send([]string{"result"}, wire.Message{
Frame: wire.ProfileFrame{Version: 1, Kind: wire.ProfileEvent, Data: []byte("null")},
})
}
// Compile this separate owner-side consumer without providing a fake runtime.
// Behavioral receiver ownership checks belong to implementation conformance.
func attach(endpoint wire.Endpoint, receiver wire.Receiver) (wire.Wire, func(), error) {
detach, err := endpoint.Receive(receiver)
return endpoint, detach, err
}
Output: [result] event