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