# struct

Larky module containing functions to work with Struct.

This module provides access to C-like structs represented as Larky bytes objects. This can be used in handling binary data. It uses Format Strings as compact descriptions of the layout of the C structs and the intended conversion to/from Larky values.

Similar to [struct](https://docs.python.org/3/library/struct.html).

## struct.calcsize(fmt)

Return the size of the struct (and hence of the bytes object produced by pack(format, …)) corresponding to the format string format.

**Parameters:**

**fmt** – format.

*Returns:* size.

## struct.pack(fmt, \*values)

Return a bytes object containing the values v1, v2, ... packed according to the format string format. The arguments must match the values required by the format exactly.

Example:

```python
values = (1, 'ab', 2.7)
struct.pack('I 2s f', *values)
(1, 'ab', 2.7)
```

**Parameters:**

* **fmt** – format.
* **values** – values to pack.

*Returns:* struct object containing values.

## struct.pack\_into(fmt, buffer, offset, \*v)

Pack the values v1, v2, ... according to the format string format and write the packed bytes into the writable buffer buffer starting at position offset. Note that offset is a required argument.

**Parameters:**

* **fmt** – format.
* **buffer** – writable buffer.
* **offset** – starting positions.
* **v** – values to pack.

*Returns:* struct object containing values.

## struct.unpack(fmt, buffer)

Unpack from the buffer buffer (presumably packed by pack(format, ...)) according to the format string format. The result is a tuple even if it contains exactly one item. The buffer’s size in bytes must match the size required by the format, as reflected by calcsize().

**Parameters:**

* **fmt** – format.
* **buffer** – writable buffer.

*Returns:* string representation of struct.

## struct.unpack\_from(fmt, buffer, offset=0)

Unpack from buffer starting at position offset, according to the format string format. The result is a tuple even if it contains exactly one item. The buffer’s size in bytes, starting at position offset, must be at least the size required by the format, as reflected by calcsize().

**Parameters:**

* **fmt** – format.
* **buffer** – writable buffer.
* **offset** – starting positions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.verygoodsecurity.com/vault/developer-tools/larky/library-api/struct.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
