Skip to content

Stringify Method

The stringify method allows you to convert complex bytecode structures into a serialized format. This is particularly useful for debugging, logging, or preparing your bytecode for storage and transmission.

Using TypeScript

For TypeScript, you can use the stringify method to output your bytecode arrays into a human-readable string format. This helps in verifying the structure of your instructions before they are loaded into the VM.

ts
const raw = [
  ['push', 5],
  ['val', 'x'],
  ['set', 'x'],
];
const stringify = tools.stringifyLTC(raw);
console.log(stringify);

Using Rust

In Rust, you can stringify your bytecode by working with raw string representations or using serde_json to manage complex serialization. This provides flexibility when you need to transform your bytecode into a format compatible with external tools or logging systems.

rust
let raw = r#"[
  ["push", 5],
  ["val", "x"],
  ["set", "x"]
]"#;
let stringify = tools.stringify_ltc(raw);
println!("{:#}", stringify.clone());
rust
let raw = serde_json::json!([
  ["push", 5],
  ["val", "x"],
  ["set", "x"]
]);
let stringify = tools.stringify_ltc(raw);
println!("{:#}", stringify.clone());

INFO

Capability Required: no specific capability

Released under the Apache-2.0 License.