JsonDecoderDag.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.JsonDecoderDag = exports.fromBase64Bin = void 0;
  4. const JsonDecoder_1 = require("./JsonDecoder");
  5. const util_1 = require("./util");
  6. const createFromBase64Bin_1 = require("@jsonjoy.com/base64/lib/createFromBase64Bin");
  7. exports.fromBase64Bin = (0, createFromBase64Bin_1.createFromBase64Bin)(undefined, '');
  8. class JsonDecoderDag extends JsonDecoder_1.JsonDecoder {
  9. readObj() {
  10. const bytes = this.tryReadBytes();
  11. if (bytes)
  12. return bytes;
  13. const cid = this.tryReadCid();
  14. if (cid)
  15. return cid;
  16. return super.readObj();
  17. }
  18. tryReadBytes() {
  19. const reader = this.reader;
  20. const x = reader.x;
  21. if (reader.u8() !== 0x7b) {
  22. reader.x = x;
  23. return;
  24. }
  25. this.skipWhitespace();
  26. if (reader.u8() !== 0x22 || reader.u8() !== 0x2f || reader.u8() !== 0x22) {
  27. reader.x = x;
  28. return;
  29. }
  30. this.skipWhitespace();
  31. if (reader.u8() !== 0x3a) {
  32. reader.x = x;
  33. return;
  34. }
  35. this.skipWhitespace();
  36. if (reader.u8() !== 0x7b) {
  37. reader.x = x;
  38. return;
  39. }
  40. this.skipWhitespace();
  41. if (reader.u8() !== 0x22 ||
  42. reader.u8() !== 0x62 ||
  43. reader.u8() !== 0x79 ||
  44. reader.u8() !== 0x74 ||
  45. reader.u8() !== 0x65 ||
  46. reader.u8() !== 0x73 ||
  47. reader.u8() !== 0x22) {
  48. reader.x = x;
  49. return;
  50. }
  51. this.skipWhitespace();
  52. if (reader.u8() !== 0x3a) {
  53. reader.x = x;
  54. return;
  55. }
  56. this.skipWhitespace();
  57. if (reader.u8() !== 0x22) {
  58. reader.x = x;
  59. return;
  60. }
  61. const bufStart = reader.x;
  62. const bufEnd = (0, util_1.findEndingQuote)(reader.uint8, bufStart);
  63. reader.x = 1 + bufEnd;
  64. this.skipWhitespace();
  65. if (reader.u8() !== 0x7d) {
  66. reader.x = x;
  67. return;
  68. }
  69. this.skipWhitespace();
  70. if (reader.u8() !== 0x7d) {
  71. reader.x = x;
  72. return;
  73. }
  74. const bin = (0, exports.fromBase64Bin)(reader.view, bufStart, bufEnd - bufStart);
  75. return bin;
  76. }
  77. tryReadCid() {
  78. const reader = this.reader;
  79. const x = reader.x;
  80. if (reader.u8() !== 0x7b) {
  81. reader.x = x;
  82. return;
  83. }
  84. this.skipWhitespace();
  85. if (reader.u8() !== 0x22 || reader.u8() !== 0x2f || reader.u8() !== 0x22) {
  86. reader.x = x;
  87. return;
  88. }
  89. this.skipWhitespace();
  90. if (reader.u8() !== 0x3a) {
  91. reader.x = x;
  92. return;
  93. }
  94. this.skipWhitespace();
  95. if (reader.u8() !== 0x22) {
  96. reader.x = x;
  97. return;
  98. }
  99. const bufStart = reader.x;
  100. const bufEnd = (0, util_1.findEndingQuote)(reader.uint8, bufStart);
  101. reader.x = 1 + bufEnd;
  102. this.skipWhitespace();
  103. if (reader.u8() !== 0x7d) {
  104. reader.x = x;
  105. return;
  106. }
  107. const finalX = reader.x;
  108. reader.x = bufStart;
  109. const cid = reader.ascii(bufEnd - bufStart);
  110. reader.x = finalX;
  111. return this.readCid(cid);
  112. }
  113. readCid(cid) {
  114. return cid;
  115. }
  116. }
  117. exports.JsonDecoderDag = JsonDecoderDag;
  118. //# sourceMappingURL=JsonDecoderDag.js.map