binary-sync-integrate
Add gaza-geo-sync (compact binary live-position sync with JSON fallback) to a web or Node project. Use when the user wants map/vehicle/courier/GPS positions to use less data, wants a binary position f
SKILL.md.claude/skills/binary-sync-integrate/SKILL.md
GitHubIntegrate gaza-geo-sync
Goal: live positions travel as ~7 bytes per object instead of ~45–100 bytes of JSON, without breaking any existing client. JSON stays the default; binary only when a client asks.
Source of truth: https://github.com/AQaddora/gaza-geo-sync (README, docs/MIGRATION.md,
templates/). If the repo is vendored or installed, read src/codec.ts header comment for the byte layout.
Steps
- Install. Either
npm install github:AQaddora/gaza-geo-sync(builds on install), or vendor the four filessrc/bytes.ts src/codec.ts src/sync.ts src/client.ts(+src/server.tsserver-side) into e.g.src/lib/geo-sync/. Zero runtime dependencies;server.tsneedsnode:zlib. - One shared codec. Copy
templates/geo-codec.ts. Setsouth/westto the south-west corner of the area most points fall in. With the defaultscale: 1e5andoffsetBytes: 2the cheap box is ≈0.655° per side (≈73 km N–S); larger areas →offsetBytes: 3orscale: 1e4. Points outside still work (they cost a few bytes more). Server and client must import the same file. - Stable small numbers. Each tracked object needs a small integer
nthat never changes: add an additive DB column (Postgresseq SERIAL UNIQUE, MySQLAUTO_INCREMENT, SQLite rowid). Never reuse a number for a different id. Send[n, id]pairs (index) on a first sync. - Server route. Adapt
templates/nextjs-route.ts(App Router) ortemplates/express-server.ts. UsepositionsReply(...); it negotiates onAccept, setsVary: Accept, Accept-Encoding, gzips binary only when smaller. Keep the JSON branch byte-for-byte compatible with what clients already parse — add fields, never rename. - Client. Replace the positions fetch with
fetchPositions(url, { codec, idOf })(ortemplates/use-live-positions.ts). It sendsAccept: application/octet-stream, application/json;q=0.5and always resolves to the JSON shape, so caches and screens stay unchanged. Persistpayload.indexnext to your cached records; whenunknown > 0, drop the cursor so the next request is a full sync. - Uploads (optional). For a phone sending its GPS point, use
createPointSenderortemplates/use-point-sender.tsandreadPointBodyserver-side (templates/nextjs-point-route.ts). Answer binary uploads with 204. Old servers answering 400/415 switch the sender to JSON. - Service worker. Do not cache the positions endpoint and never queue point uploads offline
(
templates/service-worker-cache.js). - Verify with the
binary-sync-verifyskill before calling it done.
Rules
- JSON fallback is not optional. curl, old app versions and debugging must keep working.
- Bump
profilein the codec options whenever any codec option changes. - Do not binary-encode text-heavy, diffed data (chat, bookings): gzip'd JSON is fine there.
- Never log decoded coordinates of real users.