Bytes after the value: a payload is one MessagePack value (C#) (#125)
This commit is contained in:
parent
a8c2825745
commit
5e10909fe9
21 changed files with 441 additions and 30 deletions
|
|
@ -5,6 +5,10 @@ All notable changes to `@gamecult/cultnet-ts` are recorded here, following
|
|||
|
||||
## Unreleased
|
||||
|
||||
### Breaking
|
||||
|
||||
- `decodeManifest` refuses a manifest with bytes after its first MessagePack value (`CDN artifact manifest has N bytes after its first MessagePack value.`), as the C# reference does; before, the tail was ignored. `contracts/cultmesh/content-acceptance-vectors.json` now holds `trailing_nil`, `trailing_reserved_code` and `trailing_truncated_array` as refused.
|
||||
|
||||
### Added
|
||||
|
||||
- Fork card (`contracts/cultnet/governance/fork-card.md`): `raised_at`, a required key holding an RFC3339 instant string or nil (the question's first admission time), outside `options_hash`; the card vectors are re-pinned with the key, three negatives (epoch integer, date-only string, missing key) and a nil-`raised_at` valid card; every `optionsHash` digest is unchanged.
|
||||
|
|
|
|||
|
|
@ -144,8 +144,8 @@ imports no `node:` module, so a browser bundle can take it.
|
|||
past the shared depth limit are refused.
|
||||
- The decoder reads what MessagePack-CSharp reads and refuses what it refuses:
|
||||
nil in a string, tag or metadata slot is `null` and is written back as nil,
|
||||
a missing trailing slot takes the reference's default, extra slots and trailing
|
||||
bytes are skipped (a chunk reference's fifth slot is its element id, a string
|
||||
a missing trailing slot takes the reference's default, extra slots are skipped and bytes
|
||||
after the manifest's first value are refused (a chunk reference's fifth slot is its element id, a string
|
||||
or nil, `""` when absent; `packContent` writes the decimal offset as the id, as the
|
||||
reference does), a float-encoded integer is refused, and invalid UTF-8
|
||||
decodes to U+FFFD. A nil `chunks` is refused, as the reference's
|
||||
|
|
|
|||
|
|
@ -249,7 +249,7 @@ class Reader {
|
|||
export function decodeManifest(bytes: Uint8Array): CultMeshCdnArtifactManifest {
|
||||
checkPayloadDepth(bytes, "CDN artifact manifest");
|
||||
const reader = new Reader(bytes);
|
||||
// A slot the array does not reach keeps the property initialiser; a slot past the tenth is skipped. Trailing bytes are not read.
|
||||
// A slot the array does not reach keeps the property initialiser; a slot past the tenth is skipped.
|
||||
const count = reader.array("manifest");
|
||||
let index = 0;
|
||||
const slot = <T>(read: () => T, initial: T): T => index++ < count ? read() : initial;
|
||||
|
|
@ -267,6 +267,8 @@ export function decodeManifest(bytes: Uint8Array): CultMeshCdnArtifactManifest {
|
|||
[reader.string("metadata") ?? wrongType("metadata"), reader.string("metadata")] as const), []),
|
||||
};
|
||||
for (; index < count; index += 1) reader.skip();
|
||||
// A manifest is one record payload: exactly one MessagePack value, as the reference's one-value rule has it.
|
||||
if (reader.position < bytes.length) throw new Error(`CDN artifact manifest has ${bytes.length - reader.position} bytes after its first MessagePack value.`);
|
||||
validateManifest(manifest);
|
||||
return manifest;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue