Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
serban-mihai opened this issue Jan 30, 2025 · 0 comments
Open

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

serban-mihai opened this issue Jan 30, 2025 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@serban-mihai
Copy link

serban-mihai commented Jan 30, 2025

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?

@serban-mihai serban-mihai added the documentation Improvements or additions to documentation label Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant