FieldSize -> ElementSize

This commit is contained in:
David Renshaw 2014-10-11 09:25:31 -04:00
parent 40fc0193c2
commit c941f5960f
11 changed files with 40 additions and 40 deletions

View file

@ -1152,7 +1152,7 @@ private:
spaces(indent), " public static final org.capnproto.StructSize STRUCT_SIZE =\n", spaces(indent), " public static final org.capnproto.StructSize STRUCT_SIZE =\n",
spaces(indent), " new org.capnproto.StructSize((short)", structNode.getDataWordCount(), spaces(indent), " new org.capnproto.StructSize((short)", structNode.getDataWordCount(),
",(short)", structNode.getPointerCount(), ",(short)", structNode.getPointerCount(),
", org.capnproto.FieldSize.", FIELD_SIZE_NAMES[(int)structNode.getPreferredListEncoding()], ");\n"), ", org.capnproto.ElementSize.", FIELD_SIZE_NAMES[(int)structNode.getPreferredListEncoding()], ");\n"),
spaces(indent), " public static final class Factory extends org.capnproto.StructFactory<Builder, Reader> {\n", spaces(indent), " public static final class Factory extends org.capnproto.StructFactory<Builder, Reader> {\n",
spaces(indent), spaces(indent),

View file

@ -23,7 +23,7 @@ package org.capnproto;
public final class DataList { public final class DataList {
public static final class Factory extends ListFactory<Builder, Reader> { public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (FieldSize.POINTER); } Factory() {super (ElementSize.POINTER); }
public final Reader constructReader(SegmentReader segment, public final Reader constructReader(SegmentReader segment,
int ptr, int ptr,
int elementCount, int step, int elementCount, int step,

View file

@ -21,7 +21,7 @@
package org.capnproto; package org.capnproto;
public final class FieldSize { public final class ElementSize {
public static final byte VOID = 0; public static final byte VOID = 0;
public static final byte BIT = 1; public static final byte BIT = 1;
public static final byte BYTE = 2; public static final byte BYTE = 2;

View file

@ -34,7 +34,7 @@ public class EnumList {
public final T values[]; public final T values[];
public Factory(T values[]) { public Factory(T values[]) {
super(FieldSize.TWO_BYTES); super(ElementSize.TWO_BYTES);
this.values = values; this.values = values;
} }
public final Reader<T> constructReader(SegmentReader segment, public final Reader<T> constructReader(SegmentReader segment,

View file

@ -28,7 +28,7 @@ public final class ListList {
public final ListFactory<ElementBuilder, ElementReader> factory; public final ListFactory<ElementBuilder, ElementReader> factory;
public Factory(ListFactory<ElementBuilder, ElementReader> factory) { public Factory(ListFactory<ElementBuilder, ElementReader> factory) {
super(FieldSize.POINTER); super(ElementSize.POINTER);
this.factory = factory; this.factory = factory;
} }

View file

@ -45,6 +45,6 @@ final class ListPointer {
public static void setInlineComposite(ByteBuffer buffer, int offset, int wordCount) { public static void setInlineComposite(ByteBuffer buffer, int offset, int wordCount) {
// TODO length assertion // TODO length assertion
buffer.putInt(8 * offset + 4, buffer.putInt(8 * offset + 4,
(wordCount << 3) | FieldSize.INLINE_COMPOSITE); (wordCount << 3) | ElementSize.INLINE_COMPOSITE);
} }
} }

View file

@ -24,7 +24,7 @@ package org.capnproto;
public class PrimitiveList { public class PrimitiveList {
public static class Void { public static class Void {
public static final class Factory extends ListFactory<Builder, Reader> { public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (FieldSize.VOID); } Factory() {super (ElementSize.VOID); }
public final Reader constructReader(SegmentReader segment, public final Reader constructReader(SegmentReader segment,
int ptr, int ptr,
@ -69,7 +69,7 @@ public class PrimitiveList {
public static class Boolean { public static class Boolean {
public static final class Factory extends ListFactory<Builder, Reader> { public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (FieldSize.BIT); } Factory() {super (ElementSize.BIT); }
public final Reader constructReader(SegmentReader segment, public final Reader constructReader(SegmentReader segment,
int ptr, int ptr,
int elementCount, int step, int elementCount, int step,
@ -120,7 +120,7 @@ public class PrimitiveList {
public static class Byte { public static class Byte {
public static final class Factory extends ListFactory<Builder, Reader> { public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (FieldSize.BYTE); } Factory() {super (ElementSize.BYTE); }
public final Reader constructReader(SegmentReader segment, public final Reader constructReader(SegmentReader segment,
int ptr, int ptr,
int elementCount, int step, int elementCount, int step,
@ -172,7 +172,7 @@ public class PrimitiveList {
public static class Short { public static class Short {
public static final class Factory extends ListFactory<Builder, Reader> { public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (FieldSize.TWO_BYTES); } Factory() {super (ElementSize.TWO_BYTES); }
public final Reader constructReader(SegmentReader segment, public final Reader constructReader(SegmentReader segment,
int ptr, int ptr,
int elementCount, int step, int elementCount, int step,
@ -225,7 +225,7 @@ public class PrimitiveList {
public static class Int { public static class Int {
public static final class Factory extends ListFactory<Builder, Reader> { public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (FieldSize.FOUR_BYTES); } Factory() {super (ElementSize.FOUR_BYTES); }
public final Reader constructReader(SegmentReader segment, public final Reader constructReader(SegmentReader segment,
int ptr, int ptr,
int elementCount, int step, int elementCount, int step,
@ -277,7 +277,7 @@ public class PrimitiveList {
public static class Float { public static class Float {
public static final class Factory extends ListFactory<Builder, Reader> { public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (FieldSize.FOUR_BYTES); } Factory() {super (ElementSize.FOUR_BYTES); }
public final Reader constructReader(SegmentReader segment, public final Reader constructReader(SegmentReader segment,
int ptr, int ptr,
int elementCount, int step, int elementCount, int step,
@ -329,7 +329,7 @@ public class PrimitiveList {
public static class Long { public static class Long {
public static final class Factory extends ListFactory<Builder, Reader> { public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (FieldSize.EIGHT_BYTES); } Factory() {super (ElementSize.EIGHT_BYTES); }
public final Reader constructReader(SegmentReader segment, public final Reader constructReader(SegmentReader segment,
int ptr, int ptr,
int elementCount, int step, int elementCount, int step,
@ -380,7 +380,7 @@ public class PrimitiveList {
public static class Double { public static class Double {
public static final class Factory extends ListFactory<Builder, Reader> { public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (FieldSize.EIGHT_BYTES); } Factory() {super (ElementSize.EIGHT_BYTES); }
public final Reader constructReader(SegmentReader segment, public final Reader constructReader(SegmentReader segment,
int ptr, int ptr,
int elementCount, int step, int elementCount, int step,

View file

@ -28,7 +28,7 @@ public final class StructList {
public final StructFactory<ElementBuilder, ElementReader> factory; public final StructFactory<ElementBuilder, ElementReader> factory;
public Factory(StructFactory<ElementBuilder, ElementReader> factory) { public Factory(StructFactory<ElementBuilder, ElementReader> factory) {
super(FieldSize.INLINE_COMPOSITE); super(ElementSize.INLINE_COMPOSITE);
this.factory = factory; this.factory = factory;
} }

View file

@ -23,7 +23,7 @@ package org.capnproto;
public final class TextList { public final class TextList {
public static final class Factory extends ListFactory<Builder, Reader> { public static final class Factory extends ListFactory<Builder, Reader> {
Factory() {super (FieldSize.POINTER); } Factory() {super (ElementSize.POINTER); }
public final Reader constructReader(SegmentReader segment, public final Reader constructReader(SegmentReader segment,
int ptr, int ptr,
int elementCount, int step, int elementCount, int step,

View file

@ -214,10 +214,10 @@ final class WireHelpers {
SegmentBuilder segment, SegmentBuilder segment,
int elementCount, int elementCount,
byte elementSize) { byte elementSize) {
assert elementSize != FieldSize.INLINE_COMPOSITE : "Should have called initStructListPointer instead"; assert elementSize != ElementSize.INLINE_COMPOSITE : "Should have called initStructListPointer instead";
int dataSize = FieldSize.dataBitsPerElement(elementSize); int dataSize = ElementSize.dataBitsPerElement(elementSize);
int pointerCount = FieldSize.pointersPerElement(elementSize); int pointerCount = ElementSize.pointersPerElement(elementSize);
int step = dataSize + pointerCount * Constants.BITS_PER_POINTER; int step = dataSize + pointerCount * Constants.BITS_PER_POINTER;
int wordCount = roundBitsUpToWords((long)elementCount * (long)step); int wordCount = roundBitsUpToWords((long)elementCount * (long)step);
AllocateResult allocation = allocate(refOffset, segment, wordCount, WirePointer.LIST); AllocateResult allocation = allocate(refOffset, segment, wordCount, WirePointer.LIST);
@ -234,7 +234,7 @@ final class WireHelpers {
SegmentBuilder segment, SegmentBuilder segment,
int elementCount, int elementCount,
StructSize elementSize) { StructSize elementSize) {
if (elementSize.preferredListEncoding != FieldSize.INLINE_COMPOSITE) { if (elementSize.preferredListEncoding != ElementSize.INLINE_COMPOSITE) {
//# Small data-only struct. Allocate a list of primitives instead. //# Small data-only struct. Allocate a list of primitives instead.
return initListPointer(factory, refOffset, segment, elementCount, return initListPointer(factory, refOffset, segment, elementCount,
elementSize.preferredListEncoding); elementSize.preferredListEncoding);
@ -265,7 +265,7 @@ final class WireHelpers {
byte elementSize, byte elementSize,
SegmentReader defaultSegment, SegmentReader defaultSegment,
int defaultOffset) { int defaultOffset) {
assert elementSize != FieldSize.INLINE_COMPOSITE : "Use getStructList{Element,Field} for structs"; assert elementSize != ElementSize.INLINE_COMPOSITE : "Use getStructList{Element,Field} for structs";
long origRef = WirePointer.get(origSegment.buffer, origRefOffset); long origRef = WirePointer.get(origSegment.buffer, origRefOffset);
int origRefTarget = WirePointer.target(origRefOffset, origRef); int origRefTarget = WirePointer.target(origRefOffset, origRef);
@ -288,7 +288,7 @@ final class WireHelpers {
byte oldSize = ListPointer.elementSize(resolved.ref); byte oldSize = ListPointer.elementSize(resolved.ref);
if (oldSize == FieldSize.INLINE_COMPOSITE) { if (oldSize == ElementSize.INLINE_COMPOSITE) {
//# The existing element size is InlineComposite, which //# The existing element size is InlineComposite, which
//# means that it is at least two words, which makes it //# means that it is at least two words, which makes it
//# bigger than the expected element size. Since fields can //# bigger than the expected element size. Since fields can
@ -299,13 +299,13 @@ final class WireHelpers {
//# from what we expected. //# from what we expected.
throw new Error("unimplemented"); throw new Error("unimplemented");
} else { } else {
int dataSize = FieldSize.dataBitsPerElement(oldSize); int dataSize = ElementSize.dataBitsPerElement(oldSize);
int pointerCount = FieldSize.pointersPerElement(oldSize); int pointerCount = ElementSize.pointersPerElement(oldSize);
if (dataSize < FieldSize.dataBitsPerElement(elementSize)) { if (dataSize < ElementSize.dataBitsPerElement(elementSize)) {
throw new DecodeException("Existing list value is incompatible with expected type."); throw new DecodeException("Existing list value is incompatible with expected type.");
} }
if (pointerCount < FieldSize.pointersPerElement(elementSize)) { if (pointerCount < ElementSize.pointersPerElement(elementSize)) {
throw new DecodeException("Existing list value is incompatible with expected type."); throw new DecodeException("Existing list value is incompatible with expected type.");
} }
@ -338,7 +338,7 @@ final class WireHelpers {
WirePointer.LIST); WirePointer.LIST);
//# Initialize the pointer. //# Initialize the pointer.
ListPointer.set(allocation.segment.buffer, allocation.refOffset, FieldSize.BYTE, byteSize); ListPointer.set(allocation.segment.buffer, allocation.refOffset, ElementSize.BYTE, byteSize);
return new Text.Builder(allocation.segment.buffer, allocation.ptr * Constants.BYTES_PER_WORD, size); return new Text.Builder(allocation.segment.buffer, allocation.ptr * Constants.BYTES_PER_WORD, size);
} }
@ -382,7 +382,7 @@ final class WireHelpers {
if (WirePointer.kind(resolved.ref) != WirePointer.LIST) { if (WirePointer.kind(resolved.ref) != WirePointer.LIST) {
throw new DecodeException("Called getText{Field,Element} but existing pointer is not a list."); throw new DecodeException("Called getText{Field,Element} but existing pointer is not a list.");
} }
if (ListPointer.elementSize(resolved.ref) != FieldSize.BYTE) { if (ListPointer.elementSize(resolved.ref) != ElementSize.BYTE) {
throw new DecodeException( throw new DecodeException(
"Called getText{Field,Element} but existing list pointer is not byte-sized."); "Called getText{Field,Element} but existing list pointer is not byte-sized.");
} }
@ -403,7 +403,7 @@ final class WireHelpers {
WirePointer.LIST); WirePointer.LIST);
//# Initialize the pointer. //# Initialize the pointer.
ListPointer.set(allocation.segment.buffer, allocation.refOffset, FieldSize.BYTE, size); ListPointer.set(allocation.segment.buffer, allocation.refOffset, ElementSize.BYTE, size);
return new Data.Builder(allocation.segment.buffer, allocation.ptr * Constants.BYTES_PER_WORD, size); return new Data.Builder(allocation.segment.buffer, allocation.ptr * Constants.BYTES_PER_WORD, size);
} }
@ -446,7 +446,7 @@ final class WireHelpers {
if (WirePointer.kind(resolved.ref) != WirePointer.LIST) { if (WirePointer.kind(resolved.ref) != WirePointer.LIST) {
throw new DecodeException("Called getData{Field,Element} but existing pointer is not a list."); throw new DecodeException("Called getData{Field,Element} but existing pointer is not a list.");
} }
if (ListPointer.elementSize(resolved.ref) != FieldSize.BYTE) { if (ListPointer.elementSize(resolved.ref) != ElementSize.BYTE) {
throw new DecodeException( throw new DecodeException(
"Called getData{Field,Element} but existing list pointer is not byte-sized."); "Called getData{Field,Element} but existing list pointer is not byte-sized.");
} }
@ -512,7 +512,7 @@ final class WireHelpers {
if (value.structPointerCount == 1) { if (value.structPointerCount == 1) {
//# List of pointers. //# List of pointers.
ListPointer.set(allocation.segment.buffer, allocation.refOffset, FieldSize.POINTER, value.elementCount); ListPointer.set(allocation.segment.buffer, allocation.refOffset, ElementSize.POINTER, value.elementCount);
for (int i = 0; i < value.elementCount; ++i) { for (int i = 0; i < value.elementCount; ++i) {
//copyPointer(segment); //copyPointer(segment);
} }
@ -555,7 +555,7 @@ final class WireHelpers {
if (nestingLimit <= 0) { if (nestingLimit <= 0) {
throw new DecodeException("Message is too deeply nested or contains cycles. See org.capnproto.ReaderOptions."); throw new DecodeException("Message is too deeply nested or contains cycles. See org.capnproto.ReaderOptions.");
} }
if (elementSize == FieldSize.INLINE_COMPOSITE) { if (elementSize == ElementSize.INLINE_COMPOSITE) {
int wordCount = ListPointer.inlineCompositeWordCount(resolved.ref); int wordCount = ListPointer.inlineCompositeWordCount(resolved.ref);
//long tag = //long tag =
} else { } else {
@ -598,7 +598,7 @@ final class WireHelpers {
FollowFarsResult resolved = followFars(ref, refTarget, segment); FollowFarsResult resolved = followFars(ref, refTarget, segment);
switch (ListPointer.elementSize(resolved.ref)) { switch (ListPointer.elementSize(resolved.ref)) {
case FieldSize.INLINE_COMPOSITE : { case ElementSize.INLINE_COMPOSITE : {
int wordCount = ListPointer.inlineCompositeWordCount(resolved.ref); int wordCount = ListPointer.inlineCompositeWordCount(resolved.ref);
long tag = WirePointer.get(resolved.segment.buffer, resolved.ptr); long tag = WirePointer.get(resolved.segment.buffer, resolved.ptr);
@ -627,8 +627,8 @@ final class WireHelpers {
//# lists can also be interpreted as struct lists. We //# lists can also be interpreted as struct lists. We
//# need to compute the data size and pointer count for //# need to compute the data size and pointer count for
//# such structs. //# such structs.
int dataSize = FieldSize.dataBitsPerElement(ListPointer.elementSize(resolved.ref)); int dataSize = ElementSize.dataBitsPerElement(ListPointer.elementSize(resolved.ref));
int pointerCount = FieldSize.pointersPerElement(ListPointer.elementSize(resolved.ref)); int pointerCount = ElementSize.pointersPerElement(ListPointer.elementSize(resolved.ref));
int step = dataSize + pointerCount * Constants.BITS_PER_POINTER; int step = dataSize + pointerCount * Constants.BITS_PER_POINTER;
resolved.segment.arena.checkReadLimit( resolved.segment.arena.checkReadLimit(
@ -642,8 +642,8 @@ final class WireHelpers {
//# case where we expected a list of some primitive or //# case where we expected a list of some primitive or
//# pointer type. //# pointer type.
int expectedDataBitsPerElement = FieldSize.dataBitsPerElement(expectedElementSize); int expectedDataBitsPerElement = ElementSize.dataBitsPerElement(expectedElementSize);
int expectedPointersPerElement = FieldSize.pointersPerElement(expectedElementSize); int expectedPointersPerElement = ElementSize.pointersPerElement(expectedElementSize);
if (expectedDataBitsPerElement > dataSize) { if (expectedDataBitsPerElement > dataSize) {
throw new DecodeException("Message contains list with incompatible element type."); throw new DecodeException("Message contains list with incompatible element type.");
@ -690,7 +690,7 @@ final class WireHelpers {
throw new DecodeException("Message contains non-list pointer where text was expected."); throw new DecodeException("Message contains non-list pointer where text was expected.");
} }
if (ListPointer.elementSize(resolved.ref) != FieldSize.BYTE) { if (ListPointer.elementSize(resolved.ref) != ElementSize.BYTE) {
throw new DecodeException("Message contains list pointer of non-bytes where text was expected."); throw new DecodeException("Message contains list pointer of non-bytes where text was expected.");
} }
@ -728,7 +728,7 @@ final class WireHelpers {
throw new DecodeException("Message contains non-list pointer where data was expected."); throw new DecodeException("Message contains non-list pointer where data was expected.");
} }
if (ListPointer.elementSize(resolved.ref) != FieldSize.BYTE) { if (ListPointer.elementSize(resolved.ref) != ElementSize.BYTE) {
throw new DecodeException("Message contains list pointer of non-bytes where data was expected."); throw new DecodeException("Message contains list pointer of non-bytes where data was expected.");
} }

View file

@ -137,7 +137,7 @@ class LayoutSuite extends FunSuite {
val segment = new SegmentBuilder(buffer, new BuilderArena(BuilderArena.SUGGESTED_FIRST_SEGMENT_WORDS, val segment = new SegmentBuilder(buffer, new BuilderArena(BuilderArena.SUGGESTED_FIRST_SEGMENT_WORDS,
BuilderArena.SUGGESTED_ALLOCATION_STRATEGY)) BuilderArena.SUGGESTED_ALLOCATION_STRATEGY))
val factory = new BareStructBuilder(new StructSize(2, 4, FieldSize.INLINE_COMPOSITE)); val factory = new BareStructBuilder(new StructSize(2, 4, ElementSize.INLINE_COMPOSITE));
val builder = WireHelpers.initStructPointer(factory, 0, segment, factory.structSize()); val builder = WireHelpers.initStructPointer(factory, 0, segment, factory.structSize());
setupStruct(builder); setupStruct(builder);
checkStruct(builder); checkStruct(builder);