Skip to main content

Bytes

cameligo

val concat : bytes -> bytes -> bytes

jsligo

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);
cameligo

val concats : bytes list -> bytes

jsligo

let concats: (bs: list<bytes>) => bytes

Concatenate together a list of bytes and return the result.

cameligo

val sub : nat -> nat -> bytes -> bytes

jsligo

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);

It would return "7a7a".

cameligo

val pack : 'a -> bytes

jsligo

let pack : (data: 'a) => bytes

Converts Michelson data structures to a binary format for serialisation.

⚠️ PACK and UNPACK 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 as UNPACKing 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.

function id_string (p: string) {
let packed : bytes = Bytes.pack(p);
return Bytes.unpack(packed);
};
cameligo

val unpack : bytes -> 'a option

jsligo

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 and UNPACK 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 as UNPACKing 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.

function id_string (p: string) {
let packed : bytes = Bytes.pack(p);
return Bytes.unpack(packed);
};
cameligo

val length : bytes -> nat

jsligo

let length: (b: bytes) => nat