diff --git a/go/buscalls/buscalls.go b/go/buscalls/buscalls.go index 44e007d4..e24f5613 100644 --- a/go/buscalls/buscalls.go +++ b/go/buscalls/buscalls.go @@ -31,6 +31,8 @@ const ( StreamRead = "mesh/stream.read" StreamFill = "mesh/stream.fill" + // StreamPublish says one event on the module's own bound stream (A-42). + StreamPublish = "mesh/stream.publish" WorkQueueSize = "mesh/workqueue.size" WorkQueueDead = "mesh/workqueue.dead" @@ -153,6 +155,20 @@ type StreamPage struct { Last uint64 `json:"last"` } +// StreamPublishRequest says one event on a module's own stream, by the stream's local name: the tool runner publishes +// Body on the binding's subject plus "." plus Event, acknowledged, with ID as the message id (design 42 zfs-owns-zfs, A-42). +type StreamPublishRequest struct { + Stream string `json:"stream"` + Event string `json:"event"` + Body json.RawMessage `json:"body"` + ID string `json:"id,omitempty"` +} + +// StreamPublished is publish's answer: the sequence the stream acknowledged the event at. +type StreamPublished struct { + Sequence uint64 `json:"sequence"` +} + // StreamFilled is fill's answer: the stream's fill and its first and last sequence. type StreamFilled struct { Fill diff --git a/go/buscalls/buscalls_test.go b/go/buscalls/buscalls_test.go new file mode 100644 index 00000000..01cf18d4 --- /dev/null +++ b/go/buscalls/buscalls_test.go @@ -0,0 +1,21 @@ +package buscalls + +import ( + "encoding/json" + "testing" +) + +// A-42: stream.publish is a method of its own, beside read and fill, and its request and answer keep their field names. +func TestStreamPublishIsAMethodWithItsShapes(t *testing.T) { + if StreamPublish != "mesh/stream.publish" || StreamPublish == StreamRead || StreamPublish == StreamFill { + t.Fatalf("method %q", StreamPublish) + } + b, _ := json.Marshal(StreamPublishRequest{Stream: "events", Event: "scrub.requested", Body: json.RawMessage(`{"a":1}`), ID: "x"}) + if string(b) != `{"stream":"events","event":"scrub.requested","body":{"a":1},"id":"x"}` { + t.Errorf("request %s", b) + } + a, _ := json.Marshal(StreamPublished{Sequence: 7}) + if string(a) != `{"sequence":7}` { + t.Errorf("answer %s", a) + } +}