Skip to content

Make an example on how to serialize/extract correctly Lists #19

@serban-mihai

Description

@serban-mihai

It would be nice to have examples of working with any List<T> or Data types.
Right now I don't understand how to correctly assign values to List keys from the generated schema.

The only way I've been able to work with Lists has been to use _private methods

const message = new capnp.
const requestData = message.initRoot(RequestData);

const headers = requestData._initHeaders(parsedHeaders.length);

parsedHeaders.forEach(({ key, value }, i) => {
  const h = headers.get(i);
  h.key = key;
  h.value = value;
});

But trying the following leads to errors both from typescripts due to type mismatch and also at runtime TypeError: Cannot read properties of undefined (reading 'isWordZero'):

requestData.headers = parsedHeaders.map(({ key, value }) => {
  return { key, value };
});

Also, how to deserialize string each values from the List of structs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions