-
Notifications
You must be signed in to change notification settings - Fork 321
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
expose method to create parser from direct memory #435
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,4 +64,16 @@ public void close() | |
{ | ||
// Nothing to do | ||
} | ||
|
||
/** | ||
* Create a ByteBufferInput on off heap memory | ||
* @param address the address | ||
* @param offset the offset | ||
* @param length the length | ||
* @return a new ByteBufferInput on the specified address | ||
*/ | ||
public static ByteBuffer directBuffer(long address, int offset, int length) | ||
{ | ||
return DirectBufferAccess.newByteBuffer(address, offset, length, null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't seem to me that this method is related to ByteBufferInput. @xerial Do you think this is the right place to put the method in? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can make DirectBufferAccess a public class instead of adding this method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually this location is a bit weird. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,15 @@ | |
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.io.IOContext; | ||
import org.msgpack.core.MessagePack; | ||
import org.msgpack.core.buffer.ByteBufferInput; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.io.Writer; | ||
import java.nio.ByteBuffer; | ||
import java.util.Arrays; | ||
|
||
public class MessagePackFactory | ||
|
@@ -98,6 +100,22 @@ public JsonParser createParser(byte[] data) | |
return _createParser(data, 0, data.length, ioContext); | ||
} | ||
|
||
@Override | ||
public JsonParser createParser(byte[] data, int offset, int length) | ||
throws IOException, JsonParseException | ||
{ | ||
IOContext ioContext = _createContext(data, false); | ||
return _createParser(data, offset, length, ioContext); | ||
} | ||
|
||
public JsonParser createParser(long memoryAddress, int offset, int length) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you might notice since this method doesn't have How do you use this method via Jackson's API? It would be great, if you add some unit tests to make it clear 😺 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use the MessagePackFactory directly, currently using reflection. |
||
throws IOException, JsonParseException | ||
{ | ||
ByteBuffer byteBuffer = ByteBufferInput.directBuffer(memoryAddress, offset, length); | ||
IOContext ioContext = _createContext(byteBuffer, false); | ||
return _createParser(byteBuffer, ioContext); | ||
} | ||
|
||
@Override | ||
public JsonParser createParser(InputStream in) | ||
throws IOException, JsonParseException | ||
|
@@ -117,6 +135,16 @@ protected MessagePackParser _createParser(InputStream in, IOContext ctxt) | |
return parser; | ||
} | ||
|
||
protected MessagePackParser _createParser(ByteBuffer in, IOContext ctxt) | ||
throws IOException | ||
{ | ||
MessagePackParser parser = new MessagePackParser(ctxt, _parserFeatures, _objectCodec, in, reuseResourceInParser); | ||
if (extTypeCustomDesers != null) { | ||
parser.setExtensionTypeCustomDeserializers(extTypeCustomDesers); | ||
} | ||
return parser; | ||
} | ||
|
||
@Override | ||
protected JsonParser _createParser(byte[] data, int offset, int len, IOContext ctxt) | ||
throws IOException, JsonParseException | ||
|
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.
This static method returns ByteBuffer not ByteBufferInput