fix(proto): emit state=0 on whole-ban unmute via new pb_optional marker
set_group_whole_ban false (unmute) failed with `OIDB error 1007` while enabling worked (issue #70). OIDB (0x89A, 0) is shared by several commands (SetSearch / SetAddOption / mute-all) disambiguated by body shape. Unmute sends muteState.state=0, but proton omits zero scalars (proto3), leaving an empty `muteState` the server can't classify. Enable sends 0xFFFFFFFF, which is non-zero and survives — hence the asymmetry. Add a `pb_optional<N, T>` marker (proto3 explicit presence): a scalar so marked serialises even at its zero/default value. It is opt-in per field via a NEW `explicitPresence` flag set ONLY by this marker — never reused from the TS-`?`-derived `isOptional` (true for nearly every field). The encoder routes explicit-presence scalars to a dedicated block; every `pb<>` / `pb_repeated<>` field takes the untouched branches, so existing wire output is byte-identical (proton's 99 existing tests, incl. byte-level round-trips, stay green). Mark OidbMuteAllState.state `pb_optional<17, uint_32>` so unmute now puts field 17 (=0) on the wire. New tests: proton pb_optional encode/round-trip (incl. that sibling pb<> fields still omit zero), and a byte-level assertion that mute-all unmute carries the state field. Note: proton ships as a built Vite plugin (dist, gitignored); rebuild it (`pnpm --filter @snowluma/proton build`) for the change to reach consumers.
This commit is contained in:
9 files changed
+304
-7
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import ts from 'typescript';
|
||||
import {
|
||||
WireType,
|
||||
PB_MARKER, PB_REPEATED_MARKER,
|
||||
PB_MARKER, PB_REPEATED_MARKER, PB_OPTIONAL_MARKER,
|
||||
type ProtobufField, type ProtobufMessage,
|
||||
type GenericProtobufTemplate, type GenericFieldTemplate,
|
||||
} from './types.js';
|
||||
@@ -85,7 +85,7 @@ function parsePbTypeRef(
|
||||
// Resolve the marker name through aliased imports so `import { pb as P }`
|
||||
// / `import { pb_repeated as PR }` still match the marker constants.
|
||||
const marker = resolveImportedTypeName(t.typeName.text);
|
||||
if (marker !== PB_MARKER && marker !== PB_REPEATED_MARKER) return null;
|
||||
if (marker !== PB_MARKER && marker !== PB_REPEATED_MARKER && marker !== PB_OPTIONAL_MARKER) return null;
|
||||
const ta = t.typeArguments;
|
||||
if (!ta || ta.length !== 2) return null;
|
||||
const fnNode = ta[0];
|
||||
@@ -129,6 +129,7 @@ function extractField(
|
||||
isMessage: false, // placeholder
|
||||
isOptional: member.questionToken != null,
|
||||
isRepeated: parsed.marker === PB_REPEATED_MARKER,
|
||||
explicitPresence: parsed.marker === PB_OPTIONAL_MARKER,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -149,6 +150,7 @@ function extractGenericField(
|
||||
isTypeParam: tpSet.has(raw),
|
||||
isOptional: member.questionToken != null,
|
||||
isRepeated: parsed.marker === PB_REPEATED_MARKER,
|
||||
explicitPresence: parsed.marker === PB_OPTIONAL_MARKER,
|
||||
};
|
||||
// If the field's type-arg is itself a generic instantiation (`Wrapper<U>`,
|
||||
// where U is a type param of the enclosing template), capture the original
|
||||
|
||||
Reference in new issue
Block a user