@moqtap/trace 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +13 -7
- package/dist/index.js +7 -1
- package/package.json +2 -2
- package/src/binary.ts +15 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/binary.ts
|
|
2
2
|
var _cborx = require('cbor-x');
|
|
3
|
+
var codec = new (0, _cborx.Encoder)({ useRecords: false, mapsAsObjects: true });
|
|
4
|
+
var encode = (value) => codec.encode(value);
|
|
5
|
+
var decode = (bytes) => codec.decode(bytes);
|
|
6
|
+
var decodeMultiple = (bytes, cb) => {
|
|
7
|
+
codec.decodeMultiple(bytes, cb);
|
|
8
|
+
};
|
|
3
9
|
var MAGIC = new Uint8Array([77, 79, 81, 84, 82, 65, 67, 69]);
|
|
4
10
|
var FORMAT_VERSION = 1;
|
|
5
11
|
var PREAMBLE_SIZE = 16;
|
|
@@ -230,12 +236,12 @@ function validatePreamble(bytes) {
|
|
|
230
236
|
return { version, headerLength };
|
|
231
237
|
}
|
|
232
238
|
function writeMoqtrace(trace) {
|
|
233
|
-
const headerCbor =
|
|
239
|
+
const headerCbor = encode(headerToCbor(trace.header));
|
|
234
240
|
const preamble = writePreamble(headerCbor);
|
|
235
241
|
const eventChunks = [];
|
|
236
242
|
let totalEventBytes = 0;
|
|
237
243
|
for (const event of trace.events) {
|
|
238
|
-
const chunk =
|
|
244
|
+
const chunk = encode(eventToCbor(event));
|
|
239
245
|
eventChunks.push(chunk);
|
|
240
246
|
totalEventBytes += chunk.length;
|
|
241
247
|
}
|
|
@@ -251,11 +257,11 @@ function writeMoqtrace(trace) {
|
|
|
251
257
|
function readMoqtrace(bytes) {
|
|
252
258
|
const { headerLength } = validatePreamble(bytes);
|
|
253
259
|
const headerBytes = bytes.slice(PREAMBLE_SIZE, PREAMBLE_SIZE + headerLength);
|
|
254
|
-
const header = cborToHeader(
|
|
260
|
+
const header = cborToHeader(decode(headerBytes));
|
|
255
261
|
const eventBytes = bytes.slice(PREAMBLE_SIZE + headerLength);
|
|
256
262
|
const events = [];
|
|
257
263
|
if (eventBytes.length > 0) {
|
|
258
|
-
|
|
264
|
+
decodeMultiple(eventBytes, (obj) => {
|
|
259
265
|
events.push(cborToEvent(obj));
|
|
260
266
|
});
|
|
261
267
|
}
|
|
@@ -264,17 +270,17 @@ function readMoqtrace(bytes) {
|
|
|
264
270
|
function readMoqtraceHeader(bytes) {
|
|
265
271
|
const { headerLength } = validatePreamble(bytes);
|
|
266
272
|
const headerBytes = bytes.slice(PREAMBLE_SIZE, PREAMBLE_SIZE + headerLength);
|
|
267
|
-
return cborToHeader(
|
|
273
|
+
return cborToHeader(decode(headerBytes));
|
|
268
274
|
}
|
|
269
275
|
function createMoqtraceWriter(header) {
|
|
270
|
-
const headerCbor =
|
|
276
|
+
const headerCbor = encode(headerToCbor(header));
|
|
271
277
|
const preambleBytes = writePreamble(headerCbor);
|
|
272
278
|
return {
|
|
273
279
|
preamble() {
|
|
274
280
|
return preambleBytes;
|
|
275
281
|
},
|
|
276
282
|
writeEvent(event) {
|
|
277
|
-
return
|
|
283
|
+
return encode(eventToCbor(event));
|
|
278
284
|
}
|
|
279
285
|
};
|
|
280
286
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// src/binary.ts
|
|
2
|
-
import {
|
|
2
|
+
import { Encoder } from "cbor-x";
|
|
3
|
+
var codec = new Encoder({ useRecords: false, mapsAsObjects: true });
|
|
4
|
+
var encode = (value) => codec.encode(value);
|
|
5
|
+
var decode = (bytes) => codec.decode(bytes);
|
|
6
|
+
var decodeMultiple = (bytes, cb) => {
|
|
7
|
+
codec.decodeMultiple(bytes, cb);
|
|
8
|
+
};
|
|
3
9
|
var MAGIC = new Uint8Array([77, 79, 81, 84, 82, 65, 67, 69]);
|
|
4
10
|
var FORMAT_VERSION = 1;
|
|
5
11
|
var PREAMBLE_SIZE = 16;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moqtap/trace",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "MoQT session trace format — record, serialize, and analyze .moqtrace files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"test": "vitest run"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@moqtap/codec": "^0.
|
|
50
|
+
"@moqtap/codec": "^0.3.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"cbor-x": "^1.6.0"
|
package/src/binary.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Encoder } from 'cbor-x'
|
|
2
2
|
import type { DetailLevel, Perspective, Trace, TraceEvent, TraceHeader } from './types.js'
|
|
3
3
|
|
|
4
|
+
// Use a CBOR codec configured for cross-language interop.
|
|
5
|
+
// Why: cbor-x's default `useRecords: true` enables a proprietary "record
|
|
6
|
+
// extension" that encodes JS objects as tagged structures rather than standard
|
|
7
|
+
// CBOR maps — unreadable by ciborium (Rust) and other spec-compliant decoders.
|
|
8
|
+
// The .moqtrace spec requires standard CBOR, so we disable records and encode
|
|
9
|
+
// as plain maps. `mapsAsObjects` is set so decoded maps come back as plain
|
|
10
|
+
// JS objects (matching the code that accesses fields via `obj.protocol`).
|
|
11
|
+
const codec = new Encoder({ useRecords: false, mapsAsObjects: true })
|
|
12
|
+
const encode = (value: unknown): Uint8Array => codec.encode(value)
|
|
13
|
+
const decode = (bytes: Uint8Array): unknown => codec.decode(bytes)
|
|
14
|
+
const decodeMultiple = (bytes: Uint8Array, cb: (value: unknown) => void): void => {
|
|
15
|
+
codec.decodeMultiple(bytes, cb as (value: unknown) => boolean | undefined)
|
|
16
|
+
}
|
|
17
|
+
|
|
4
18
|
const MAGIC = new Uint8Array([0x4d, 0x4f, 0x51, 0x54, 0x52, 0x41, 0x43, 0x45]) // "MOQTRACE"
|
|
5
19
|
const FORMAT_VERSION = 1
|
|
6
20
|
const PREAMBLE_SIZE = 16 // 8 magic + 4 version + 4 header length
|