@leofcoin/codec-format-interface 1.2.8 → 1.3.0
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 +10 -5
- package/dist/module.js +4836 -0
- package/package.json +2 -3
- package/rollup.config.js +12 -0
- package/src/codec-format-interface.js +10 -4
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ var bs58 = require('@vandeurenglenn/base58');
|
|
|
7
7
|
var isHex = require('@vandeurenglenn/is-hex');
|
|
8
8
|
var varint = require('varint');
|
|
9
9
|
var createKeccakHash = require('keccak');
|
|
10
|
-
var protons = require('protons');
|
|
11
10
|
|
|
12
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
12
|
|
|
@@ -16,7 +15,6 @@ var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
|
16
15
|
var isHex__default = /*#__PURE__*/_interopDefaultLegacy(isHex);
|
|
17
16
|
var varint__default = /*#__PURE__*/_interopDefaultLegacy(varint);
|
|
18
17
|
var createKeccakHash__default = /*#__PURE__*/_interopDefaultLegacy(createKeccakHash);
|
|
19
|
-
var protons__default = /*#__PURE__*/_interopDefaultLegacy(protons);
|
|
20
18
|
|
|
21
19
|
class BasicInterface$1 {
|
|
22
20
|
handleDecode() {
|
|
@@ -443,11 +441,13 @@ class CodecHash$1 extends BasicInterface$1 {
|
|
|
443
441
|
class FormatInterface$1 extends BasicInterface$1 {
|
|
444
442
|
|
|
445
443
|
async protoEncode(data) {
|
|
446
|
-
|
|
444
|
+
// check schema
|
|
445
|
+
return new TextEncoder().encode(data)
|
|
447
446
|
}
|
|
448
447
|
|
|
449
448
|
async protoDecode(data) {
|
|
450
|
-
|
|
449
|
+
// check schema
|
|
450
|
+
return new TextDecoder().decode(data)
|
|
451
451
|
}
|
|
452
452
|
|
|
453
453
|
async init(buffer) {
|
|
@@ -503,6 +503,11 @@ class FormatInterface$1 extends BasicInterface$1 {
|
|
|
503
503
|
encoded = encoded.slice(discoCodec.codecBuffer.length);
|
|
504
504
|
this.name = discoCodec.name;
|
|
505
505
|
this.decoded = await this.protoDecode(encoded);
|
|
506
|
+
try {
|
|
507
|
+
this.decoded = JSON.parse(this.decoded);
|
|
508
|
+
} catch {
|
|
509
|
+
|
|
510
|
+
}
|
|
506
511
|
return this.decoded
|
|
507
512
|
}
|
|
508
513
|
|
|
@@ -512,7 +517,7 @@ class FormatInterface$1 extends BasicInterface$1 {
|
|
|
512
517
|
async encode(decoded) {
|
|
513
518
|
if (!decoded) decoded = this.decoded;
|
|
514
519
|
const codec = new PeernetCodec(this.name);
|
|
515
|
-
const encoded = await this.protoEncode(decoded);
|
|
520
|
+
const encoded = await this.protoEncode(typeof decoded === 'object' ? JSON.stringify(decoded) : decoded);
|
|
516
521
|
const uint8Array = new Uint8Array(encoded.length + codec.codecBuffer.length);
|
|
517
522
|
uint8Array.set(codec.codecBuffer);
|
|
518
523
|
uint8Array.set(encoded, codec.codecBuffer.length);
|