capnproto-java-rpc/runtime/src/main/java/org/capnproto/MessageBuilder.java

41 lines
1.4 KiB
Java
Raw Normal View History

package org.capnproto;
public final class MessageBuilder {
2014-05-24 14:12:44 +00:00
private final BuilderArena arena;
public MessageBuilder() {
2014-06-15 18:17:32 +00:00
this.arena = new BuilderArena(BuilderArena.SUGGESTED_FIRST_SEGMENT_WORDS,
BuilderArena.SUGGESTED_ALLOCATION_STRATEGY);
}
public MessageBuilder(int firstSegmentWords) {
this.arena = new BuilderArena(firstSegmentWords,
BuilderArena.SUGGESTED_ALLOCATION_STRATEGY);
}
public MessageBuilder(int firstSegmentWords, BuilderArena.AllocationStrategy allocationStrategy) {
this.arena = new BuilderArena(firstSegmentWords,
allocationStrategy);
2014-05-24 14:12:44 +00:00
}
public <T> T getRoot(StructBuilder.Factory<T> factory) {
throw new Error("unimplemented");
}
2014-10-08 02:35:08 +00:00
public <T> T initRoot(InitFromPointerBuilder<T> factory) {
2014-05-24 14:12:44 +00:00
SegmentBuilder rootSegment = this.arena.segments.get(0);
int location = rootSegment.allocate(1);
if (location == SegmentBuilder.FAILED_ALLOCATION) {
throw new Error("could not allocate root pointer");
}
2014-10-08 16:22:58 +00:00
AnyPointer.Builder ptr = new AnyPointer.Builder(rootSegment, location);
2014-10-08 02:35:08 +00:00
return ptr.initAs(factory);
}
2014-05-24 14:45:55 +00:00
public final java.nio.ByteBuffer[] getSegmentsForOutput() {
return this.arena.getSegmentsForOutput();
}
}