{"route":"/en-US-v0.14.1/reference/data-loading/cbor/","title":"CBOR","description":"Documentation for the `cbor` function.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"conversion","name":"Conversion","children":[{"id":"notes","name":"Notes","children":[]}]},{"id":"parameters","name":"Parameters","children":[{"id":"parameters-source","name":"source","children":[]}]},{"id":"definitions","name":"Definitions","children":[{"id":"definitions-decode","name":"Decode CBOR","children":[{"id":"definitions-decode-data","name":"data","children":[]}]},{"id":"definitions-encode","name":"Encode CBOR","children":[{"id":"definitions-encode-value","name":"value","children":[]}]}]}],"body":{"kind":"func","content":{"path":[],"name":"cbor","title":"CBOR","keywords":[],"oneliner":"Reads structured data from a CBOR file.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Reads structured data from a CBOR file.</p>\n<p>The file must contain a valid CBOR serialization. The CBOR values will be\nconverted into corresponding Typst values as listed in the\n<a href=\"#conversion\">table below</a>.</p>\n<p>The function returns a dictionary, an array or, depending on the CBOR file,\nanother CBOR data type.</p>\n<h2 id=\"conversion\">Conversion details</h2>\n<table><thead><tr><th>CBOR value</th><th>Converted into Typst</th></tr></thead><tbody>\n<tr><td>integer</td><td><a href=\"/en-US-v0.14.1/reference/foundations/int/\" title=\"`int`\"><code>int</code></a> (or <a href=\"/en-US-v0.14.1/reference/foundations/float/\" title=\"`float`\"><code>float</code></a>)</td></tr>\n<tr><td>bytes</td><td><a href=\"/en-US-v0.14.1/reference/foundations/bytes/\" title=\"`bytes`\"><code>bytes</code></a></td></tr>\n<tr><td>float</td><td><a href=\"/en-US-v0.14.1/reference/foundations/float/\" title=\"`float`\"><code>float</code></a></td></tr>\n<tr><td>text</td><td><a href=\"/en-US-v0.14.1/reference/foundations/str/\" title=\"`str`\"><code>str</code></a></td></tr>\n<tr><td>bool</td><td><a href=\"/en-US-v0.14.1/reference/foundations/bool/\" title=\"`bool`\"><code>bool</code></a></td></tr>\n<tr><td>null</td><td><code><span class=\"typ-key\">none</span></code></td></tr>\n<tr><td>array</td><td><a href=\"/en-US-v0.14.1/reference/foundations/array/\" title=\"`array`\"><code>array</code></a></td></tr>\n<tr><td>map</td><td><a href=\"/en-US-v0.14.1/reference/foundations/dictionary/\" title=\"`dictionary`\"><code>dictionary</code></a></td></tr>\n</tbody></table>\n<table><thead><tr><th>Typst value</th><th>Converted into CBOR</th></tr></thead><tbody>\n<tr><td>types that can be converted from CBOR</td><td>corresponding CBOR value</td></tr>\n<tr><td><a href=\"/en-US-v0.14.1/reference/foundations/symbol/\" title=\"`symbol`\"><code>symbol</code></a></td><td>text</td></tr>\n<tr><td><a href=\"/en-US-v0.14.1/reference/foundations/content/\" title=\"`content`\"><code>content</code></a></td><td>a map describing the content</td></tr>\n<tr><td>other types (<a href=\"/en-US-v0.14.1/reference/layout/length/\" title=\"`length`\"><code>length</code></a>, etc.)</td><td>text via <a href=\"/en-US-v0.14.1/reference/foundations/repr/\" title=\"`repr`\"><code>repr</code></a></td></tr>\n</tbody></table>\n<h3 id=\"notes\">Notes</h3>\n<ul>\n<li>\n<p>Be aware that CBOR integers larger than 2<sup>63</sup>-1 or smaller than\n-2<sup>63</sup> will be converted to floating point numbers, which may\nresult in an approximative value.</p>\n</li>\n<li>\n<p>CBOR tags are not supported, and an error will be thrown.</p>\n</li>\n<li>\n<p>The <code>repr</code> function is <a href=\"/en-US-v0.14.1/reference/foundations/repr/#debugging-only\">for debugging purposes only</a>,\nand its output is not guaranteed to be stable across Typst versions.</p>\n</li>\n</ul>"}],"self":false,"params":[{"name":"source","details":[{"kind":"html","content":"<p>A <a href=\"/en-US-v0.14.1/reference/syntax/#paths\">path</a> to a CBOR file or raw CBOR bytes.</p>"}],"types":["str","bytes"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["any"],"scope":[{"path":["cbor"],"name":"decode","title":"Decode CBOR","keywords":[],"oneliner":"Reads structured data from CBOR bytes.","element":false,"contextual":false,"deprecationMessage":"`cbor.decode` is deprecated, directly pass bytes to `cbor` instead","deprecationUntil":"0.15.0","details":[{"kind":"html","content":"<p>Reads structured data from CBOR bytes.</p>"}],"self":false,"params":[{"name":"data","details":[{"kind":"html","content":"<p>CBOR data.</p>"}],"types":["bytes"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["any"],"scope":[]},{"path":["cbor"],"name":"encode","title":"Encode CBOR","keywords":[],"oneliner":"Encode structured data into CBOR bytes.","element":false,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Encode structured data into CBOR bytes.</p>"}],"self":false,"params":[{"name":"value","details":[{"kind":"html","content":"<p>Value to be encoded.</p>"}],"types":["any"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["bytes"],"scope":[]}]}}}