-
Notifications
You must be signed in to change notification settings - Fork 120
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
ByteBuffer POC [DO NOT MERGE] #1526
Conversation
@Test | ||
public void deserialization_from_byte_buffer() throws Exception { | ||
String json = loadJsonFixture(DIRECTIONS_V5_PRECISION6_FIXTURE); | ||
ByteBuffer buffer = ByteBuffer.wrap(json.getBytes(StandardCharsets.UTF_8)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want to point out that you can only pass java.nio.DirectBuffer
(created with java.nio.ByteBuffer.allocateDirect
, or the JNI NewDirectByteBuffer
function) to native using the DataRef type (I know it's unrelated to this test, I just want to make sure there is no surprise). ByteBuffer.wrap
doesn't allocate memory on native heap so native can't access the memory region directly. Otherwise, code from DirectionsResponse
looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the clarification. I updated the test to use direct buffer to avoid confusion.
@@ -146,6 +154,49 @@ public static DirectionsResponse fromJson(@NonNull String json) { | |||
return gson.create().fromJson(json, DirectionsResponse.class).toBuilder().build(); | |||
} | |||
|
|||
public static DirectionsResponse fromJson(@NonNull ByteBuffer json, Charset charsets) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about ways we could access specific parts of the DirectionsResponse, rather than deserializing the entire object. The DirectionsResponse can be large, but if we could stream the components.
For example, could we stream the geometry? #1518
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kmadsen , I'm not sure if I understood this idea correctly. Is the idea about keeping raw json response in memory and deserialise only during first access?
71d2919
to
16c0cd2
Compare
16c0cd2
to
96c0c3a
Compare
Closed in favour of #1545 |
It's an example of how mapbox java can deserialise direction response model from buffer allocated in native memory copying data by small chunks, in our case by 1024 bytes which happens inside GSON library.