@omnibuf/node 0.0.7 → 0.1.1

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.
@@ -1,7 +1,7 @@
1
1
  // Code generated by protoc-gen-omnibuf-es. DO NOT EDIT.
2
- // source: peer.proto
2
+ // source: omnibuf/bench/peer.proto
3
3
  /* eslint-disable @typescript-eslint/no-unused-vars */
4
- import { Encoder, MaxNestingDepth, appendStringArrBody, appendUint32ArrBody, countSubMsgArrElems, decodeSchemaMeta, decodeUTF8, decodeVarintBigInt, decodeZigZag, defineMessage, encodeField0SchemaMeta, float32FromBits, parseArrayHeader, readBool, readFloat32, readFloat64, readFloat64At, readInt, readLenSlice, readString, readStringArr, readSubMsgArrDecoded, readSubMsgMerged, readUint, readUint32Arr, readUintAuto, roundFloat32Shortest, spliceFields, validateValue, writeField0SchemaMeta, } from '@omnibuf/core';
4
+ import { Encoder, MaxNestingDepth, appendStringArrBody, appendUint32ArrBody, countSubMsgArrElems, decodeSchemaMeta as $decodeSchemaMeta, decodeUTF8, decodeVarintBigInt, decodeZigZag32, defineMessage, encodeField0SchemaMeta, float32FromBits, parseArrayHeader, readBool, readField0SchemaMeta, readFloat32, readFloat64, readFloat64At, readInt32, readLenSlice, readString, readStringArr, readSubMsgArrDecoded, readSubMsgMerged, readUint32, readUint32Arr, readUintAuto, roundFloat32Shortest, spliceFields, validateMessage, validateValue, writeField0SchemaMeta, } from '@omnibuf/core';
5
5
  export const LocationSchema = defineMessage('omnibuf.bench.Location', {
6
6
  region: { fieldNum: 1, type: 'string' },
7
7
  datacenter: { fieldNum: 2, type: 'string' },
@@ -58,9 +58,15 @@ export function decodeLocation(buf, target, depth = 0, options, startPos = 0, en
58
58
  throw new Error(`omnibuf: nesting depth ${depth} exceeds MaxNestingDepth (${maxDepth})`);
59
59
  }
60
60
  const out = target ?? new LocationMsg();
61
- if (target !== undefined && !options?.merge) {
62
- Object.assign(out, new LocationMsg());
63
- delete out.$unknown;
61
+ if (target !== undefined) {
62
+ if (!(out instanceof LocationMsg)) {
63
+ Object.setPrototypeOf(out, LocationMsg.prototype);
64
+ }
65
+ if (!options?.merge) {
66
+ Object.assign(out, new LocationMsg());
67
+ if (Object.hasOwn(out, '$unknown'))
68
+ delete out.$unknown;
69
+ }
64
70
  }
65
71
  const n = endPos;
66
72
  let pos = startPos;
@@ -94,7 +100,7 @@ export function decodeLocation(buf, target, depth = 0, options, startPos = 0, en
94
100
  if (wt !== 12)
95
101
  throw new Error('omnibuf: invalid Field #0 wire type');
96
102
  const [meta, nextPos] = readLenSlice(buf, pos, 0, n);
97
- decodeSchemaMeta(meta, depth + 1, maxDepth);
103
+ $decodeSchemaMeta(meta, depth + 1, maxDepth);
98
104
  pos = nextPos;
99
105
  continue;
100
106
  }
@@ -393,7 +399,7 @@ export class OpaqueLocation {
393
399
  if ((this._dirtyMask & (1 << 4)) !== 0) {
394
400
  return this._rack;
395
401
  }
396
- return readUint(this._raw, 4)[0];
402
+ return readUint32(this._raw, 4)[0];
397
403
  }
398
404
  rack() {
399
405
  return this.getRack();
@@ -466,7 +472,10 @@ export class OpaqueLocation {
466
472
  });
467
473
  this._dirtyMask = 0;
468
474
  }
469
- if (options?.selfDescribing && (this._raw.length === 0 || this._raw[0] !== 0x19)) {
475
+ else {
476
+ validateMessage(this._raw);
477
+ }
478
+ if (options?.selfDescribing && !readField0SchemaMeta(this._raw)[1]) {
470
479
  const f0 = encodeField0SchemaMeta(LocationSchema.getSchemaMeta(0), Boolean(options.deterministic));
471
480
  const out = new Uint8Array(f0.length + this._raw.length);
472
481
  out.set(f0, 0);
@@ -538,9 +547,19 @@ export function decodeNeighbor(buf, target, depth = 0, options, startPos = 0, en
538
547
  throw new Error(`omnibuf: nesting depth ${depth} exceeds MaxNestingDepth (${maxDepth})`);
539
548
  }
540
549
  const out = target ?? new NeighborMsg();
541
- if (target !== undefined && !options?.merge) {
542
- Object.assign(out, new NeighborMsg());
543
- delete out.$unknown;
550
+ if (target !== undefined) {
551
+ if (!(out instanceof NeighborMsg)) {
552
+ Object.setPrototypeOf(out, NeighborMsg.prototype);
553
+ }
554
+ if (!options?.merge) {
555
+ if (Object.hasOwn(out, 'peer_asn'))
556
+ delete out.peer_asn;
557
+ if (Object.hasOwn(out, 'latency_us'))
558
+ delete out.latency_us;
559
+ Object.assign(out, new NeighborMsg());
560
+ if (Object.hasOwn(out, '$unknown'))
561
+ delete out.$unknown;
562
+ }
544
563
  }
545
564
  const n = endPos;
546
565
  let pos = startPos;
@@ -574,7 +593,7 @@ export function decodeNeighbor(buf, target, depth = 0, options, startPos = 0, en
574
593
  if (wt !== 12)
575
594
  throw new Error('omnibuf: invalid Field #0 wire type');
576
595
  const [meta, nextPos] = readLenSlice(buf, pos, 0, n);
577
- decodeSchemaMeta(meta, depth + 1, maxDepth);
596
+ $decodeSchemaMeta(meta, depth + 1, maxDepth);
578
597
  pos = nextPos;
579
598
  continue;
580
599
  }
@@ -789,7 +808,7 @@ export class OpaqueNeighbor {
789
808
  if ((this._dirtyMask & (1 << 1)) !== 0) {
790
809
  return this._peerAsn;
791
810
  }
792
- return readUint(this._raw, 1)[0];
811
+ return readUint32(this._raw, 1)[0];
793
812
  }
794
813
  peerAsn() {
795
814
  return this.getPeerAsn();
@@ -818,7 +837,7 @@ export class OpaqueNeighbor {
818
837
  if ((this._dirtyMask & (1 << 3)) !== 0) {
819
838
  return this._latencyUs;
820
839
  }
821
- return readUint(this._raw, 3)[0];
840
+ return readUint32(this._raw, 3)[0];
822
841
  }
823
842
  latencyUs() {
824
843
  return this.getLatencyUs();
@@ -871,7 +890,10 @@ export class OpaqueNeighbor {
871
890
  });
872
891
  this._dirtyMask = 0;
873
892
  }
874
- if (options?.selfDescribing && (this._raw.length === 0 || this._raw[0] !== 0x19)) {
893
+ else {
894
+ validateMessage(this._raw);
895
+ }
896
+ if (options?.selfDescribing && !readField0SchemaMeta(this._raw)[1]) {
875
897
  const f0 = encodeField0SchemaMeta(NeighborSchema.getSchemaMeta(0), Boolean(options.deterministic));
876
898
  const out = new Uint8Array(f0.length + this._raw.length);
877
899
  out.set(f0, 0);
@@ -947,7 +969,7 @@ export function encodePeerUpdate(enc, msg, options) {
947
969
  enc.writeString(2, msg.routerId ?? msg.router_id ?? '');
948
970
  enc.writeBool(3, Boolean(msg.active));
949
971
  enc.writeUint(4, msg.uptimeSec ?? msg.uptime_sec ?? 0);
950
- enc.writeInt(5, msg.rssiDbm ?? msg.rssi_dbm ?? 0);
972
+ enc.writeInt(5, Number(msg.rssiDbm ?? msg.rssi_dbm ?? 0) | 0);
951
973
  enc.writeFloat64(6, msg.cpuLoad ?? msg.cpu_load ?? 0);
952
974
  enc.writeStringArr(7, msg.tags ?? []);
953
975
  enc.writeUint32Arr(8, msg.prefixes ?? []);
@@ -964,7 +986,8 @@ export function encodePeerUpdate(enc, msg, options) {
964
986
  enc.beginSubMsgArr(10);
965
987
  for (let i = 0; i < arr.length; i++) {
966
988
  enc.beginSubMsgElem();
967
- encodeNeighbor(enc, arr[i], options);
989
+ if (arr[i] !== null && arr[i] !== undefined)
990
+ encodeNeighbor(enc, arr[i], options);
968
991
  enc.endSubMsgElem();
969
992
  }
970
993
  enc.endSubMsgArr();
@@ -992,9 +1015,23 @@ export function decodePeerUpdate(buf, target, depth = 0, options, startPos = 0,
992
1015
  throw new Error(`omnibuf: nesting depth ${depth} exceeds MaxNestingDepth (${maxDepth})`);
993
1016
  }
994
1017
  const out = target ?? new PeerUpdateMsg();
995
- if (target !== undefined && !options?.merge) {
996
- Object.assign(out, new PeerUpdateMsg());
997
- delete out.$unknown;
1018
+ if (target !== undefined) {
1019
+ if (!(out instanceof PeerUpdateMsg)) {
1020
+ Object.setPrototypeOf(out, PeerUpdateMsg.prototype);
1021
+ }
1022
+ if (!options?.merge) {
1023
+ if (Object.hasOwn(out, 'router_id'))
1024
+ delete out.router_id;
1025
+ if (Object.hasOwn(out, 'uptime_sec'))
1026
+ delete out.uptime_sec;
1027
+ if (Object.hasOwn(out, 'rssi_dbm'))
1028
+ delete out.rssi_dbm;
1029
+ if (Object.hasOwn(out, 'cpu_load'))
1030
+ delete out.cpu_load;
1031
+ Object.assign(out, new PeerUpdateMsg());
1032
+ if (Object.hasOwn(out, '$unknown'))
1033
+ delete out.$unknown;
1034
+ }
998
1035
  }
999
1036
  const n = endPos;
1000
1037
  let pos = startPos;
@@ -1028,7 +1065,7 @@ export function decodePeerUpdate(buf, target, depth = 0, options, startPos = 0,
1028
1065
  if (wt !== 12)
1029
1066
  throw new Error('omnibuf: invalid Field #0 wire type');
1030
1067
  const [meta, nextPos] = readLenSlice(buf, pos, 0, n);
1031
- decodeSchemaMeta(meta, depth + 1, maxDepth);
1068
+ $decodeSchemaMeta(meta, depth + 1, maxDepth);
1032
1069
  pos = nextPos;
1033
1070
  continue;
1034
1071
  }
@@ -1241,7 +1278,7 @@ export function decodePeerUpdate(buf, target, depth = 0, options, startPos = 0,
1241
1278
  const [v, vn] = decodeVarintBigInt(buf, pos, n);
1242
1279
  if (vn === 0)
1243
1280
  throw new Error('omnibuf: truncated int32/enum');
1244
- i32Val = decodeZigZag(v) | 0;
1281
+ i32Val = decodeZigZag32(v);
1245
1282
  pos += vn;
1246
1283
  }
1247
1284
  out.rssiDbm = i32Val;
@@ -1285,6 +1322,8 @@ export function decodePeerUpdate(buf, target, depth = 0, options, startPos = 0,
1285
1322
  break;
1286
1323
  }
1287
1324
  seenMask |= bit;
1325
+ if (depth + 1 > maxDepth)
1326
+ throw new Error(`omnibuf: nesting depth ${depth + 1} exceeds MaxNestingDepth (${maxDepth})`);
1288
1327
  if (pos >= n)
1289
1328
  throw new Error('omnibuf: invalid string array');
1290
1329
  const lb = buf[pos];
@@ -1376,6 +1415,8 @@ export function decodePeerUpdate(buf, target, depth = 0, options, startPos = 0,
1376
1415
  break;
1377
1416
  }
1378
1417
  seenMask |= bit;
1418
+ if (depth + 1 > maxDepth)
1419
+ throw new Error(`omnibuf: nesting depth ${depth + 1} exceeds MaxNestingDepth (${maxDepth})`);
1379
1420
  if (pos >= n)
1380
1421
  throw new Error('omnibuf: invalid uint32 array');
1381
1422
  const lb = buf[pos];
@@ -1521,6 +1562,8 @@ export function decodePeerUpdate(buf, target, depth = 0, options, startPos = 0,
1521
1562
  break;
1522
1563
  }
1523
1564
  seenMask |= bit;
1565
+ if (depth + 1 > maxDepth)
1566
+ throw new Error(`omnibuf: nesting depth ${depth + 1} exceeds MaxNestingDepth (${maxDepth})`);
1524
1567
  if (pos >= n)
1525
1568
  throw new Error('omnibuf: corrupt submsg array');
1526
1569
  let arrLen = 0;
@@ -1546,7 +1589,7 @@ export function decodePeerUpdate(buf, target, depth = 0, options, startPos = 0,
1546
1589
  const [el, en] = decodeVarintBigInt(arrPayload, p);
1547
1590
  p += en;
1548
1591
  const elNum = Number(el);
1549
- elems.push(decodeNeighbor(arrPayload, undefined, depth + 1, options, p, p + elNum));
1592
+ elems.push(decodeNeighbor(arrPayload, undefined, depth + 2, options, p, p + elNum));
1550
1593
  p += elNum;
1551
1594
  }
1552
1595
  out.neighbors = elems;
@@ -1593,7 +1636,7 @@ export function decodePeerUpdate(buf, target, depth = 0, options, startPos = 0,
1593
1636
  }
1594
1637
  if (p + elNum > arrEnd)
1595
1638
  throw new Error('omnibuf: corrupt submsg array');
1596
- elems.push(decodeNeighbor(buf, undefined, depth + 1, options, p, p + elNum));
1639
+ elems.push(decodeNeighbor(buf, undefined, depth + 2, options, p, p + elNum));
1597
1640
  p += elNum;
1598
1641
  }
1599
1642
  if (p !== arrEnd)
@@ -1611,7 +1654,7 @@ export function decodePeerUpdate(buf, target, depth = 0, options, startPos = 0,
1611
1654
  const [el, en] = decodeVarintBigInt(arrPayload, p);
1612
1655
  p += en;
1613
1656
  const elNum = Number(el);
1614
- elems.push(decodeNeighbor(arrPayload, undefined, depth + 1, options, p, p + elNum));
1657
+ elems.push(decodeNeighbor(arrPayload, undefined, depth + 2, options, p, p + elNum));
1615
1658
  p += elNum;
1616
1659
  }
1617
1660
  out.neighbors = elems;
@@ -1733,7 +1776,7 @@ export class OpaquePeerUpdate {
1733
1776
  if ((this._dirtyMask & (1 << 1)) !== 0) {
1734
1777
  return this._asn;
1735
1778
  }
1736
- return readUint(this._raw, 1)[0];
1779
+ return readUint32(this._raw, 1)[0];
1737
1780
  }
1738
1781
  asn() {
1739
1782
  return this.getAsn();
@@ -1791,7 +1834,7 @@ export class OpaquePeerUpdate {
1791
1834
  if ((this._dirtyMask & (1 << 5)) !== 0) {
1792
1835
  return this._rssiDbm;
1793
1836
  }
1794
- return readInt(this._raw, 5)[0];
1837
+ return readInt32(this._raw, 5)[0];
1795
1838
  }
1796
1839
  rssiDbm() {
1797
1840
  return this.getRssiDbm();
@@ -1922,7 +1965,7 @@ export class OpaquePeerUpdate {
1922
1965
  }
1923
1966
  case 5: {
1924
1967
  const msg = { rssiDbm: this._rssiDbm };
1925
- enc.writeInt(5, msg.rssiDbm ?? msg.rssi_dbm ?? 0);
1968
+ enc.writeInt(5, Number(msg.rssiDbm ?? msg.rssi_dbm ?? 0) | 0);
1926
1969
  break;
1927
1970
  }
1928
1971
  case 6: {
@@ -1959,7 +2002,8 @@ export class OpaquePeerUpdate {
1959
2002
  enc.beginSubMsgArr(10);
1960
2003
  for (let i = 0; i < arr.length; i++) {
1961
2004
  enc.beginSubMsgElem();
1962
- encodeNeighbor(enc, arr[i], options);
2005
+ if (arr[i] !== null && arr[i] !== undefined)
2006
+ encodeNeighbor(enc, arr[i], options);
1963
2007
  enc.endSubMsgElem();
1964
2008
  }
1965
2009
  enc.endSubMsgArr();
@@ -1975,7 +2019,10 @@ export class OpaquePeerUpdate {
1975
2019
  });
1976
2020
  this._dirtyMask = 0;
1977
2021
  }
1978
- if (options?.selfDescribing && (this._raw.length === 0 || this._raw[0] !== 0x19)) {
2022
+ else {
2023
+ validateMessage(this._raw);
2024
+ }
2025
+ if (options?.selfDescribing && !readField0SchemaMeta(this._raw)[1]) {
1979
2026
  const f0 = encodeField0SchemaMeta(PeerUpdateSchema.getSchemaMeta(0), Boolean(options.deterministic));
1980
2027
  const out = new Uint8Array(f0.length + this._raw.length);
1981
2028
  out.set(f0, 0);