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

Support array of strings #98

Open
vlkv opened this issue Feb 23, 2023 · 1 comment
Open

Support array of strings #98

vlkv opened this issue Feb 23, 2023 · 1 comment
Labels

Comments

@vlkv
Copy link

vlkv commented Feb 23, 2023

This is not possible:

struct Foo inline {
    Bars [][]char;
}

So, at the moment we have to do:

struct Str inline {
    Value []char;
}
struct Foo inline {
    Bars []Str;
}

This is not very convenient.

@inkeliz
Copy link
Owner

inkeliz commented Feb 24, 2023

That is a known limitation, but I'm not sure how to proper fix.


If you have one function such as Foo.Bars() []string, then it needs to create a new array and, maybe, encoding all strings.

It have two alternatives:

  • Create functions to get string per index: Foo.BarsAt(index int) string.
    • That allows to zero-copy, since it call will return a single string (which is, usually, just one pointer). Or, in the worse situation, it will encode a single string.
  • Create a "class/struct" such as StringArrayViewer: Foo.Bars() []StringArrayViewer.
    • That will return array of fixed-size struct, which contains the start position of the first string. Then, StringArrayViewer have methods such as GetAt(index int).

The second case, is basically what happens in your schema (but instead of known-type, you need to create your custom type). 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants