@spacemesh/svm-codec
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -25,1 +25,2 @@ export declare const OK_MARKER = 1; | ||
export declare function decodeInput(encodedData: any): JSON; | ||
export declare function wasmBufferFree(buf: any): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeInput = exports.encodeInput = exports.decodeCall = exports.encodeCall = exports.decodeSpawn = exports.encodeSpawn = exports.isInitialized = exports.init = exports.ERR_MARKER = exports.OK_MARKER = void 0; | ||
exports.wasmBufferFree = exports.decodeInput = exports.encodeInput = exports.decodeCall = exports.encodeCall = exports.decodeSpawn = exports.encodeSpawn = exports.isInitialized = exports.init = exports.ERR_MARKER = exports.OK_MARKER = void 0; | ||
exports.OK_MARKER = 1; | ||
@@ -16,3 +16,3 @@ exports.ERR_MARKER = 0; | ||
function isInitialized() { | ||
return (codec !== null); | ||
return (codec !== undefined); | ||
} | ||
@@ -26,6 +26,3 @@ exports.isInitialized = isInitialized; | ||
const slice = wasmBufferDataSlice(result, 0, len); | ||
let errMessage = ""; | ||
if (slice[0] !== exports.OK_MARKER) { | ||
errMessage = loadWasmBufferError(result); | ||
} | ||
let errMessage = (slice[0] !== exports.OK_MARKER) ? loadWasmBufferError(result) : ""; | ||
wasmBufferFree(buf); | ||
@@ -39,3 +36,3 @@ wasmBufferFree(result); | ||
exports.encodeSpawn = encodeSpawn; | ||
// Decodes the provided svm encoded spwan data | ||
// Decodes the provided SVM encoded spawn data | ||
function decodeSpawn(data) { | ||
@@ -56,6 +53,3 @@ const buf = newWasmBuffer({ data: binToString(data) }); | ||
const slice = wasmBufferDataSlice(result, 0, len); | ||
let errMessage = ""; | ||
if (slice[0] !== exports.OK_MARKER) { | ||
errMessage = loadWasmBufferError(result); | ||
} | ||
let errMessage = (slice[0] !== exports.OK_MARKER) ? loadWasmBufferError(result) : ""; | ||
wasmBufferFree(buf); | ||
@@ -69,3 +63,3 @@ wasmBufferFree(result); | ||
exports.encodeCall = encodeCall; | ||
// Decodes the svm encoded call account data | ||
// Decodes the SVM encoded call account data | ||
function decodeCall(bytes) { | ||
@@ -90,3 +84,3 @@ const buf = newWasmBuffer({ data: binToString(bytes) }); | ||
exports.encodeInput = encodeInput; | ||
// Decode svm data provided in encodedData value and returns a json object of the data | ||
// Decode SVM data provided in encodedData value and returns a json object of the data | ||
function decodeInput(encodedData) { | ||
@@ -101,2 +95,8 @@ const buf = newWasmBuffer(encodedData); | ||
exports.decodeInput = decodeInput; | ||
// Frees an allocated svm_codec buffer that was previously allocated and returned to caller by an api function | ||
function wasmBufferFree(buf) { | ||
return codec.exports.wasm_free(buf); | ||
} | ||
exports.wasmBufferFree = wasmBufferFree; | ||
// internal helper functions | ||
// Encodes binary provided binary data as a hex binary string (without an 0x prefix) | ||
@@ -115,5 +115,7 @@ function binToString(array) { | ||
} | ||
///// Internal help functions below | ||
// Call an svm_codec function with the provided buffer. Returns result buffer. | ||
function call(funcName, buf) { | ||
if (codec === undefined) { | ||
throw new Error("Svm codec library is not initialized."); | ||
} | ||
return codec.exports[funcName](buf); | ||
@@ -123,10 +125,12 @@ } | ||
function wasmBufferAlloc(length) { | ||
if (codec === undefined) { | ||
throw new Error("Svm codec library is not initialized."); | ||
} | ||
return codec.exports.wasm_alloc(length); | ||
} | ||
// Frees an allocated svm_codec buffer that was previously allocated by svm_codec | ||
function wasmBufferFree(buf) { | ||
return codec.exports.wasm_free(buf); | ||
} | ||
// Returns the bytes length of a wasm_codec buffer | ||
function wasmBufferLength(buf) { | ||
if (codec === undefined) { | ||
throw new Error("Svm codec library is not initialized."); | ||
} | ||
return codec.exports.wasm_buffer_length(buf); | ||
@@ -136,2 +140,5 @@ } | ||
function wasmBufferDataPtr(buf) { | ||
if (codec === undefined) { | ||
throw new Error("Svm codec library is not initialized."); | ||
} | ||
return codec.exports.wasm_buffer_data(buf); | ||
@@ -141,2 +148,5 @@ } | ||
function copyToWasmBufferData(buf, data) { | ||
if (codec === undefined) { | ||
throw new Error("Svm codec library is not initialized."); | ||
} | ||
const ptr = wasmBufferDataPtr(buf); | ||
@@ -149,2 +159,5 @@ const memory = codec.exports.memory.buffer; | ||
function wasmBufferDataSlice(buf, offset, length) { | ||
if (codec === undefined) { | ||
throw new Error("Svm codec library is not initialized."); | ||
} | ||
const ptr = wasmBufferDataPtr(buf); | ||
@@ -151,0 +164,0 @@ const memory = codec.exports.memory.buffer; |
{ | ||
"name": "@spacemesh/svm-codec", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"collaborators": [ | ||
@@ -5,0 +5,0 @@ "Aviv Eyal <aviveyal07@gmail.com>" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18500
221
0