diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index 3e3ec1a..a787b51 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -1152,7 +1152,7 @@ private: spaces(indent), " public static final org.capnproto.StructSize STRUCT_SIZE =\n", spaces(indent), " new org.capnproto.StructSize((short)", structNode.getDataWordCount(), ",(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 {\n", spaces(indent), diff --git a/runtime/src/main/java/org/capnproto/DataList.java b/runtime/src/main/java/org/capnproto/DataList.java index 6305cb0..24af979 100644 --- a/runtime/src/main/java/org/capnproto/DataList.java +++ b/runtime/src/main/java/org/capnproto/DataList.java @@ -23,7 +23,7 @@ package org.capnproto; public final class DataList { public static final class Factory extends ListFactory { - Factory() {super (FieldSize.POINTER); } + Factory() {super (ElementSize.POINTER); } public final Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, diff --git a/runtime/src/main/java/org/capnproto/FieldSize.java b/runtime/src/main/java/org/capnproto/ElementSize.java similarity index 98% rename from runtime/src/main/java/org/capnproto/FieldSize.java rename to runtime/src/main/java/org/capnproto/ElementSize.java index 791c394..a145d93 100644 --- a/runtime/src/main/java/org/capnproto/FieldSize.java +++ b/runtime/src/main/java/org/capnproto/ElementSize.java @@ -21,7 +21,7 @@ package org.capnproto; -public final class FieldSize { +public final class ElementSize { public static final byte VOID = 0; public static final byte BIT = 1; public static final byte BYTE = 2; diff --git a/runtime/src/main/java/org/capnproto/EnumList.java b/runtime/src/main/java/org/capnproto/EnumList.java index df73c68..3e90f3f 100644 --- a/runtime/src/main/java/org/capnproto/EnumList.java +++ b/runtime/src/main/java/org/capnproto/EnumList.java @@ -34,7 +34,7 @@ public class EnumList { public final T values[]; public Factory(T values[]) { - super(FieldSize.TWO_BYTES); + super(ElementSize.TWO_BYTES); this.values = values; } public final Reader constructReader(SegmentReader segment, diff --git a/runtime/src/main/java/org/capnproto/ListList.java b/runtime/src/main/java/org/capnproto/ListList.java index b933a9e..53a2b5f 100644 --- a/runtime/src/main/java/org/capnproto/ListList.java +++ b/runtime/src/main/java/org/capnproto/ListList.java @@ -28,7 +28,7 @@ public final class ListList { public final ListFactory factory; public Factory(ListFactory factory) { - super(FieldSize.POINTER); + super(ElementSize.POINTER); this.factory = factory; } diff --git a/runtime/src/main/java/org/capnproto/ListPointer.java b/runtime/src/main/java/org/capnproto/ListPointer.java index feee75a..c73f25b 100644 --- a/runtime/src/main/java/org/capnproto/ListPointer.java +++ b/runtime/src/main/java/org/capnproto/ListPointer.java @@ -45,6 +45,6 @@ final class ListPointer { public static void setInlineComposite(ByteBuffer buffer, int offset, int wordCount) { // TODO length assertion buffer.putInt(8 * offset + 4, - (wordCount << 3) | FieldSize.INLINE_COMPOSITE); + (wordCount << 3) | ElementSize.INLINE_COMPOSITE); } } diff --git a/runtime/src/main/java/org/capnproto/PrimitiveList.java b/runtime/src/main/java/org/capnproto/PrimitiveList.java index 0a6030c..1bb9bd3 100644 --- a/runtime/src/main/java/org/capnproto/PrimitiveList.java +++ b/runtime/src/main/java/org/capnproto/PrimitiveList.java @@ -24,7 +24,7 @@ package org.capnproto; public class PrimitiveList { public static class Void { public static final class Factory extends ListFactory { - Factory() {super (FieldSize.VOID); } + Factory() {super (ElementSize.VOID); } public final Reader constructReader(SegmentReader segment, int ptr, @@ -69,7 +69,7 @@ public class PrimitiveList { public static class Boolean { public static final class Factory extends ListFactory { - Factory() {super (FieldSize.BIT); } + Factory() {super (ElementSize.BIT); } public final Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, @@ -120,7 +120,7 @@ public class PrimitiveList { public static class Byte { public static final class Factory extends ListFactory { - Factory() {super (FieldSize.BYTE); } + Factory() {super (ElementSize.BYTE); } public final Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, @@ -172,7 +172,7 @@ public class PrimitiveList { public static class Short { public static final class Factory extends ListFactory { - Factory() {super (FieldSize.TWO_BYTES); } + Factory() {super (ElementSize.TWO_BYTES); } public final Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, @@ -225,7 +225,7 @@ public class PrimitiveList { public static class Int { public static final class Factory extends ListFactory { - Factory() {super (FieldSize.FOUR_BYTES); } + Factory() {super (ElementSize.FOUR_BYTES); } public final Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, @@ -277,7 +277,7 @@ public class PrimitiveList { public static class Float { public static final class Factory extends ListFactory { - Factory() {super (FieldSize.FOUR_BYTES); } + Factory() {super (ElementSize.FOUR_BYTES); } public final Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, @@ -329,7 +329,7 @@ public class PrimitiveList { public static class Long { public static final class Factory extends ListFactory { - Factory() {super (FieldSize.EIGHT_BYTES); } + Factory() {super (ElementSize.EIGHT_BYTES); } public final Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, @@ -380,7 +380,7 @@ public class PrimitiveList { public static class Double { public static final class Factory extends ListFactory { - Factory() {super (FieldSize.EIGHT_BYTES); } + Factory() {super (ElementSize.EIGHT_BYTES); } public final Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, diff --git a/runtime/src/main/java/org/capnproto/StructList.java b/runtime/src/main/java/org/capnproto/StructList.java index 500733d..68150a9 100644 --- a/runtime/src/main/java/org/capnproto/StructList.java +++ b/runtime/src/main/java/org/capnproto/StructList.java @@ -28,7 +28,7 @@ public final class StructList { public final StructFactory factory; public Factory(StructFactory factory) { - super(FieldSize.INLINE_COMPOSITE); + super(ElementSize.INLINE_COMPOSITE); this.factory = factory; } diff --git a/runtime/src/main/java/org/capnproto/TextList.java b/runtime/src/main/java/org/capnproto/TextList.java index aa802aa..6167dd1 100644 --- a/runtime/src/main/java/org/capnproto/TextList.java +++ b/runtime/src/main/java/org/capnproto/TextList.java @@ -23,7 +23,7 @@ package org.capnproto; public final class TextList { public static final class Factory extends ListFactory { - Factory() {super (FieldSize.POINTER); } + Factory() {super (ElementSize.POINTER); } public final Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, diff --git a/runtime/src/main/java/org/capnproto/WireHelpers.java b/runtime/src/main/java/org/capnproto/WireHelpers.java index ca19638..db527e4 100644 --- a/runtime/src/main/java/org/capnproto/WireHelpers.java +++ b/runtime/src/main/java/org/capnproto/WireHelpers.java @@ -214,10 +214,10 @@ final class WireHelpers { SegmentBuilder segment, int elementCount, 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 pointerCount = FieldSize.pointersPerElement(elementSize); + int dataSize = ElementSize.dataBitsPerElement(elementSize); + int pointerCount = ElementSize.pointersPerElement(elementSize); int step = dataSize + pointerCount * Constants.BITS_PER_POINTER; int wordCount = roundBitsUpToWords((long)elementCount * (long)step); AllocateResult allocation = allocate(refOffset, segment, wordCount, WirePointer.LIST); @@ -234,7 +234,7 @@ final class WireHelpers { SegmentBuilder segment, int elementCount, StructSize elementSize) { - if (elementSize.preferredListEncoding != FieldSize.INLINE_COMPOSITE) { + if (elementSize.preferredListEncoding != ElementSize.INLINE_COMPOSITE) { //# Small data-only struct. Allocate a list of primitives instead. return initListPointer(factory, refOffset, segment, elementCount, elementSize.preferredListEncoding); @@ -265,7 +265,7 @@ final class WireHelpers { byte elementSize, SegmentReader defaultSegment, 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); int origRefTarget = WirePointer.target(origRefOffset, origRef); @@ -288,7 +288,7 @@ final class WireHelpers { byte oldSize = ListPointer.elementSize(resolved.ref); - if (oldSize == FieldSize.INLINE_COMPOSITE) { + if (oldSize == ElementSize.INLINE_COMPOSITE) { //# The existing element size is InlineComposite, which //# means that it is at least two words, which makes it //# bigger than the expected element size. Since fields can @@ -299,13 +299,13 @@ final class WireHelpers { //# from what we expected. throw new Error("unimplemented"); } else { - int dataSize = FieldSize.dataBitsPerElement(oldSize); - int pointerCount = FieldSize.pointersPerElement(oldSize); + int dataSize = ElementSize.dataBitsPerElement(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."); } - if (pointerCount < FieldSize.pointersPerElement(elementSize)) { + if (pointerCount < ElementSize.pointersPerElement(elementSize)) { throw new DecodeException("Existing list value is incompatible with expected type."); } @@ -338,7 +338,7 @@ final class WireHelpers { WirePointer.LIST); //# 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); } @@ -382,7 +382,7 @@ final class WireHelpers { if (WirePointer.kind(resolved.ref) != WirePointer.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( "Called getText{Field,Element} but existing list pointer is not byte-sized."); } @@ -403,7 +403,7 @@ final class WireHelpers { WirePointer.LIST); //# 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); } @@ -446,7 +446,7 @@ final class WireHelpers { if (WirePointer.kind(resolved.ref) != WirePointer.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( "Called getData{Field,Element} but existing list pointer is not byte-sized."); } @@ -512,7 +512,7 @@ final class WireHelpers { if (value.structPointerCount == 1) { //# 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) { //copyPointer(segment); } @@ -555,7 +555,7 @@ final class WireHelpers { if (nestingLimit <= 0) { 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); //long tag = } else { @@ -598,7 +598,7 @@ final class WireHelpers { FollowFarsResult resolved = followFars(ref, refTarget, segment); switch (ListPointer.elementSize(resolved.ref)) { - case FieldSize.INLINE_COMPOSITE : { + case ElementSize.INLINE_COMPOSITE : { int wordCount = ListPointer.inlineCompositeWordCount(resolved.ref); 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 //# need to compute the data size and pointer count for //# such structs. - int dataSize = FieldSize.dataBitsPerElement(ListPointer.elementSize(resolved.ref)); - int pointerCount = FieldSize.pointersPerElement(ListPointer.elementSize(resolved.ref)); + int dataSize = ElementSize.dataBitsPerElement(ListPointer.elementSize(resolved.ref)); + int pointerCount = ElementSize.pointersPerElement(ListPointer.elementSize(resolved.ref)); int step = dataSize + pointerCount * Constants.BITS_PER_POINTER; resolved.segment.arena.checkReadLimit( @@ -642,8 +642,8 @@ final class WireHelpers { //# case where we expected a list of some primitive or //# pointer type. - int expectedDataBitsPerElement = FieldSize.dataBitsPerElement(expectedElementSize); - int expectedPointersPerElement = FieldSize.pointersPerElement(expectedElementSize); + int expectedDataBitsPerElement = ElementSize.dataBitsPerElement(expectedElementSize); + int expectedPointersPerElement = ElementSize.pointersPerElement(expectedElementSize); if (expectedDataBitsPerElement > dataSize) { 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."); } - 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."); } @@ -728,7 +728,7 @@ final class WireHelpers { 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."); } diff --git a/runtime/src/test/scala/org/capnproto/LayoutTest.scala b/runtime/src/test/scala/org/capnproto/LayoutTest.scala index f44d06a..b5593c7 100644 --- a/runtime/src/test/scala/org/capnproto/LayoutTest.scala +++ b/runtime/src/test/scala/org/capnproto/LayoutTest.scala @@ -137,7 +137,7 @@ class LayoutSuite extends FunSuite { val segment = new SegmentBuilder(buffer, new BuilderArena(BuilderArena.SUGGESTED_FIRST_SEGMENT_WORDS, 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()); setupStruct(builder); checkStruct(builder);