@@ -12,7 +12,7 @@ const version_id = 'dev',
12
12
13
13
/** @summary version date
14
14
* @desc Release date in format day/month/year like '14/04/2022' */
15
- version_date = '6 /06/2025',
15
+ version_date = '16 /06/2025',
16
16
17
17
/** @summary version id and date
18
18
* @desc Produced by concatenation of {@link version_id} and {@link version_date}
@@ -175237,24 +175237,225 @@ __proto__: null,
175237
175237
TASImagePainter: TASImagePainter
175238
175238
});
175239
175239
175240
+ const LITTLE_ENDIAN = true;
175241
+ class RBufferReader {
175242
+
175243
+ constructor(buffer) {
175244
+ if (buffer instanceof ArrayBuffer) {
175245
+ this.buffer = buffer;
175246
+ this.byteOffset = 0;
175247
+ this.byteLength = buffer.byteLength;
175248
+ } else if (ArrayBuffer.isView(buffer)) {
175249
+ this.buffer = buffer.buffer;
175250
+ this.byteOffset = buffer.byteOffset;
175251
+ this.byteLength = buffer.byteLength;
175252
+ } else
175253
+ throw new TypeError('Invalid buffer type');
175254
+
175255
+ this.view = new DataView(this.buffer);
175256
+ this.offset = 0;
175257
+ }
175258
+
175259
+ // Move to a specific position in the buffer
175260
+ seek(position) {
175261
+ this.offset = position;
175262
+ }
175263
+
175264
+ // Read unsigned 8-bit integer (1 BYTE)
175265
+ readU8() {
175266
+ const val = this.view.getUint8(this.offset);
175267
+ this.offset += 1;
175268
+ return val;
175269
+ }
175270
+
175271
+ // Read unsigned 16-bit integer (2 BYTES)
175272
+ readU16() {
175273
+ const val = this.view.getUint16(this.offset, LITTLE_ENDIAN);
175274
+ this.offset += 2;
175275
+ return val;
175276
+ }
175277
+
175278
+ // Read unsigned 32-bit integer (4 BYTES)
175279
+ readU32() {
175280
+ const val = this.view.getUint32(this.offset, LITTLE_ENDIAN);
175281
+ this.offset += 4;
175282
+ return val;
175283
+ }
175284
+
175285
+ // Read signed 8-bit integer (1 BYTE)
175286
+ readS8() {
175287
+ const val = this.view.getInt8(this.offset);
175288
+ this.offset += 1;
175289
+ return val;
175290
+ }
175291
+
175292
+ // Read signed 16-bit integer (2 BYTES)
175293
+ readS16() {
175294
+ const val = this.view.getInt16(this.offset, LITTLE_ENDIAN);
175295
+ this.offset += 2;
175296
+ return val;
175297
+ }
175298
+
175299
+ // Read signed 32-bit integer (4 BYTES)
175300
+ readS32() {
175301
+ const val = this.view.getInt32(this.offset, LITTLE_ENDIAN);
175302
+ this.offset += 4;
175303
+ return val;
175304
+ }
175305
+
175306
+ // Read 32-bit float (4 BYTES)
175307
+ readF32() {
175308
+ const val = this.view.getFloat32(this.offset, LITTLE_ENDIAN);
175309
+ this.offset += 4;
175310
+ return val;
175311
+ }
175312
+
175313
+ // Read 64-bit float (8 BYTES)
175314
+ readF64() {
175315
+ const val = this.view.getFloat64(this.offset, LITTLE_ENDIAN);
175316
+ this.offset += 8;
175317
+ return val;
175318
+ }
175319
+
175320
+ // Read a string with 32-bit length prefix
175321
+ readString() {
175322
+ const length = this.readU32();
175323
+ let str = '';
175324
+ for (let i = 0; i < length; i++)
175325
+ str += String.fromCharCode(this.readU8());
175326
+ return str;
175327
+ }
175328
+
175329
+ // Read unsigned 64-bit integer (8 BYTES)
175330
+ readU64() {
175331
+ const val = this.view.getBigUint64(this.offset, LITTLE_ENDIAN);
175332
+ this.offset += 8;
175333
+ return val;
175334
+ }
175335
+
175336
+ // Read signed 64-bit integer (8 BYTES)
175337
+ readS64() {
175338
+ const val = this.view.getBigInt64(this.offset, LITTLE_ENDIAN);
175339
+ this.offset += 8;
175340
+ return val;
175341
+ }
175342
+
175343
+ }
175344
+
175345
+
175240
175346
class RNTupleDescriptorBuilder {
175347
+
175348
+ deserializeHeader(header_blob) {
175349
+ if (!header_blob) return;
175241
175350
175242
- deserializeHeader (header_blob) {
175243
- if (!header_blob)
175244
- return ;
175351
+ const reader = new RBufferReader (header_blob);
175352
+ // Read the envelope metadata
175353
+ this._readEnvelopeMetadata(reader) ;
175245
175354
175246
- this.xxhash3 = 1234;
175247
- this.featuresFlags = [];
175248
- this.name = 'rntuple';
175249
- this.description = 'description';
175250
- // this.deserializeSchemaDescription ...
175251
- }
175355
+ // TODO: Validate the envelope checksum at the end of deserialization
175356
+ // const payloadStart = reader.offset;
175252
175357
175253
- deserializeFooter(footer_blob) {
175254
- if (!footer_blob)
175255
- return;
175256
- this.xxhash3 = 1234;
175257
- }
175358
+ // Read feature flags list (may span multiple 64-bit words)
175359
+ this._readFeatureFlags(reader);
175360
+
175361
+ // Read metadata strings
175362
+ this.name = reader.readString();
175363
+ this.description = reader.readString();
175364
+ this.writer = reader.readString();
175365
+
175366
+ // List frame: list of field record frames
175367
+ this._readFieldDescriptors(reader);
175368
+ }
175369
+
175370
+ deserializeFooter(footer_blob) {
175371
+ if (!footer_blob) return;
175372
+
175373
+ const reader = new RBufferReader(footer_blob);
175374
+
175375
+ this.footerFeatureFlags = reader.readU32();
175376
+ this.headerChecksum = reader.readU32();
175377
+
175378
+ console.log('Footer Feature Flags:', this.footerFeatureFlags);
175379
+ console.log('Header Checksum:', this.headerChecksum);
175380
+ }
175381
+
175382
+
175383
+ _readEnvelopeMetadata(reader) {
175384
+ const typeAndLength = reader.readU64(),
175385
+
175386
+ // Envelope metadata
175387
+ // The 16 bits are the envelope type ID, and the 48 bits are the envelope length
175388
+ envelopeType = Number(typeAndLength & 0xFFFFn),
175389
+ envelopeLength = Number((typeAndLength >> 16n) & 0xFFFFFFFFFFFFn);
175390
+
175391
+ console.log('Envelope Type ID:', envelopeType);
175392
+ console.log('Envelope Length:', envelopeLength);
175393
+ return { envelopeType, envelopeLength };
175394
+ }
175395
+
175396
+ _readFeatureFlags(reader) {
175397
+ this.featureFlags = [];
175398
+ while (true) {
175399
+ const val = reader.readU64();
175400
+ this.featureFlags.push(val);
175401
+ if ((val & 0x8000000000000000n) === 0n) break; // MSB not set: end of list
175402
+ }
175403
+
175404
+ // verify all feature flags are zero
175405
+ if (this.featureFlags.some(v => v !== 0n))
175406
+ throw new Error('Unexpected non-zero feature flags: ' + this.featureFlags);
175407
+ }
175408
+
175409
+ _readFieldDescriptors(reader) {
175410
+ const fieldListSize = reader.readS64(), // signed 64-bit
175411
+ fieldListIsList = fieldListSize < 0;
175412
+
175413
+
175414
+ if (!fieldListIsList)
175415
+ throw new Error('Field list frame is not a list frame, which is required.');
175416
+
175417
+ const fieldListCount = reader.readU32(); // number of field entries
175418
+ console.log('Field List Count:', fieldListCount);
175419
+
175420
+ // List frame: list of field record frames
175421
+
175422
+ const fieldDescriptors = [];
175423
+ for (let i = 0; i < fieldListCount; ++i) {
175424
+ const fieldRecordSize = reader.readS64(),
175425
+ fieldVersion = reader.readU32(),
175426
+ typeVersion = reader.readU32(),
175427
+ parentFieldId = reader.readU32(),
175428
+ structRole = reader.readU16(),
175429
+ flags = reader.readU16(),
175430
+
175431
+ fieldName = reader.readString(),
175432
+ typeName = reader.readString(),
175433
+ typeAlias = reader.readString(),
175434
+ description = reader.readString();
175435
+ console.log(`Field Record Size: ${fieldRecordSize}`);
175436
+ let arraySize = null, sourceFieldId = null, checksum = null;
175437
+
175438
+ if (flags & 0x1) arraySize = reader.readU64();
175439
+ if (flags & 0x2) sourceFieldId = reader.readU32();
175440
+ if (flags & 0x4) checksum = reader.readU32();
175441
+
175442
+ fieldDescriptors.push({
175443
+ fieldVersion,
175444
+ typeVersion,
175445
+ parentFieldId,
175446
+ structRole,
175447
+ flags,
175448
+ fieldName,
175449
+ typeName,
175450
+ typeAlias,
175451
+ description,
175452
+ arraySize,
175453
+ sourceFieldId,
175454
+ checksum
175455
+ });
175456
+ }
175457
+ this.fieldDescriptors = fieldDescriptors;
175458
+ }
175258
175459
175259
175460
}
175260
175461
@@ -175321,6 +175522,7 @@ async function tupleHierarchy(tuple_node, tuple) {
175321
175522
175322
175523
var rntuple = /*#__PURE__*/Object.freeze({
175323
175524
__proto__: null,
175525
+ RBufferReader: RBufferReader,
175324
175526
readHeaderFooter: readHeaderFooter,
175325
175527
tupleHierarchy: tupleHierarchy
175326
175528
});
0 commit comments