Protocol index
The heart of the library: 683 request types and 683 response types built at
import time from a single JSON description. No protoc, no
generated Python checked into the repo.
What the index contains
{
"release": "web@5.5.1+169491",
"services": {
"bale.meet.v1.Meet": {
"StartGroupCall": {
"req": "m77108_local_3a9",
"res": "m77108_local_3aP",
"fields": [ ... ]
}
}
},
"codecs": { ... 1960 wire definitions ... },
"aliases": { ... },
"scalars": { ... }
}
| Key | Meaning |
|---|---|
release | Web build the description came from |
services | 52 services → method → request/response type ids |
codecs | 1,960 message definitions with field numbers and types |
aliases | Alternative service names seen in different bundles |
scalars | Primitive type metadata |
How a type gets built
- Topological sort. The module dependency graph is a DAG (proved with an SCC check — no cycles). Types are registered in dependency order.
- Register once.
AddSerializedFilesilently ignores a second file with the same name. Early builds stalled at depth 3 because of this; ordering fixed it. - Resolve references. Each field points at another generated type, so nested messages are real messages, not raw bytes.
5,520 typed fields, 1,960 codecs, and all 683 request/response pairs built in
about 0.08 s. Only 30 fields remain as raw
bytes — and those really are bytes in the protocol.
Inspecting the index
from balexyz import dynamic
level = dynamic.INDEX
len(level.services) # 52
len(level.all_methods()) # 683
level.method_names("bale.meet.v1.Meet") # 30 names, sorted
level.search("story") # [(service, method), ...]
level.canonical("Meet") # alias resolution
Getting message classes
Request = dynamic.request_type("bale.meet.v1.Meet", "StartGroupCall")
Response = dynamic.response_type("bale.meet.v1.Meet", "StartGroupCall")
for field in Request.DESCRIPTOR.fields:
print(field.number, field.name, field.type)
req = Request()
req.video = False
req.mode = 2
print(req.SerializeToString().hex())
Signatures
print(dynamic.describe("bale.meet.v1.Meet", "StartGroupCall"))
bale.meet.v1.Meet.StartGroupCall(peer: message, randomId: int64, video: bool,
mode: int32, invitees: list[message])
-> {groupCall: message, seq: int32}
The camelCase story
They come from the webpack AST, so groupCall, not
group_call. Everything crossing into Python is normalised: the
dicts you get from to_dict(), invoke() and every
high-level method use snake_case at all nesting levels. When you
build a payload you may use either spelling — _fill tries both.
m = dynamic.response_type("bale.meet.v1.Meet", "GenerateCallLink")()
from balexyz.dynamic import _fill
_fill(m, {"group_call": {"id": 1, "link": "x"}, "link_expiration_period": 10800})
dynamic.to_dict(m)
# {"group_call": {"id": 1, "link": "x"}, "link_expiration_period": 10800}
Rebuilding the index
When Bale ships a new web build:
python scripts/build_protocol_index.py
The script reads src/balexyz/proto/protocol.json (the upstream
description) and emits index.json plus the compact proto modules.
Then verify nothing regressed:
python -m pytest tests/ -q
bale-xyz info
A protocol index that silently drifts produces wrong field numbers, which
corrupts binary payloads in ways that look like server bugs. Pinning means a
mismatch fails loudly — as an UNIMPLEMENTED RPC.