Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Commands

Guardian Tcl currenly adds one ensemble command, parse. This command exposes subcommands to parse data from a variety of formats directly into nested Tcl data structures.

parse

The parse command has the following usage:

parse <format> <data>
parse <format> -file <path>
  • <format> can be any of json, toml, or yaml.
  • <data> is a Tcl string containing the raw data to deserialize.
  • <path> is the path to a file containing data in the specified format.

For example, to deserialize the contents of the $conf_src variable as JSON, you can write:

set config [parse json $conf_src]

These commands are wrappers around the corresponding Serde deserializers. You can also parse by parsing to typedata and using td native to obtain a native Tcl structure.

uuid

The uuid ensemble can generate and inspect UUIDs (backed by the uuid crate). UUIDs are represented as hexadecimal strings without braces.

uuid v3 namespace name
Generate a version 3 (MD5) UUID with the specified namespace and name. namespace can be either a UUID, or one of the strings oid, url, dns, or x500.
uuid v4
Generate a version 4 (random) UUID.
uuid v5 namespace name
Generate a version 5 (SHA1) UUID. Parameters are identical to uuid v3.
uuid v7
Generate a version 7 (timestamp + random, sortable) UUID.
uuid version uuid
Query the version number of the specified UUID.
uuid timestamp uuid
Query the timestamp of the specified UUID (v1, v6, or v7).
uuid random
Generate a random UUID (currently alias for uuid v4).
uuid bytes
Obtain the binary representation of the UUID as a 16-byte binary string.

Binary Extensions

Guardian Tcl extends the binary ensemble with binary encode and binary decode commands. These function much like the standard Tcl binary encode/decode commands1, except they do not support any options.

binary encode encoding data
Encode data with encoding.
binary decode encoding data
Decode data with encoding.

It also provides a command to generate random bytes:

binary random n
Generate n random bytes as a binary string. This uses the system’s (secure) random number generator via getrandom.

Supported Encoding

The following encodings are supported:


  1. https://www.tcl-lang.org/man/tcl9.1/TclCmd/binary.html#M5