stop using GatheringByteChannel
This commit is contained in:
parent
5d2b5df2b9
commit
196f67bb5d
2 changed files with 20 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
||||||
package org.capnproto.benchmark;
|
package org.capnproto.benchmark;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import org.capnproto.FromStructReader;
|
import org.capnproto.FromStructReader;
|
||||||
|
@ -37,7 +38,7 @@ public abstract class TestCase<RequestFactory extends StructFactory<RequestBuild
|
||||||
static final int SCRATCH_SIZE = 128 * 1024;
|
static final int SCRATCH_SIZE = 128 * 1024;
|
||||||
|
|
||||||
public void passByBytes(RequestFactory requestFactory, ResponseFactory responseFactory,
|
public void passByBytes(RequestFactory requestFactory, ResponseFactory responseFactory,
|
||||||
long iters) {
|
long iters) throws IOException {
|
||||||
|
|
||||||
ByteBuffer requestBytes = ByteBuffer.allocate(SCRATCH_SIZE * 8);
|
ByteBuffer requestBytes = ByteBuffer.allocate(SCRATCH_SIZE * 8);
|
||||||
ByteBuffer responseBytes = ByteBuffer.allocate(SCRATCH_SIZE * 8);
|
ByteBuffer responseBytes = ByteBuffer.allocate(SCRATCH_SIZE * 8);
|
||||||
|
@ -52,8 +53,9 @@ public abstract class TestCase<RequestFactory extends StructFactory<RequestBuild
|
||||||
|
|
||||||
{
|
{
|
||||||
org.capnproto.ByteBufferWritableByteChannel writer = new org.capnproto.ByteBufferWritableByteChannel(requestBytes);
|
org.capnproto.ByteBufferWritableByteChannel writer = new org.capnproto.ByteBufferWritableByteChannel(requestBytes);
|
||||||
//org.capnproto.writeMessage
|
org.capnproto.Serialize.writeMessage(writer, requestMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
throw new Error("unimplemented");
|
throw new Error("unimplemented");
|
||||||
}
|
}
|
||||||
|
@ -72,6 +74,7 @@ public abstract class TestCase<RequestFactory extends StructFactory<RequestBuild
|
||||||
String compression = args[2];
|
String compression = args[2];
|
||||||
long iters = Long.parseLong(args[3]);
|
long iters = Long.parseLong(args[3]);
|
||||||
|
|
||||||
|
try {
|
||||||
if (mode.equals("object")) {
|
if (mode.equals("object")) {
|
||||||
passByObject(requestFactory, responseFactory, iters);
|
passByObject(requestFactory, responseFactory, iters);
|
||||||
} else if (mode.equals("bytes")) {
|
} else if (mode.equals("bytes")) {
|
||||||
|
@ -79,5 +82,8 @@ public abstract class TestCase<RequestFactory extends StructFactory<RequestBuild
|
||||||
} else {
|
} else {
|
||||||
System.out.println("unknown mode: " + mode);
|
System.out.println("unknown mode: " + mode);
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("IOException: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.channels.GatheringByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
public final class Serialize {
|
public final class Serialize {
|
||||||
|
|
||||||
static boolean hasRemaining(ByteBuffer[] buffers) {
|
public static void writeMessage(WritableByteChannel outputChannel,
|
||||||
for (ByteBuffer buffer : buffers) {
|
|
||||||
if (buffer.hasRemaining()) { return true; }
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeMessage(GatheringByteChannel outputChannel,
|
|
||||||
MessageBuilder message) throws IOException {
|
MessageBuilder message) throws IOException {
|
||||||
ByteBuffer[] segments = message.getSegmentsForOutput();
|
ByteBuffer[] segments = message.getSegmentsForOutput();
|
||||||
int tableSize = (segments.length + 2) & (~1);
|
int tableSize = (segments.length + 2) & (~1);
|
||||||
|
@ -33,9 +26,10 @@ public final class Serialize {
|
||||||
outputChannel.write(table);
|
outputChannel.write(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (hasRemaining(segments)) {
|
for (ByteBuffer buffer : segments) {
|
||||||
outputChannel.write(segments);
|
while(buffer.hasRemaining()) {
|
||||||
// TODO check for results of 0 or -1.
|
outputChannel.write(buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue