hm. we may need to implement GatheringByteChannel

This commit is contained in:
David Renshaw 2014-09-03 15:06:22 -04:00
parent b0998afc3e
commit 5d2b5df2b9
2 changed files with 50 additions and 0 deletions

View file

@ -1,5 +1,7 @@
package org.capnproto.benchmark;
import java.nio.ByteBuffer;
import org.capnproto.FromStructReader;
import org.capnproto.FromStructBuilder;
import org.capnproto.StructFactory;
@ -32,14 +34,26 @@ public abstract class TestCase<RequestFactory extends StructFactory<RequestBuild
}
}
static final int SCRATCH_SIZE = 128 * 1024;
public void passByBytes(RequestFactory requestFactory, ResponseFactory responseFactory,
long iters) {
ByteBuffer requestBytes = ByteBuffer.allocate(SCRATCH_SIZE * 8);
ByteBuffer responseBytes = ByteBuffer.allocate(SCRATCH_SIZE * 8);
Common.FastRand rng = new Common.FastRand();
for (int i = 0; i < iters; ++i) {
MessageBuilder requestMessage = new MessageBuilder();
MessageBuilder responseMessage = new MessageBuilder();
RequestBuilder request = requestMessage.initRoot(requestFactory);
Expectation expected = this.setupRequest(rng, request);
ResponseBuilder response = responseMessage.initRoot(responseFactory);
{
org.capnproto.ByteBufferWritableByteChannel writer = new org.capnproto.ByteBufferWritableByteChannel(requestBytes);
//org.capnproto.writeMessage
}
// TODO
throw new Error("unimplemented");
}

View file

@ -0,0 +1,36 @@
package org.capnproto;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
public final class ByteBufferWritableByteChannel implements BufferedWritableByteChannel {
public final ByteBuffer buf;
public ByteBufferWritableByteChannel(ByteBuffer buf) {
this.buf = buf;
}
public final int write(ByteBuffer src) throws IOException {
int available = this.buf.remaining();
int size = src.remaining();
if (available < size) {
throw new IOException("backing buffer was not large enough");
}
this.buf.put(src);
return size;
}
public final ByteBuffer getWriteBuffer() {
return this.buf;
}
public final void close() throws IOException {
return;
}
public final boolean isOpen() {
return true;
}
}