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

26 lines
744 B
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() {
this.arena = new BuilderArena();
}
public <T> T getRoot(FromStructBuilder<T> factory) {
throw new Error("unimplemented");
}
public <T> T initRoot(FromStructBuilder<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");
}
AnyPointer.Builder ptr = new AnyPointer.Builder(PointerBuilder.getRoot(rootSegment, location));
return ptr.initAsStruct(factory);
}
}