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

Allow ByteArray as input when parsing JSON #357

Closed
yorickpeterse opened this issue Jan 24, 2023 · 2 comments
Closed

Allow ByteArray as input when parsing JSON #357

yorickpeterse opened this issue Jan 24, 2023 · 2 comments
Assignees
Labels
accepting contributions Issues that are suitable to be worked on by anybody, not just maintainers feature New things to add to Inko, such as a new standard library module std Changes related to the standard library
Milestone

Comments

@yorickpeterse
Copy link
Collaborator

The JSON parser introduced in master only supports String as input, which makes parsing files rather wasteful/clunky as you first have to convert a ByteArray to a String. Instead the JSON parser should just support both String and ByteArray.

For this to work we probably need to introduce a trait that is both implemented by String and ByteArray, and use that as the expected input. The parser does try to parse strings into Int/Float values (with a custom offset) in a few places, so we need a way of handling that.

@yorickpeterse yorickpeterse added feature New things to add to Inko, such as a new standard library module and removed type::feature labels Mar 15, 2023
@yorickpeterse yorickpeterse removed this from the 0.2.5 milestone Mar 15, 2023
@yorickpeterse yorickpeterse added the accepting contributions Issues that are suitable to be worked on by anybody, not just maintainers label Mar 18, 2023
@yorickpeterse
Copy link
Collaborator Author

Any runtime library changes that need to be made will probably conflict with #508, so it's best to wait until said PR is merged.

@yorickpeterse
Copy link
Collaborator Author

There are two approaches I can think of:

  1. We just take a ByteArray as input. When parsing from IO inputs, this is probably the type of data you already have anyway. String also implements IntoByteArray, so we can take that as an argument.
  2. We introduce some sort of Slice type which is a class enum with two cases: String and ByteArray, wrapping a reference to their corresponding types. We then provide the necessary methods for creating sub slices, turning it into a String, etc.

In both cases a problem is that std::json::Parser uses _INKO.string_to_int and _INKO.string_to_float directly, which only supports strings as input. We'd have to change these intrinsics to operate on bytes directly, then pass those in accordingly.

@yorickpeterse yorickpeterse added this to the 0.13.0 milestone Jul 21, 2023
@yorickpeterse yorickpeterse self-assigned this Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting contributions Issues that are suitable to be worked on by anybody, not just maintainers feature New things to add to Inko, such as a new standard library module std Changes related to the standard library
Projects
None yet
Development

No branches or pull requests

1 participant