Encoding
The functions for converting data from one format to another are described here.

Functions

Json( obj o ) str

The Json function converts a variable of obj type into json string.

JsonToObj( str s ) obj

The JsonToObj function converts json string into a variable of the obj type.
1
run str {
2
return Json(JsonToObj(`{
3
"int": 1234,
4
"str": "value",
5
"float": -45.67,
6
"list":[{"on": true},
7
"sub 2",
8
"sub 3",
9
{
10
"q": "OK"
11
}]
12
}`))
13
}
14
// Result {"float":-45.67,"int":1234,"list":[{"on":true},"sub 2","sub 3",{"q":"OK"}],"str":"value"}
Copied!

StructDecode( buf b, struct s )

The StructDecode function converts the binary data of a buf variable to the field values of the specified structure variable. The binary data must be created with StructEncode function.
1
time t
2
StructDecode(StructEncode(Now()), t)
Copied!

StructEncode( struct s ) buf

The StructEncode function converts a structure variable to binary and stores the result into a buf variable. The function saves only fields of the following types: int, bool, char, float, buf, str. Fields of other types are skipped.
1
struct tmp {
2
str head
3
int i
4
}
5
6
run str {
7
tmp t1 = {head: `HEADER`, i: -356}
8
buf bout = StructEncode(t1)
9
...
10
}
Copied!
Last modified 10mo ago