Bytes
val concat : bytes -> bytes -> bytes
let concat: (a: bytes, b: bytes) => bytes
Concatenate together two bytes
arguments and return the result.
let concat_op (s : bytes) : bytes = Bytes.concat s 0x7070
let concat_op = (s: bytes): bytes => Bytes.concat(s, 0x7070);
val concats : bytes list -> bytes
let concats: (bs: list<bytes>) => bytes
Concatenate together a list of bytes
and return the result.
val sub : nat -> nat -> bytes -> bytes
let sub : (start: nat, length: nat, input: bytes) => bytes
Extract bytes from start
to length
. For example if you gave the
input "ff7a7aff" to the following function:
let slice_op (s : bytes) = Bytes.sub 1n 2n s
let slice_op = (s: bytes) => Bytes.sub(1n, 2n, s);
It would return "7a7a".
val pack : 'a -> bytes
let pack : (data: 'a) => bytes
Converts Michelson data structures to a binary format for serialisation.
⚠️
PACK
andUNPACK
are features of Michelson that are intended to be used by people that really know what they're doing. There are several failure cases (such asUNPACK
ing a lambda from an untrusted source), most of which are beyond the scope of this document. Don't use these functions without doing your homework first.
let id_string (p : string) =
let packed : bytes = Bytes.pack p in
Bytes.unpack packed
function id_string (p: string) {
let packed : bytes = Bytes.pack(p);
return Bytes.unpack(packed);
};
val unpack : bytes -> 'a option
let unpack: (serialized_data: bytes) => option<'a>
Reverses the result of using pack
on data.
As the conversion might fail an option type is returned.
⚠️
PACK
andUNPACK
are features of Michelson that are intended to be used by people that really know what they're doing. There are several failure cases (such asUNPACK
ing a lambda from an untrusted source), most of which are beyond the scope of this document. Don't use these functions without doing your homework first.
let id_string (p : string) =
let packed : bytes = Bytes.pack p in
Bytes.unpack packed
function id_string (p: string) {
let packed : bytes = Bytes.pack(p);
return Bytes.unpack(packed);
};
val length : bytes -> nat
let length: (b: bytes) => nat