CodeSampleX

Beispiel

compact-encoding 3.3.2: c.decode

Verifiziertes Beispiel für npm compact-encoding 3.3.2: c.decode. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:030633ff9dd643d7b4695e7a30029f83ed272e85a4fac49547f58c2f3c2ce32b

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-02

Fall

HOW
Ziel
verify c.decode in pkg:npm/compact-encoding@3.3.2
Pakete
Symbole
  • c.decode
Umgebung
node 22.23.2
Erstellt
2026-09-02T15:21:41Z

Contract

  1. c.decode is exported as a function
  2. c.decode decodes UTF-8 strings from binary buffers
  3. c.decode decodes compact variable-length unsigned integers
  4. c.decode decodes fixed-size integers and signed integers
  5. c.decode decodes boolean values
  6. c.decode decodes arrays using composite array codecs
  7. c.decode decodes JSON objects from binary buffers
  8. c.decode decodes prefixed and raw binary buffers
  9. c.decode decodes structured custom records with multi-field codecs
  10. c.decode decodes from Uint8Array instances
  11. c.decode throws an out of bounds error when buffer length is insufficient

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify c.decode in pkg:npm/compact-encoding@3.3.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/compact-encoding@3.3.2
Demonstrate these symbols/APIs:
  - c.decode

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:59a97621c25985b0ca1eb0fe44e0c174e83b1da6227cb53f28769f9a2082a93e","contract":["c.decode is exported as a function","c.decode decodes UTF-8 strings from binary buffers","c.decode decodes compact variable-length unsigned integers","c.decode decodes fixed-size integers and signed integers","c.decode decodes boolean values","c.decode decodes arrays using composite array codecs","c.decode decodes JSON objects from binary buffers","c.decode decodes prefixed and raw binary buffers","c.decode decodes structured custom records with multi-field codecs","c.decode decodes from Uint8Array instances","c.decode throws an out of bounds error when buffer length is insufficient"],"goal":"verify c.decode in pkg:npm/compact-encoding@3.3.2","kind":"HOW","packages":["pkg:npm/compact-encoding@3.3.2"],"schemaVersion":1,"symbols":["c.decode"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/compact-encoding@3.3.2"],"schemaVersion":1,"subject":"pkg:npm/compact-encoding@3.3.2","symbols":["c.decode"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-compact-encoding",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-compact-encoding",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "compact-encoding": "3.3.2"
      }
    },
    "node_modules/b4a": {
      "version": "1.8.1",
      "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.8.1.tgz",
      "integrity": "sha512-aiqre1Nr0B/6DgE2N5vwTc+2/oQZ4Wh1t4NznYY4E00y8LCt6NqdRv81so00oo27D8MVKTpUa/MwUUtBLXCoDw==",
      "license": "Apache-2.0",
      "peerDependencies": {
        "react-native-b4a": "*"
      },
      "peerDependenciesMeta": {
        "react-native-b4a": {
          "optional": true
        }
      }
    },
    "node_modules/compact-encoding": {
      "version": "3.3.2",
      "resolved": "https://registry.npmjs.org/compact-encoding/-/compact-encoding-3.3.2.tgz",
      "integrity": "sha512-bgZ84oVSzjQmVHXBYWON+wQUkdVflrr8fM5+0X6UwQHZyzolsGIkdsjNK3vLLn22dhdASGFz5mS6Lf7rfrPdlg==",
      "license": "Apache-2.0",
      "dependencies": {
        "b4a": "^1.3.0"
      }
    }
  }
}
package.json
{
  "name": "sample-compact-encoding",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of compact-encoding",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "compact-encoding": "3.3.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify c.decode in pkg:npm/compact-encoding@3.3.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/compact-encoding@3.3.2"
  ],
  "symbols": [
    "c.decode"
  ]
}
src/index.js
'use strict';

const c = require('compact-encoding');

/**
 * Decode a binary buffer using compact-encoding.
 * @param {object} encoding - compact-encoding codec
 * @param {Buffer|Uint8Array} buffer - binary buffer to decode
 * @returns {*} decoded value
 */
function decode(encoding, buffer) {
  return c.decode(encoding, buffer);
}

/**
 * Encode a value into a binary buffer using compact-encoding.
 * @param {object} encoding - compact-encoding codec
 * @param {*} value - value to encode
 * @returns {Buffer|Uint8Array} encoded buffer
 */
function encode(encoding, value) {
  return c.encode(encoding, value);
}

