gs1_wasm.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import * as wasm from './gs1_wasm_bg.wasm';
  2. let WASM_VECTOR_LEN = 0;
  3. let cachegetUint8Memory0 = null;
  4. function getUint8Memory0() {
  5. if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
  6. cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
  7. }
  8. return cachegetUint8Memory0;
  9. }
  10. let cachedTextEncoder = new TextEncoder('utf-8');
  11. const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
  12. ? function (arg, view) {
  13. return cachedTextEncoder.encodeInto(arg, view);
  14. }
  15. : function (arg, view) {
  16. const buf = cachedTextEncoder.encode(arg);
  17. view.set(buf);
  18. return {
  19. read: arg.length,
  20. written: buf.length
  21. };
  22. });
  23. function passStringToWasm0(arg, malloc, realloc) {
  24. if (realloc === undefined) {
  25. const buf = cachedTextEncoder.encode(arg);
  26. const ptr = malloc(buf.length);
  27. getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
  28. WASM_VECTOR_LEN = buf.length;
  29. return ptr;
  30. }
  31. let len = arg.length;
  32. let ptr = malloc(len);
  33. const mem = getUint8Memory0();
  34. let offset = 0;
  35. for (; offset < len; offset++) {
  36. const code = arg.charCodeAt(offset);
  37. if (code > 0x7F) break;
  38. mem[ptr + offset] = code;
  39. }
  40. if (offset !== len) {
  41. if (offset !== 0) {
  42. arg = arg.slice(offset);
  43. }
  44. ptr = realloc(ptr, len, len = offset + arg.length * 3);
  45. const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
  46. const ret = encodeString(arg, view);
  47. offset += ret.written;
  48. }
  49. WASM_VECTOR_LEN = offset;
  50. return ptr;
  51. }
  52. let cachegetInt32Memory0 = null;
  53. function getInt32Memory0() {
  54. if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
  55. cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
  56. }
  57. return cachegetInt32Memory0;
  58. }
  59. let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
  60. cachedTextDecoder.decode();
  61. function getStringFromWasm0(ptr, len) {
  62. return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
  63. }
  64. /**
  65. * @param {string} epc_strings
  66. * @param {string} separator
  67. * @returns {string}
  68. */
  69. export function batch_epc2ean(epc_strings, separator) {
  70. try {
  71. var ptr0 = passStringToWasm0(epc_strings, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
  72. var len0 = WASM_VECTOR_LEN;
  73. var ptr1 = passStringToWasm0(separator, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
  74. var len1 = WASM_VECTOR_LEN;
  75. wasm.batch_epc2ean(8, ptr0, len0, ptr1, len1);
  76. var r0 = getInt32Memory0()[8 / 4 + 0];
  77. var r1 = getInt32Memory0()[8 / 4 + 1];
  78. return getStringFromWasm0(r0, r1);
  79. } finally {
  80. wasm.__wbindgen_free(r0, r1);
  81. }
  82. }