---
url: /en-us/standard/quick-start.md
---
This page walks you through writing a **Core reader**: it reads every page and draws the strokes and basic shapes. The code is pseudocode close to TypeScript and works the same in any language. For the complete rules, see the block pages; the IDs in parentheses are the corresponding rules.

## Preparation

You need a library that can **decode one object at a time** from a sequence of consecutive MessagePack objects, for example `@msgpack/msgpack` (`decodeMulti`) for JavaScript, `MessagePack-CSharp` for C#, `msgpack-c` (`unpacker`) for C++, or `msgpack` (`Unpacker`) for Python.

The main file has no outer array: the objects follow one another directly (FILE-6).

## 1. Read all objects

```ts
const objects = []
try {
  for (const obj of decodeMulti(bytes)) objects.push(obj)
} catch {
  // Incomplete object at the end, or corruption in the middle: keep the objects read so far (FILE-16, FILE-17)
}
```

## 2. Check the Header

```ts
const header = objects[0]
if (!Array.isArray(header) || header.length !== 7 || header[0] !== 0
    || header[1] < 10 || header[1] > 19) {
  throw new Error('Not a UInk 1.x file')                  // VER-3, HDR-2
}
```

When `version` is greater than `11`, read the file as usual, and if needed tell the user "the file comes from a newer version" (VER-4).

## 3. Build the pages

```ts
let i = 1
const ext = objects[i]?.type === 1 ? objects[i++] : null   // Header Extension, optional
const firstDevice = ext?.devices?.[0]?.guid ?? null         // Core shows only the first Device (FILE-9)

const canvases = new Map()                                  // unique key → { canvas, blocks }
let current = null
for (; i < objects.length; i++) {
  const o = objects[i]
  if (o?.type === 2) {
    const key = [o.workspaceGuid ?? '', o.deviceGuid ?? '', o.pageGuid, o.layerIndex].join('|')
    current = { canvas: o, blocks: [] }
    canvases.set(key, current)                              // same key appears again: the later one replaces the earlier one (FILE-8)
  } else if (current && [3, 4, 5, 6].includes(o?.type)) {
    current.blocks.push(o)                                  // a content block belongs to the preceding Canvas (FILE-3)
  }                                                         // any other Type ID: skip (TYPE-9)
}
```

Then list the pages ordered by Workspace registration order and `pageIndex`; take only the Canvases whose `deviceGuid` equals `firstDevice` (or is omitted); stack multiple layers of the same page by `layerIndex` from low to high (FILE-9).

## 4. Draw a page

```ts
function drawCanvas(blocks) {
  // Recommended fallback for Clear (Inkeys extension): draw only the content after the last Clear (CLEAR-7)
  const lastClear = blocks.findLastIndex(b => b.type === 6)
  for (const b of blocks.slice(lastClear + 1)) {
    if (b.type === 3) drawInk(b)
    else if (b.type === 5) drawShape(b)
    // Media (type 4) belongs to Standard; a Core reader may skip it
  }
}
```

### Strokes

```ts
function drawInk(ink) {
  if (ink.inkType === 0) return                 // Erase belongs to the Inkeys extension: must be skipped (INK-11)
  const color = rgb(ink.color.fallback)         // Core uses only fallback (COLOR-2)
  let x = 0, y = 0
  const pts = ink.points.map((p, k) => {
    x = k === 0 ? p.x : x + p.x                 // first point absolute, the rest are offsets; accumulate in float64 (INK-4)
    y = k === 0 ? p.y : y + p.y
    return { x, y, w: p.width }
  })
  // The simplest way to draw: a circle of diameter w at each point, and a trapezoid between adjacent points to connect the circles.
  // This is exactly "circle nib + round cap" (NIB-1). Draw every other inkType as a normal pen (INK-13).
  strokeVariableWidth(pts, color)
}
```

### Shapes

```ts
function drawShape(s) {
  const g = s.geometry
  switch (s.shapeType) {
    case 0: case 1: polyline(g.points); break                       // Line, Polyline
    case 6: polygon(g.points); break                                // Polygon, closed automatically
    case 2: rect(g.centerX, g.centerY, g.width, g.height, g.rotation ?? 0); break
    case 3: rect(g.centerX, g.centerY, g.size, g.size, g.rotation ?? 0); break
    case 4: ellipse(g.centerX, g.centerY, g.width / 2, g.height / 2, g.rotation ?? 0); break
    case 5: ellipse(g.centerX, g.centerY, g.radius, g.radius, 0); break
    default: return                                                 // unknown geometry: skip (SHAPE-20)
  }
  if (s.fill) fillWith(rgb(s.fill.color.fallback))
  if (s.stroke) strokeWith(rgb(s.stroke.color.fallback), s.stroke.width)   // round caps, round joins (NIB-4)
}
```

At this point your reader meets the main requirements for reading at Core. Fill in the remaining items from the [Core checklist](levels#core), then verify with the [public samples](conformance#public-samples).

## 5. Write a minimal file

When writing, you must use the specified **exact types and bit widths** (TYPE-1). Many MessagePack libraries automatically choose the shortest integer encoding; in that case you need to specify the type by hand.

```ts
const header = [
  u16(0), u16(11), str8(uuid()),       // type, version, guid
  u32(1), u32(1), u32(1),              // deviceNum, workspaceNum, pageNum
  u64(Math.floor(Date.now() / 1000)),  // time
]
const canvas = {
  type: u16(2), pageGuid: uuid(), pageIndex: u32(0), pageNumber: u32(1),
  layerIndex: u32(0), layerNumber: u32(0),
}
const ink = {
  type: u16(3), contentId: u32(0), undoId: u32(0), inkType: i32(1),
  color: { fallback: u32(0x000000) }, opacity: f32(1), texture: i32(0),
  points: [
    { x: f32(100), y: f32(100), width: f32(4) },
    { x: f32(50), y: f32(20), width: f32(4) },   // offset from the previous point
  ],
}
write(encode(header), encode(canvas), encode(ink))  // the three objects directly end to end
```

This file has no Header Extension and uses the implicit Device and Workspace (HEXT-3), so the Canvas does not write `workspaceGuid` or `deviceGuid`.

## Next steps

* To display highlighters, dashed lines and arrows correctly: [Basic](levels#basic).
* To support images, PowerPoint and undo: [Standard](levels#standard).
* To save in real time while writing: [Saving, Appending and Recovery](incremental).
