diff --git a/msgpack-core/src/main/java/org/msgpack/core/buffer/ByteBufferInput.java b/msgpack-core/src/main/java/org/msgpack/core/buffer/ByteBufferInput.java index fd0311b83..204ff0eb3 100644 --- a/msgpack-core/src/main/java/org/msgpack/core/buffer/ByteBufferInput.java +++ b/msgpack-core/src/main/java/org/msgpack/core/buffer/ByteBufferInput.java @@ -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); + } } diff --git a/msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackFactory.java b/msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackFactory.java index 11b5ee88f..bc2311cf6 100644 --- a/msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackFactory.java +++ b/msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackFactory.java @@ -22,6 +22,7 @@ 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; @@ -29,6 +30,7 @@ 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) + 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 diff --git a/msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackParser.java b/msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackParser.java index 5df9632ab..85f32ca8a 100644 --- a/msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackParser.java +++ b/msgpack-jackson/src/main/java/org/msgpack/jackson/dataformat/MessagePackParser.java @@ -33,6 +33,7 @@ import org.msgpack.core.MessagePack; import org.msgpack.core.MessageUnpacker; import org.msgpack.core.buffer.ArrayBufferInput; +import org.msgpack.core.buffer.ByteBufferInput; import org.msgpack.core.buffer.InputStreamBufferInput; import org.msgpack.core.buffer.MessageBufferInput; import org.msgpack.value.ValueType; @@ -41,6 +42,7 @@ import java.io.InputStream; import java.math.BigDecimal; import java.math.BigInteger; +import java.nio.ByteBuffer; import java.util.LinkedList; public class MessagePackParser @@ -149,6 +151,17 @@ public MessagePackParser( this(ctxt, features, new ArrayBufferInput(bytes), objectCodec, bytes, reuseResourceInParser); } + public MessagePackParser( + IOContext ctxt, + int features, + ObjectCodec objectCodec, + ByteBuffer byteBuffer, + boolean reuseResourceInParser) + throws IOException + { + this(ctxt, features, new ByteBufferInput(byteBuffer), objectCodec, byteBuffer, reuseResourceInParser); + } + private MessagePackParser(IOContext ctxt, int features, MessageBufferInput input,