mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-21 06:11:18 +01:00
java: fixes native zero-copy unpacking routines of ByteBuffer
This commit is contained in:
parent
8b7894f9bd
commit
05d9d22d9e
@ -25,6 +25,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
|
||||
int offset = 0;
|
||||
int filled = 0;
|
||||
byte[] buffer = null;
|
||||
boolean bufferReferenced = false; // TODO zero-copy buffer
|
||||
private ByteBuffer castBuffer = ByteBuffer.allocate(8);
|
||||
|
||||
abstract boolean fill() throws IOException;
|
||||
@ -417,19 +418,18 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
|
||||
|
||||
final byte[] unpackByteArray() throws IOException, MessageTypeException {
|
||||
int length = unpackRaw();
|
||||
return unpackRawBody(length);
|
||||
}
|
||||
|
||||
final ByteBuffer unpackByteBuffer(int length) throws IOException, MessageTypeException {
|
||||
more(length);
|
||||
ByteBuffer buf = ByteBuffer.wrap(buffer, offset, length);
|
||||
advance(length);
|
||||
return buf;
|
||||
byte[] body = unpackRawBody(length);
|
||||
return body;
|
||||
}
|
||||
|
||||
final ByteBuffer unpackByteBuffer() throws IOException, MessageTypeException {
|
||||
// TODO zero-copy buffer
|
||||
int length = unpackRaw();
|
||||
return unpackByteBuffer(length);
|
||||
more(length);
|
||||
ByteBuffer buf = ByteBuffer.wrap(buffer, offset, length);
|
||||
bufferReferenced = true; // TODO fix magical code
|
||||
advance(length);
|
||||
return buf;
|
||||
}
|
||||
|
||||
final String unpackString() throws IOException, MessageTypeException {
|
||||
|
@ -232,6 +232,7 @@ public class Unpacker implements Iterable<MessagePackObject> {
|
||||
impl.buffer = buffer;
|
||||
impl.offset = offset;
|
||||
impl.filled = length;
|
||||
impl.bufferReferenced = false; // TODO zero-copy buffer
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,13 +277,16 @@ public class Unpacker implements Iterable<MessagePackObject> {
|
||||
if(impl.buffer == null) {
|
||||
int nextSize = (bufferReserveSize < require) ? require : bufferReserveSize;
|
||||
impl.buffer = new byte[nextSize];
|
||||
impl.bufferReferenced = false; // TODO zero-copy buffer
|
||||
return;
|
||||
}
|
||||
|
||||
if(impl.filled <= impl.offset) {
|
||||
// rewind the buffer
|
||||
impl.filled = 0;
|
||||
impl.offset = 0;
|
||||
if(!impl.bufferReferenced) { // TODO zero-copy buffer
|
||||
if(impl.filled <= impl.offset) {
|
||||
// rewind the buffer
|
||||
impl.filled = 0;
|
||||
impl.offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(impl.buffer.length - impl.filled >= require) {
|
||||
@ -301,6 +305,7 @@ public class Unpacker implements Iterable<MessagePackObject> {
|
||||
impl.buffer = tmp;
|
||||
impl.filled = notParsed;
|
||||
impl.offset = 0;
|
||||
impl.bufferReferenced = false; // TODO zero-copy buffer
|
||||
}
|
||||
|
||||
/**
|
||||
@ -538,7 +543,7 @@ public class Unpacker implements Iterable<MessagePackObject> {
|
||||
|
||||
|
||||
/**
|
||||
* Gets one raw bytes from the buffer.
|
||||
* Gets one raw object (header + body) from the buffer.
|
||||
* This method calls {@link fill()} method if needed.
|
||||
*/
|
||||
public byte[] unpackByteArray() throws IOException {
|
||||
@ -546,15 +551,7 @@ public class Unpacker implements Iterable<MessagePackObject> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets one raw body from the buffer.
|
||||
* This method calls {@link fill()} method if needed.
|
||||
*/
|
||||
public ByteBuffer unpackByteBuffer(int length) throws IOException {
|
||||
return impl.unpackByteBuffer(length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets one raw body from the buffer.
|
||||
* Gets one raw object (header + body) from the buffer.
|
||||
* This method calls {@link fill()} method if needed.
|
||||
*/
|
||||
public ByteBuffer unpackByteBuffer() throws IOException {
|
||||
|
@ -309,6 +309,7 @@ public class UnpackerImpl {
|
||||
cs = ACS_RAW_VALUE;
|
||||
break _fixed_trail_again;
|
||||
case ACS_RAW_VALUE: {
|
||||
// TODO zero-copy buffer
|
||||
byte[] raw = new byte[trail];
|
||||
System.arraycopy(src, n, raw, 0, trail);
|
||||
obj = RawType.create(raw);
|
||||
|
Loading…
x
Reference in New Issue
Block a user