Module envelope

Source
Expand description

Envelope format for HUGR packages.

The format is designed to be extensible and backwards-compatible. It consists of a header declaring the format used to encode the HUGR, followed by the encoded HUGR itself.

Use read_envelope and write_envelope for reading and writing envelopes from/to readers and writers, or call Package::load and Package::store directly.

§Payload formats

The envelope may encode the HUGR in different formats, listed in EnvelopeFormat. The payload may also be compressed with zstd.

Some formats can be represented as ASCII, as indicated by the EnvelopeFormat::ascii_printable method. When this is the case, the whole envelope can be stored in a string.

§Envelope header

The binary header format is 10 bytes, with the following fields:

FieldSize (bytes)Description
Magic8MAGIC_NUMBERS constant identifying the envelope format.
Format1EnvelopeFormat describing the payload format.
Flags1Additional configuration flags.

Flags:

  • Bit 0: Whether the payload is compressed with zstd.
  • Bits 1-5: Reserved for future use.
  • Bit 7,6: Constant “01” to make some headers ascii-printable.

Structs§

EnvelopeConfig
Configuration for encoding an envelope.
ZstdConfig
Configuration for zstd compression.

Enums§

EnvelopeError
Error type for envelope operations.
EnvelopeFormat
Encoded format of an envelope payload.

Constants§

MAGIC_NUMBERS
Magic number identifying the start of an envelope.

Functions§

read_envelope
Read a HUGR envelope from a reader.
write_envelope
Write a HUGR package into an envelope, using the specified configuration.