Share hand cursors with pub/sub

Alice moves her hand over the board. Bob needs the latest cursor position, but this movement does not change a piece. Publish the position on checkers/table/cursor. The generated subscription helper selects that exact subject and decodes its schema-derived payload type. Turn and animation cues have separate stored publish definitions and typed subscriptions.

The publisher receives delivery counts. Bob receives the subject, data and number of deliveries dropped since his previous receive. The example checks that Alice's cursor arrives and the board revision remains zero. Subscribe before publishing because publications have no replay.

Each subscription has a bounded queue. A slow consumer can lose cursor updates, and the reported drop count lets it detect that loss. A subsequent cursor position can replace an old one. For a missed turn or animation cue, read the board instead of guessing which move happened.

Keep the returned subscription for later steps. The generated owner and subscription manage the plugin IDs.

Alice's cursor data is:

TRON95 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 706C61796572txt "player"
0B5C 616C696365txt "alice"
110F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
1B1C 79txt "y"
1D03 CDCCCCCCCCCC08 40f64 3.1
260F 0A 1B000000 1D00 0000map leaf, size 10: @1B → @1D
301C 78txt "x"
3203 CDCCCCCCCCCC18 40f64 6.2
3B0F 0A 30000000 3200 0000map leaf, size 10: @30 → @32
4507 12 A0040000 1100 0000 26000000 3B00 0000map branch, size 18, depth 0 (root), slots 5, 7, 10: @11 → @26 → @3B

Define the messages

The game data installs publish/checkers/table/cursor in the events definition folder:

TRON286 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0046C 706C61796572txt "player"
00B1C 78txt "x"
00D1C 79txt "y"
00F0E 15 00 0700 030000 00 04000000 0B0000 00 0D000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @B → @D
0244C 74797065txt "type"
0296C 737472696E67txt "string"
0300F 0A 24000000 2900 0000map leaf, size 10: @24 → @29
03A4C 74797065txt "type"
03F6C 6E756D626572txt "number"
0460F 0A 3A000000 3F00 0000map leaf, size 10: @3A → @3F
0504C 74797065txt "type"
0556C 6E756D626572txt "number"
05C0F 0A 50000000 5500 0000map leaf, size 10: @50 → @55
0666C 706C61796572txt "player"
06D0F 0A 66000000 3000 0000map leaf, size 10: @66 → @30
0771C 79txt "y"
0790F 0A 77000000 5C00 0000map leaf, size 10: @77 → @5C
0831C 78txt "x"
0850F 0A 83000000 4600 0000map leaf, size 10: @83 → @46
08F07 12 A0040000 6D00 0000 79000000 8500 0000map branch, size 18, depth 0 (root), slots 5, 7, 10: @6D → @79 → @85
0A1AC 70726F70657274 696573txt "properties"
0AC0F 0A A1000000 8F00 0000map leaf, size 10: @A1 → @8F
0B68C 72657175697265 64txt "required"
0BF0F 0A B6000000 0F00 0000map leaf, size 10: @B6 → @F
0C914 14 616464697469 6F6E616C50726F70 657274696573txt "additionalProperties"
0DF01bit false
0E00F 0A C9000000 DF00 0000map leaf, size 10: @C9 → @DF
0EA4C 74797065txt "type"
0EF6C 6F626A656374txt "object"
0F60F 0A EA000000 EF00 0000map leaf, size 10: @EA → @EF
10007 16 A8040000 AC00 0000 BF000000 E000 0000 F6000000map branch, size 22, depth 0 (root), slots 3, 5, 7, 10: @AC → @BF → @E0 → @F6

The SDK plugin derives the payload types and route helpers from this definition. The Events plugin validates publications before delivery, including when no subscriber is present. Invalid data reaches no subscriber. The example below imports the generated SDK.

Code

go701 B
func shareCursors(game *Game, alice, bob *events.Owner) *events.Subscription[events.CheckersTableCursorData] {
	subscription, err := events.SubscribeCheckersTableCursor(bob)
	check(game.t, err)
	cursor := events.CheckersTableCursorData{
		Player: "alice",
		X:      6.2,
		Y:      3.1,
	}
	delivered, err := events.PublishCheckersTableCursor(game.db, cursor)
	check(game.t, err)
	if delivered.Delivered != 1 || delivered.Dropped != 0 {
		game.t.Fatal("cursor delivery failed")
	}
	received, err := subscription.Receive(time.Second)
	check(game.t, err)
	if received.Data != cursor || received.Dropped != 0 || game.revision() != 0 {
		game.t.Fatal("cursor changed board state")
	}
	return subscription
}