Repository navigation
feat: decode the binary world.tick wire - #52
Merged
Merged
Conversation
Set `Realtime.RequestBinaryWire = true` and world.tick arrives as a binary frame in roughly a fifth of the bytes, and already decoded - which is the real saving here, since OnWorldTick hands the game raw JSON text and parses none of it. Binary frames reach a new OnWorldTickFrame carrying a typed AsobiWireFrame, never OnWorldTick. Two events on purpose: re-serialising a decoded frame to fire OnWorldTick would hand back exactly the text-parsing cost the wire exists to remove. AsobiWire resolves the wire's 2-byte entity slots to entity ids, per zone, so record.Id is the same id the JSON wire gives. Null only when the add that would have established the binding was lost - a FrameSeq gap, which WorldResyncAsync repairs. Also fixes the receive loop: it UTF8-decoded every frame into a StringBuilder regardless of message type, so a binary frame became mojibake rather than an error. Binary and text now accumulate separately. session.connect keeps its exact frozen shape unless binary is requested - JsonUtility writes every field, so an optional `wire` would have put `"wire": """ on every connect frame. A second payload class avoids that. Tested against asobi's own committed fixture corpus rather than hand-rolled bytes. 143 tests pass in the .NET project.
The wire now puts a generation byte on every record (asobi#505). It advances each time a slot is rebound to a different entity, and it is what lets a client also running the datagram plane keep ONE slot table for both carriers instead of two that can disagree. Redundant if you are only on the WebSocket - that stream is ordered and reliable and frame_seq already bounds the reuse hazard - so the decoder surfaces it and nothing here depends on it yet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Set
Realtime.RequestBinaryWire = trueandworld.tickarrives as a WebSocketbinary frame in roughly a fifth of the bytes, and already decoded (asobi
ADR 0013) - which is the real saving on this SDK, since
OnWorldTickhands thegame raw JSON text and parses none of it.
Binary frames reach a new
OnWorldTickFramecarrying a typedAsobiWireFrame,never
OnWorldTick. Two separate events on purpose: re-serialising a decoded frameto fire
OnWorldTickwould hand back exactly the text-parsing cost the binary wireexists to remove.
AsobiWireresolves the wire's compact 2-byte entity slots to entity ids, perzone, so
record.Idis the same id the JSON wire gives. It is null only when theaddthat would have established the binding was lost - aFrameSeqgap, whichWorldResyncAsyncrepairs.This also fixes the receive loop. It UTF8-decoded every frame into a
StringBuilderregardless of message type, so a binary frame became mojibakerather than an error. Binary and text now accumulate separately.
session.connectkeeps its exact frozen shape unless binary is requested:JsonUtilitywrites every field, so an optionalwirewould have put"wire": ""on every connect frame. A second payload class avoids that.Tested against asobi's own committed fixture corpus (
priv/wire_fixtures) ratherthan hand-rolled bytes. 143 tests pass in the .NET project.
Needs a server with
binary_wireon. Without it,session.connectedanswersjsonand this client silently stays on text; readRealtime.WireafterOnConnectedif you need to know.