샘플
engine.io-parser 5.2.3: decodePacket, decodePayload, encodePacket
검증된 샘플 — npm engine.io-parser 5.2.3: decodePacket, decodePayload, encodePacket. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:fae47bc0b0be1b881d725ebd2ad5469d4585110fb473dbc81052d0d70ed0cb79
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-27 |
케이스
HOW- 목표
- verify pkg:npm/engine.io-parser@5.2.3
- 심벌
-
- decodePacket
- decodePayload
- encodePacket
- encodePayload
- 환경
- node 22.23.2
- 생성일
- 2026-08-27T14:20:25Z
컨트랙트
- encodePacket encodes text packets with numeric type prefixes
- encodePacket encodes binary payloads as raw Buffer when supportsBinary is true, and as base64 string with 'b' prefix when false
- decodePacket decodes string packets into packet objects with type and payload data, returning error packet on invalid type
- decodePacket decodes base64 string packets and raw binary Buffers into message packets with binary data
- encodePayload bundles multiple packets into a record-separator delimited string, forcing base64 for binary packets
- decodePayload parses record-separator delimited payload strings into an array of decoded packet objects
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
소스
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 pkg:npm/engine.io-parser@5.2.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/engine.io-parser@5.2.3
Demonstrate these symbols/APIs:
- decodePacket
- decodePayload
- encodePacket
- encodePayload
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.
{"case":{"caseId":"case:sha256:3deb95755df4e195f4d9ec571fa67d991069a1eb7663bf110a5c7c3fe15e7de0","contract":["encodePacket encodes text packets with numeric type prefixes","encodePacket encodes binary payloads as raw Buffer when supportsBinary is true, and as base64 string with 'b' prefix when false","decodePacket decodes string packets into packet objects with type and payload data, returning error packet on invalid type","decodePacket decodes base64 string packets and raw binary Buffers into message packets with binary data","encodePayload bundles multiple packets into a record-separator delimited string, forcing base64 for binary packets","decodePayload parses record-separator delimited payload strings into an array of decoded packet objects"],"goal":"verify pkg:npm/engine.io-parser@5.2.3","kind":"HOW","packages":["pkg:npm/engine.io-parser@5.2.3"],"schemaVersion":1,"symbols":["decodePacket","decodePayload","encodePacket","encodePayload"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/engine.io-parser@5.2.3"],"schemaVersion":1,"subject":"pkg:npm/engine.io-parser@5.2.3","symbols":["decodePacket","decodePayload","encodePacket","encodePayload"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-engine-io-parser",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-engine-io-parser",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"engine.io-parser": "5.2.3"
}
},
"node_modules/engine.io-parser": {
"version": "5.2.3",
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz",
"integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
}
}
}
}
{
"name": "sample-engine-io-parser",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification sample for engine.io-parser",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"engine.io-parser": "5.2.3"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/engine.io-parser@5.2.3",
"kind": "HOW",
"packages": [
"pkg:npm/engine.io-parser@5.2.3"
],
"symbols": [
"decodePacket",
"decodePayload",
"encodePacket",
"encodePayload"
]
}
const {
protocol,
encodePacket,
decodePacket,
encodePayload,
decodePayload,
} = require('engine.io-parser');
/**
* Encodes a single packet asynchronously using a Promise wrapper.
* @param {{ type: string, data?: any }} packet
* @param {boolean} [supportsBinary=true]
* @returns {Promise<string | Buffer | ArrayBuffer>}
*/
function encodePacketAsync(packet, supportsBinary = true) {
return new Promise((resolve) => {
encodePacket(packet, supportsBinary, (encoded) => {
resolve(encoded);
});
});
}
/**
* Encodes an array of packets into a single payload string asynchronously.
* @param {Array<{ type: string, data?: any }>} packets
* @returns {Promise<string>}
*/
function encodePayloadAsync(packets) {
return new Promise((resolve) => {
encodePayload(packets, (encoded) => {
resolve(encoded);
});
});
}
/**
* Decodes a single encoded packet string or buffer.
* @param {string | Buffer | ArrayBuffer} encodedPacket
* @param {string} [binaryType]
* @returns {{ type: string, data?: any }}
*/
function parsePacket(encodedPacket, binaryType) {
return decodePacket(encodedPacket, binaryType);
}
/**
* Decodes a payload string into an array of packet objects.
* @param {string} encodedPayload
* @param {string} [binaryType]
* @returns {Array<{ type: string, data?: any }>}
*/
function parsePayload(encodedPayload, binaryType) {
return decodePayload(encodedPayload, binaryType);
}
module.exports = {
protocol,
encodePacket,
decodePacket,
encodePayload,
decodePayload,
encodePacketAsync,
encodePayloadAsync,
parsePacket,
parsePayload,
};
const assert = require('node:assert');
const {
protocol,
encodePacket,
decodePacket,
encodePayload,
decodePayload,
encodePacketAsync,
encodePayloadAsync,
parsePacket,
parsePayload,
} = require('../src/index.js');
async function runContractTests() {
// Protocol check
assert.strictEqual(protocol, 4, 'Engine.IO protocol version must be 4');
// Contract 1: encodePacket encodes text packets with numeric type prefixes
const textCases = [
{ type: 'open', data: '{"sid":"abc","upgrades":[],"pingInterval":25000,"pingTimeout":20000}', prefix: '0' },
{ type: 'close', data: undefined, prefix: '1' },
{ type: 'ping', data: 'probe', prefix: '2' },
{ type: 'pong', data: 'probe', prefix: '3' },
{ type: 'message', data: 'hello CodeSampleX', prefix: '4' },
{ type: 'upgrade', data: undefined, prefix: '5' },
{ type: 'noop', data: undefined, prefix: '6' },
];
for (const item of textCases) {
const packet = item.data !== undefined ? { type: item.type, data: item.data } : { type: item.type };
const encoded = await encodePacketAsync(packet, true);
assert.strictEqual(typeof encoded, 'string');
assert.strictEqual(encoded.charAt(0), item.prefix, `Packet type ${item.type} should have prefix ${item.prefix}`);
if (item.data !== undefined) {
assert.strictEqual(encoded.substring(1), item.data);
}
}
// Contract 2: encodePacket encodes binary payloads as raw Buffer when supportsBinary is true, and as base64 string with 'b' prefix when false
const binaryBuffer = Buffer.from([10, 20, 30, 40, 50]);
const encodedRaw = await encodePacketAsync({ type: 'message', data: binaryBuffer }, true);
assert(Buffer.isBuffer(encodedRaw) || encodedRaw instanceof Uint8Array, 'Binary with supportsBinary=true should return buffer');
assert.deepStrictEqual(Buffer.from(encodedRaw), binaryBuffer);
const encodedBase64 = await encodePacketAsync({ type: 'message', data: binaryBuffer }, false);
assert.strictEqual(typeof encodedBase64, 'string');
assert.strictEqual(encodedBase64.charAt(0), 'b', 'Base64 binary packet must start with prefix "b"');
assert.strictEqual(encodedBase64.substring(1), binaryBuffer.toString('base64'));
// Contract 3: decodePacket decodes string packets into packet objects with type and payload data, returning error packet on invalid type
const decodedOpen = parsePacket('0{"sid":"xyz"}');
assert.deepStrictEqual(decodedOpen, { type: 'open', data: '{"sid":"xyz"}' });
const decodedClose = parsePacket('1');
assert.deepStrictEqual(decodedClose, { type: 'close' });
const decodedPing = parsePacket('2probe');
assert.deepStrictEqual(decodedPing, { type: 'ping', data: 'probe' });
const decodedPong = parsePacket('3probe');
assert.deepStrictEqual(decodedPong, { type: 'pong', data: 'probe' });
const decodedMessage = parsePacket('4test message');
assert.deepStrictEqual(decodedMessage, { type: 'message', data: 'test message' });
const decodedUpgrade = parsePacket('5');
assert.deepStrictEqual(decodedUpgrade, { type: 'upgrade' });
const decodedNoop = parsePacket('6');
assert.deepStrictEqual(decodedNoop, { type: 'noop' });
const decodedInvalid = parsePacket('9invalid_packet');
assert.deepStrictEqual(decodedInvalid, { type: 'error', data: 'parser error' });
// Contract 4: decodePacket decodes base64 string packets and raw binary Buffers into message packets with binary data
const base64Packet = 'b' + binaryBuffer.toString('base64');
const decodedFromBase64 = parsePacket(base64Packet, 'nodebuffer');
assert.strictEqual(decodedFromBase64.type, 'message');
assert.deepStrictEqual(Buffer.from(decodedFromBase64.data), binaryBuffer);
const decodedFromRaw = parsePacket(binaryBuffer, 'nodebuffer');
assert.strictEqual(decodedFromRaw.type, 'message');
assert.deepStrictEqual(Buffer.from(decodedFromRaw.data), binaryBuffer);
// Contract 5: encodePayload bundles multiple packets into a record-separator delimited string, forcing base64 for binary packets
const payloadPackets = [
{ type: 'ping', data: 'probe' },
{ type: 'message', data: 'hello' },
{ type: 'message', data: binaryBuffer },
];
const encodedPayload = await encodePayloadAsync(payloadPackets);
assert.strictEqual(typeof encodedPayload, 'string');
const separator = String.fromCharCode(30);
const parts = encodedPayload.split(separator);
assert.strictEqual(parts.length, 3);
assert.strictEqual(parts[0], '2probe');
assert.strictEqual(parts[1], '4hello');
assert.strictEqual(parts[2], 'b' + binaryBuffer.toString('base64'));
// Contract 6: decodePayload parses record-separator delimited payload strings into an array of decoded packet objects
const decodedPayloadList = parsePayload(encodedPayload, 'nodebuffer');
assert.strictEqual(decodedPayloadList.length, 3);
assert.deepStrictEqual(decodedPayloadList[0], { type: 'ping', data: 'probe' });
assert.deepStrictEqual(decodedPayloadList[1], { type: 'message', data: 'hello' });
assert.strictEqual(decodedPayloadList[2].type, 'message');
assert.deepStrictEqual(Buffer.from(decodedPayloadList[2].data), binaryBuffer);
console.log('All contract assertions passed successfully.');
}
runContractTests().catch((err) => {
console.error('Contract test failure:', err);
process.exit(1);
});
오리진 시더
익명