The engine is more strict about the format it emits: every message ends with a newline, and unnecessary whitespace and newlines will not be emitted within a message. It is explicitly supported for a plugin to choose to parse the input from the engine by parsing each line received as a separate message, as this is most commonly supported across all languages.
Byte arrays are encoded as plain JSON arrays of numbers representing each byte. While this is inefficient, it is maximally portable.
MessagePack **should** be preferred where possible if performance is desired, especially if byte streams are expected to be a common input or output of the plugin.
### MessagePack
[MessagePack](https://msgpack.org) is a machine-first binary encoding format with a data model very similar to JSON. Messages are encoded as maps. There is no separator between messages, and no padding character is accepted.
Most messages are encoded in the same way as their JSON analogue. For example, the following [`Hello`](#hello) message in JSON:
```json
{
"Hello": {
"protocol": "nu-plugin",
"version": "0.94.0",
"features": []
}
}
```
is encoded in the MessagePack format as:
```text
81 // map, one element
a5 "Hello" // 5-character string
83 // map, three elements
a8 "protocol" // 8-character string
a9 "nu-plugin" // 9-character string
a7 "version" // 7-character string
a6 "0.94.0" // 6-character string
a8 "features" // 8-character string
90 // array, zero elements
```
(verbatim byte strings quoted for readability, non-printable bytes in hexadecimal)
Byte arrays are encoded with MessagePack's native byte arrays, which impose zero constraints on the formatting of the bytes within. In general, the MessagePack encoding is much more efficient than JSON and **should** be the first choice for plugins where performance is important and MessagePack is available.
<a name="value"></a>
## Value types
[Rust documentation](https://docs.rs/nu-protocol/latest/nu_protocol/enum.Value.html)
The `Value` enum describes all structured data used in Nu.
Example:
```json
{
"Int": {
"val": 5,
"span": {
"start": 90960,
"end": 90963
}
}
}
```
### `Bool`
A boolean.
| Field | Type |
| -------- | --------------- |
| **val** | boolean |
| **span** | [`Span`](#span) |
Example:
```nu
true
```
```json
{
"Bool": {
"val": true,
"span": {
"start": 4040,
"end": 4044
}
}
}
```
### `Int`
A 64-bit signed integer.
| Field | Type |
| -------- | --------------- |
| **val** | integer |
| **span** | [`Span`](#span) |
Example:
```nu
-2
```
```json
{
"Int": {
"val": -2,
"span": {
"start": 4040,
"end": 4042
}
}
}
```
### `Float`
A 64-bit (double precision) floating point number.
| Field | Type |
| -------- | --------------- |
| **val** | double |
| **span** | [`Span`](#span) |
Example:
```nu
36.4
```
```json
{
"Float": {
"val": 36.4,
"span": {
"start": 8040,
"end": 8044
}
}
}
```
### `Filesize`
A quantity of bytes, internally a 64-bit signed integer representing the number of bytes. This is pretty-printed to the user with a more human scale, e.g. `32.4 MiB`.
| Field | Type |
| -------- | --------------- |
| **val** | integer |
| **span** | [`Span`](#span) |
Example:
```nu
32.4MiB
```
```json
{
"Filesize": {
"val": 33973248,
"span": {
"start": 7740,
"end": 7747
}
}
}
```
### `Duration`
A duration of time, internally a 64-bit signed integer representing the number of nanoseconds. This is pretty-printed to the user with a more human scale, e.g. `8sec 375ms 604µs 528ns`.
| Field | Type |
| -------- | --------------- |
| **val** | integer |
| **span** | [`Span`](#span) |
Example:
```nu
8375604528ns
```
```json