opcjs-base 0.1.9 → 0.1.10

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.js CHANGED
@@ -1549,12 +1549,12 @@ var BinaryReader = class _BinaryReader {
1549
1549
  }
1550
1550
  case 1 /* Binary */: {
1551
1551
  const reader = new _BinaryReader(this.readByteString());
1552
- data = decoder.decodeWithTypeId(typeId.identifier, reader);
1552
+ data = decoder.decodeWithEncodingId(typeId.identifier, reader);
1553
1553
  break;
1554
1554
  }
1555
1555
  case 2 /* Xml */: {
1556
1556
  const reader = new XmlReader(this.readString());
1557
- data = decoder.decodeWithTypeId(typeId.identifier, reader);
1557
+ data = decoder.decodeWithEncodingId(typeId.identifier, reader);
1558
1558
  break;
1559
1559
  }
1560
1560
  }
@@ -2013,22 +2013,11 @@ var BinaryWriter = class {
2013
2013
  this.position += 8;
2014
2014
  }
2015
2015
  writeString(value) {
2016
- if (value == null) {
2017
- this.writeInt32(-1);
2018
- return;
2019
- }
2020
- const utf8Bytes = Buffer.from(value, "utf8");
2021
- const length = utf8Bytes.length;
2022
- if (length > 16777216) {
2023
- throw new CodecError(
2024
- `String length ${length} exceeds maximum allowed length of 16,777,216 bytes`,
2025
- { format: "Binary", suggestedAction: "Reduce string length" }
2026
- );
2016
+ let encoded = void 0;
2017
+ if (value && value !== "") {
2018
+ encoded = new TextEncoder().encode(value);
2027
2019
  }
2028
- this.writeInt32(length);
2029
- this.ensureCapacity(length);
2030
- utf8Bytes.copy(this.buffer, this.position);
2031
- this.position += length;
2020
+ this.writeByteString(encoded);
2032
2021
  }
2033
2022
  writeDateTime(value) {
2034
2023
  const jsTimestamp = BigInt(value.getTime());
@@ -2054,7 +2043,7 @@ var BinaryWriter = class {
2054
2043
  this.position += 16;
2055
2044
  }
2056
2045
  writeByteString(value) {
2057
- if (value == null) {
2046
+ if (!value) {
2058
2047
  this.writeInt32(-1);
2059
2048
  return;
2060
2049
  }
@@ -2065,14 +2054,8 @@ var BinaryWriter = class {
2065
2054
  { format: "Binary", suggestedAction: "Reduce ByteString length" }
2066
2055
  );
2067
2056
  }
2068
- this.writeInt32(length);
2069
- this.ensureCapacity(length);
2070
- if (Buffer.isBuffer(value)) {
2071
- value.copy(this.buffer, this.position);
2072
- } else {
2073
- this.buffer.set(value, this.position);
2074
- }
2075
- this.position += length;
2057
+ this.writeInt32(value.length);
2058
+ this.writeBytes(value);
2076
2059
  }
2077
2060
  writeXmlElement(value) {
2078
2061
  this.writeString(value);
@@ -2140,8 +2123,7 @@ var BinaryWriter = class {
2140
2123
  this.writeByte(5 /* ByteString */);
2141
2124
  this.writeUInt16(value.namespace);
2142
2125
  const ident = value.identifier;
2143
- const buf = ident instanceof Uint8Array && !(ident instanceof Buffer) ? Buffer.from(ident) : ident;
2144
- this.writeByteString(buf);
2126
+ this.writeByteString(ident);
2145
2127
  break;
2146
2128
  }
2147
2129
  default:
@@ -2453,7 +2435,7 @@ var BinaryWriter = class {
2453
2435
  }
2454
2436
  }
2455
2437
  constructor(initialSize = 1024) {
2456
- const data = Buffer.allocUnsafe(initialSize);
2438
+ const data = new Uint8Array(initialSize);
2457
2439
  this.buffer = data;
2458
2440
  this.view = new DataView(data.buffer, data.byteOffset, data.byteLength);
2459
2441
  this.position = 0;