Pkl Binary Encoding

Pkl values can be encoded into a binary format. This format is used for Pkl’s non-JVM language bindings, for example, for its Go and Swift bindings.

The binary format is uses MessagePack encoding.

Primitives

All Pkl primitives turn into their respective MessagePack primitive.

Pkl Type MessagePack format

Int

int

Float

float

String

string

Boolean

bool

Null

nil

Pkl integers are encoded into the smallest int type that the number will fit into. For example, value 8 gets encoded as MessagePack int8 format.

Non-primitives

All non-primitive values are encoded as MessagePack arrays. The first slot of the array designates the value’s type. The remaining slots have fixed meanings depending on the type.

The array’s length is the number of slots that are filled. For example, List is encoded as an MessagePack array with two elements.

Pkl type Slot 1 Slot 2 Slot 3 Slot 4

code

type

description

type

description

type

description

Typed, Dynamic

0x1

str

Fully qualified class name

str

Enclosing module URI

array

Array of object members

Map

0x2

map

Map of <value> to <value>

Mapping

0x3

map

Map of <value> to <value>

List

0x4

array

Array of <value>

Listing

0x5

array

Array of <value>

Set

0x6

array

Array of <value>

Duration

0x7

float64

Duration value

str

Duration unit ("ns", "ms", etc.)

DataSize

0x8

float64

Value (float64)

str

DataSize unit ("b", "kb", etc.)

Pair

0x9

<value>

First value

<value>

Second value

IntSeq

0xA

int

Start

int

End

int

Step

Regex

0xB

str

Regex string representation

Class

0xC

TypeAlias

0xD

Object Members

Like non-primitive values, object members are encoded as MessagePack arrays, where the first slot designates the value’s type.

Member type Slot 1 Slot 2 Slot 3

code

type

description

type

description

Property

0x10

str

key

<value>

property value

Entry

0x11

<value>

entry key

<value>

entry value

Element

0x12

int

index

<value>

element value