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

Move read bytes utilities to Encoding #558

Merged
merged 1 commit into from
Oct 4, 2024
Merged

Conversation

andreaTP
Copy link
Collaborator

@andreaTP andreaTP commented Oct 3, 2024

Fix #521

byte[] bytes = new byte[length];
try {
readBytes(buffer, bytes);
} catch (BufferUnderflowException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catch shouldn't be needed as readBytes already checks the length.

Or we could replace the checks in those read methods with handling for BufferUnderflowException.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

return readName(buffer, true);
}

public static String readName(ByteBuffer buffer, boolean checkMalformed) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: copy Javadoc from above or make it @see the above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


/**
* Read a symbol name from the buffer as UTF-8 String.
* See <a href="https://www.w3.org/TR/wasm-core-1/#names%E2%91%A0">2.2.4. Names</a> of the WebAssembly Core Specification.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link is broken: the extra %E2%91%A0 at the end of the URL shouldn't be there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fixed!

@@ -11,6 +13,126 @@ public final class Encoding {

private Encoding() {}

static int readInt(ByteBuffer buffer) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these need to be public? Could they be needed for parsing custom sections?

This is just a question to consider. It's fine to leave them private for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current status I think that there are quite a few changes necessary to offer a proper, usable and generic API to parse custom sections ...
I would not try to predict the future, and welcome effort in this direction when someone needs it.

Opening visibility is not going to be a breaking change.

@andreaTP andreaTP merged commit a8937a3 into dylibso:main Oct 4, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean Parser API
2 participants