encoding: case names as an encoding of Flags #47
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
["Read", "Write"]instead of3, as an option of the format. Needs a way for anEncodeimplementation to ask its format for an option.Source
Acceptance criteria
Encode/Decodeinstd/encodingFlagsencodes as names when the option is setstd/jsonandstd/yamlDependencies
None known.
Moved from the planning lists of the docs; the design record stays the specification.
[loop:torbscript] intake: in scope (author orion, label loop). FLAGS.md section 6 names the gap; the format-option mechanism for
Encode/Decodeinstd/encodingis new public std surface, so refine will likely need an owner decision, and it may touch ENCODING.md decisions (see the decoder-state decision on #95). No duplicate found. next: refine (ready buffer is 6, so not before it drops below 2).[loop:torbscript] refine: still queued behind the intake order. next: waiting (ready buffer full: #4, #163, #164, #223 are ready) until 2026-10-10T04:00:00Z
[loop:torbscript] claim refine by session:loop-torbscript-20261023 until 2026-10-23T01:33:19Z
[loop:torbscript] decided by the loop: (1) Mechanism:
EncoderandDecoderget one defaulted query each,flagsAsNames(): Boolreturningfalse, exactly like the existingEncoder.writesPrivateFields(lib.trb, docs/design/ENCODING.md section 15 point 3: a convention is an option of the format, not a question a type asks). No new trait, no generic member, no change to the seven-plus-four vocabulary. (2) Option nameflagsAsNames: Bool = falseonJson,Yaml(and any other format later), next tonamingandstrict. The default stays the number, so no published contract breaks. (3) Wire form with the option: asequenceof the case names, written by the case ownEncode(variant), in bit order; decoding reads the sequence through the case ownDecode, ORs the bits, and an unknown name is aDecodeError. This needs no case-name reflection and noShowcoupling. With the option set, only the names are read (no number/name guessing; the decoder has no look-ahead). (4)Flagsgets a hand-writtenEncode/Decodepair that asks the target and otherwise keeps the capsule route (encodeThrough/decodeThroughChecked). Where it lives (std/collections vs std/encoding) depends on the package dependency direction; the implementer picks the one that adds no cycle. Why: smallest surface that matches FLAGS.md section 6 and an existing precedent; all internal std design, no owner category applies.[loop:torbscript] refine: ready. Goal:
Flags<Case>can be written and read as the list of its case names instead of its mask, chosen by an option of the format (FLAGS.md section 6, ENCODING.md section 15 point 3). Acceptance criteria: (a)EncoderandDecoderhaveflagsAsNames(): Bool, defaultfalse, documented; (b)Json(flagsAsNames: true).encode(access)gives["Read","Write"]andJson().encode(access)still gives3; (c)Json(flagsAsNames: true).decode<Flags<Permission>>round-trips, an unknown name and a non-list are aDecodeErrorwith the field chain; (d) the same two tests forstd/yaml; (e)Valuesand other formats stay unchanged (default false); (f) FLAGS.md section 3/6 and the json/yaml docs updated, section 6 entry removed, slice table row 2 no longer says "left"; ENCODING.md gets the option in its option list. Design record point: FLAGS.md section 6 "Open", ENCODING.md section 15 point 3. Seed: no (no syntax, native, driver flag or string-looked-up std name); if the compiler capsule derivation turns out to need a change for a hand-writtenEncodeonFlags, that is a stage-0 matter to note in the PR, not a seed refresh. Size: one PR, two commits:feat(encoding): flagsAsNames query on Encoder and Decoder(+ json/yaml option and tests),feat(collections): Flags encodes as case namesor one commit if small. Token usage of this refine: ~45k. next: implement[loop:torbscript] claim implement by session:loop-torbscript-20261023 until 2026-10-23T05:43:16Z
[loop:torbscript] implement: PR #402 is open and CI is green (gates, tier A/B, registry, playground, same-C).
Encoder/Decoderget a defaultedflagsAsNames();Json(flagsAsNames: true)andYaml(flagsAsNames: true)write aFlagsas the list of its case names (lowest bit first) and read it back through each case's owndecode; the default stays the mask as a number. Tests in std/json and std/yaml, docs and FLAGS.md/ENCODING.md updated;DescribeforFlagsis unchanged (still the number); no seed change. The first push had a parse error (bits().encode target), fixed in the second commit. Tokens: not metered in this session (no usage figure available to me). next: review