> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: MessagePack
icon: message-circle-more
---

# <ApiPageIcon icon="message-circle-more" />MessagePack

## msgpack<ApiTag label="object type" />

<ApiMembers>
  <ApiMember kind="fn" name="msgpack.pack" summary="Packs one or more Lua values into one string of MessagePack data." args="...?" sig="[{&#x22;s&#x22;:&#x22;msgpack.pack&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;...&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;...&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}],&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;msgpack_stream&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]}]">
    <ApiNotes>
      `nil` is packed as MessagePack `nil`, and a boolean is packed as `true` or `false`. A number
      without a fractional part is packed as an integer. Any other number is packed as a 32 bit
      float when that keeps its exact value, and as a 64 bit double otherwise. A string is packed as
      raw bytes.

      A table is packed as an array when its keys are exactly the integers from 1 to N. An empty
      table is packed as an empty array. Any other table is packed as a map. Tables that are nested
      more than 16 levels deep are packed as `nil`.

      Values of any other type, such as functions and userdata, are packed as `nil`.

      You must pass at least one value. If you call `pack` with no values, it throws an error. When
      you pass more than one value, the string holds one MessagePack object for each value, one
      after the other.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="msgpack.unpack" summary="Unpacks every object in a string of MessagePack data and returns them as separate values. For example, a string made by `msgpack.pack(a, b, c)` returns `a`, `b` and `c`." args="msgpack_stream" sig="[{&#x22;s&#x22;:&#x22;msgpack.unpack&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;msgpack_stream&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;msgpack_stream&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]}]" returns="[{&#x22;n&#x22;:&#x22;...&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]}]">
    <ApiNotes>
      Throws an error if the data is cut short, has a bad format, or is nested more than 16 levels
      deep.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="msgpack.unpack_one" summary="Unpacks one object from a string of MessagePack data, starting at `offset`." args="msgpack_stream, offset?" sig="[{&#x22;s&#x22;:&#x22;msgpack.unpack_one&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;msgpack_stream&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;offset&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;msgpack_stream&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]},{&#x22;n&#x22;:&#x22;offset&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;resume_offset&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]},{&#x22;n&#x22;:&#x22;object&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]}]">
    <ApiNotes>
      `offset` is a byte position in `msgpack_stream`. The first byte is at offset `0`, which is
      also the default.

      The function returns `resume_offset` first and the object second. Pass `resume_offset` to the
      next `unpack_one` call to read the next object. When the end of the data is reached,
      `resume_offset` is `-1`.

      Throws an error if `offset` is negative or larger than the length of the data, or if the data
      is invalid.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="msgpack.unpack_limit" summary="Unpacks up to `limit` objects from a string of MessagePack data, starting at `offset`." args="msgpack_stream, limit, offset?" sig="[{&#x22;s&#x22;:&#x22;msgpack.unpack_limit&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;msgpack_stream&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;limit&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;[, &#x22;},{&#x22;s&#x22;:&#x22;offset&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;msgpack_stream&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]},{&#x22;n&#x22;:&#x22;limit&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]},{&#x22;n&#x22;:&#x22;offset&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;resume_offset&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]},{&#x22;n&#x22;:&#x22;...&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]}]">
    <ApiNotes>
      `offset` is a byte position in `msgpack_stream`. The first byte is at offset `0`, which is
      also the default. If the data ends first, fewer than `limit` objects are returned.

      The function returns `resume_offset` first and the objects after it. Pass `resume_offset` to
      `unpack_limit` or `unpack_one` to continue reading. When the end of the data is reached,
      `resume_offset` is `-1`.

      If `limit` and `offset` are both `0`, the function works like `msgpack.unpack`. It returns
      every object and does not return `resume_offset`.

      Throws an error if `offset` or `limit` is negative, if `offset` is larger than the length of
      the data, or if the data is invalid.
    </ApiNotes>
  </ApiMember>
</ApiMembers>
