2014-05-15 23:05:20 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-10-07 21:47:42 +00:00
|
|
|
public <T> T getRoot(StructBuilder.Factory<T> factory) {
|
2014-05-15 23:05:20 +00:00
|
|
|
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-15 23:05:20 +00:00
|
|
|
}
|
2014-05-24 14:45:55 +00:00
|
|
|
|
2014-05-24 18:33:25 +00:00
|
|
|
public final java.nio.ByteBuffer[] getSegmentsForOutput() {
|
|
|
|
return this.arena.getSegmentsForOutput();
|
|
|
|
}
|
2014-05-15 23:05:20 +00:00
|
|
|
}
|