module.exports = {
  c,
  compactEncoding: c,
  decode,
  encode,
  state: c.state,
  string: c.string,
  uint: c.uint,
  uint8: c.uint8,
  uint16: c.uint16,
  uint32: c.uint32,
  int: c.int,
  int8: c.int8,
  bool: c.bool,
  buffer: c.buffer,
  raw: c.raw,
  json: c.json,
  array: c.array,
  frame: c.frame
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  c,
  decode,
  encode,
  state,
  string,
  uint,
  uint8,
  uint16,
  uint32,
  int,
  int8,
  bool,
  buffer,
  raw,
  json,
  array,
  frame
} = require('../src/index.js');

// 1. Export verification
assert.equal(typeof c.decode, 'function', 'c.decode must be exported as a function');
assert.equal(typeof decode, 'function', 'decode wrapper must be exported as a function');
assert.equal(typeof encode, 'function', 'encode wrapper must be exported as a function');
assert.equal(typeof state, 'function', 'state helper must be exported as a function');

// 2. c.decode decodes UTF-8 strings from binary buffers
{
  const expected = 'compact encoding verification';
  const encoded = encode(string, expected);
  const result = decode(string, encoded);
  assert.equal(result, expected);
}

// 3. c.decode decodes compact variable-length unsigned integers
{
  const testValues = [0, 42, 252, 253, 65535, 65536, 4294967295];
  for (const val of testValues) {
    const encoded = encode(uint, val);
    const result = decode(uint, encoded);
    assert.equal(result, val);
  }
}

// 4. c.decode decodes fixed-size integers and signed integers
{
  assert.equal(decode(uint8, encode(uint8, 255)), 255);
  assert.equal(decode(uint16, encode(uint16, 60000)), 60000);
  assert.equal(decode(uint32, encode(uint32, 3000000000)), 3000000000);
  assert.equal(decode(int8, encode(int8, -128)), -128);
  assert.equal(decode(int, encode(int, -50000)), -50000);
}

// 5. c.decode decodes boolean values
{
  assert.equal(decode(bool, encode(bool, true)), true);
  assert.equal(decode(bool, encode(bool, false)), false);
}

// 6. c.decode decodes arrays using composite array codecs
{
  const list = ['first', 'second', 'third'];
  const listCodec = array(string);
  const encoded = encode(listCodec, list);
  const result = decode(listCodec, encoded);
  assert.deepEqual(result, list);
}

// 7. c.decode decodes JSON objects from binary buffers
{
  const payload = { id: 101, tags: ['alpha', 'beta'], active: true };
  const encoded = encode(json, payload);
  const result = decode(json, encoded);
  assert.deepEqual(result, payload);
}

// 8. c.decode decodes prefixed and raw binary buffers
{
  const sampleData = Buffer.from([0xaa, 0xbb, 0xcc, 0xdd]);
  const encodedPrefixed = encode(buffer, sampleData);
  const decodedPrefixed = decode(buffer, encodedPrefixed);
  assert.deepEqual(decodedPrefixed, sampleData);

  const encodedRaw = encode(raw, sampleData);
  const decodedRaw = decode(raw, encodedRaw);
  assert.deepEqual(decodedRaw, sampleData);
}

// 9. c.decode decodes structured custom records with multi-field codecs
{
  const recordCodec = {
    preencode(stateObj, rec) {
      string.preencode(stateObj, rec.title);
      uint.preencode(stateObj, rec.count);
      bool.preencode(stateObj, rec.verified);
    },
    encode(stateObj, rec) {
      string.encode(stateObj, rec.title);
      uint.encode(stateObj, rec.count);
      bool.encode(stateObj, rec.verified);
    },
    decode(stateObj) {
      return {
        title: string.decode(stateObj),
        count: uint.decode(stateObj),
        verified: bool.decode(stateObj)
      };
    }
  };

  const record = { title: 'Sample Spec', count: 42, verified: true };
  const encoded = encode(recordCodec, record);
  const result = decode(recordCodec, encoded);
  assert.deepEqual(result, record);
}

// 10. c.decode decodes from Uint8Array instances
{
  const text = 'typed array payload';
  const encodedBuf = encode(string, text);
  const uint8View = new Uint8Array(encodedBuf.buffer, encodedBuf.byteOffset, encodedBuf.byteLength);
  const result = decode(string, uint8View);
  assert.equal(result, text);
}

// 11. c.decode throws an out of bounds error when buffer length is insufficient
{
  const truncatedBuffer = Buffer.alloc(1);
  assert.throws(
    () => decode(uint32, truncatedBuffer),
    /Out of bounds/
  );
}

console.log('Contract assertions passed.');

Ursprungs-Seeder

anonym