more MessageBuilder constructors
This commit is contained in:
parent
74fccc9461
commit
0c56671f3c
2 changed files with 30 additions and 3 deletions
|
@ -6,12 +6,28 @@ import java.util.Vector;
|
||||||
|
|
||||||
public final class BuilderArena implements Arena {
|
public final class BuilderArena implements Arena {
|
||||||
|
|
||||||
|
public enum AllocationStrategy {
|
||||||
|
FIXED_SIZE,
|
||||||
|
GROW_HEURISTICALLY
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final int SUGGESTED_FIRST_SEGMENT_WORDS = 1024;
|
||||||
|
public static final AllocationStrategy SUGGESTED_ALLOCATION_STRATEGY =
|
||||||
|
AllocationStrategy.GROW_HEURISTICALLY;
|
||||||
|
|
||||||
// Maybe this should be ArrayList?
|
// Maybe this should be ArrayList?
|
||||||
public final Vector<SegmentBuilder> segments;
|
public final Vector<SegmentBuilder> segments;
|
||||||
|
|
||||||
public BuilderArena() {
|
public int nextSize;
|
||||||
|
public final AllocationStrategy allocationStrategy;
|
||||||
|
|
||||||
|
|
||||||
|
public BuilderArena(int firstSegmentSizeWords, AllocationStrategy allocationStrategy) {
|
||||||
this.segments = new Vector<SegmentBuilder>();
|
this.segments = new Vector<SegmentBuilder>();
|
||||||
SegmentBuilder segment0 = new SegmentBuilder(ByteBuffer.allocate(1024 * 8));
|
this.nextSize = firstSegmentSizeWords;
|
||||||
|
this.allocationStrategy = allocationStrategy;
|
||||||
|
SegmentBuilder segment0 = new SegmentBuilder(
|
||||||
|
ByteBuffer.allocate(firstSegmentSizeWords * Constants.BYTES_PER_WORD));
|
||||||
segment0.buffer.mark();
|
segment0.buffer.mark();
|
||||||
segment0.buffer.order(ByteOrder.LITTLE_ENDIAN);
|
segment0.buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
this.segments.add(segment0);
|
this.segments.add(segment0);
|
||||||
|
|
|
@ -5,7 +5,18 @@ public final class MessageBuilder {
|
||||||
private final BuilderArena arena;
|
private final BuilderArena arena;
|
||||||
|
|
||||||
public MessageBuilder() {
|
public MessageBuilder() {
|
||||||
this.arena = new BuilderArena();
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getRoot(FromStructBuilder<T> factory) {
|
public <T> T getRoot(FromStructBuilder<T> factory) {
|
||||||
|
|
Loading…
Reference in a new issue