Skip to content

Unable to decode a nested array of buffers #18

@mcuppi

Description

@mcuppi

Attempting to decode an array of buffers in a larger buffer seems to fail.

Here is an example:

import { defineFormat, Type } from "tinybuf";

const Entity = defineFormat(6, {
  id: Type.String,
});

const GameState = defineFormat(7, {
  entities: [Type.Buffer],
});

// Encode
const buffer = GameState.encode({
  entities: [
    Entity.encode({
      id: "e1",
    }),
    Entity.encode({
      id: "e2",
    }),
    Entity.encode({
      id: "e3",
    }),
  ],
});

// Decode
const payload = GameState.decode(buffer);
payload.entities.forEach((entityBuffer, index) => {
  payload.entities[index] = Entity.decode(entityBuffer);
});
console.log(payload);

Here is a live example: https://codesandbox.io/p/sandbox/sxdlyg

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions