setStruct and visibility
This commit is contained in:
parent
27b58afe46
commit
a3f3c88e35
6 changed files with 92 additions and 85 deletions
|
@ -964,7 +964,7 @@ private:
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final void set", titleCase, "(", type, ".Reader value) {\n",
|
spaces(indent), " public final void set", titleCase, "(", type, ".Reader value) {\n",
|
||||||
unionDiscrim.set,
|
unionDiscrim.set,
|
||||||
spaces(indent), " throw new Error();\n",
|
spaces(indent), " _builder.getPointerField(", offset, ").setStruct(value._reader);\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final ", type, ".Builder init", titleCase, "() {\n",
|
spaces(indent), " public final ", type, ".Builder init", titleCase, "() {\n",
|
||||||
unionDiscrim.set,
|
unionDiscrim.set,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class PointerBuilder {
|
public final class PointerBuilder {
|
||||||
public final SegmentBuilder segment;
|
final SegmentBuilder segment;
|
||||||
public final int pointer; // word offset
|
final int pointer; // word offset
|
||||||
|
|
||||||
public PointerBuilder(SegmentBuilder segment, int pointer) {
|
public PointerBuilder(SegmentBuilder segment, int pointer) {
|
||||||
this.segment = segment;
|
this.segment = segment;
|
||||||
|
@ -68,6 +68,10 @@ public final class PointerBuilder {
|
||||||
return WireHelpers.initStructListPointer(this.pointer, this.segment, elementCount, elementSize);
|
return WireHelpers.initStructListPointer(this.pointer, this.segment, elementCount, elementSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void setStruct(StructReader value) {
|
||||||
|
WireHelpers.setStructPointer(this.segment, this.pointer, value);
|
||||||
|
}
|
||||||
|
|
||||||
public final void setText(Text.Reader value) {
|
public final void setText(Text.Reader value) {
|
||||||
WireHelpers.setTextPointer(this.pointer, this.segment, value);
|
WireHelpers.setTextPointer(this.pointer, this.segment, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class PointerReader {
|
public final class PointerReader {
|
||||||
public final SegmentReader segment;
|
final SegmentReader segment;
|
||||||
public final int pointer; // word offset
|
final int pointer; // word offset
|
||||||
public final int nestingLimit;
|
final int nestingLimit;
|
||||||
|
|
||||||
public PointerReader() {
|
public PointerReader() {
|
||||||
this.segment = null;
|
this.segment = null;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class StructBuilder {
|
public final class StructBuilder {
|
||||||
public final SegmentBuilder segment;
|
final SegmentBuilder segment;
|
||||||
public final int data; // byte offset to data section
|
final int data; // byte offset to data section
|
||||||
public final int pointers; // word offset of pointer section
|
final int pointers; // word offset of pointer section
|
||||||
public final int dataSize; // in bits
|
final int dataSize; // in bits
|
||||||
public final short pointerCount;
|
final short pointerCount;
|
||||||
public final byte bit0Offset;
|
final byte bit0Offset;
|
||||||
|
|
||||||
public StructBuilder(SegmentBuilder segment, int data,
|
public StructBuilder(SegmentBuilder segment, int data,
|
||||||
int pointers, int dataSize, short pointerCount,
|
int pointers, int dataSize, short pointerCount,
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class StructReader {
|
public final class StructReader {
|
||||||
public final SegmentReader segment;
|
final SegmentReader segment;
|
||||||
public final int data; //byte offset to data section
|
final int data; //byte offset to data section
|
||||||
public final int pointers; // word offset of pointer section
|
final int pointers; // word offset of pointer section
|
||||||
public final int dataSize; // in bits
|
final int dataSize; // in bits
|
||||||
public final short pointerCount;
|
final short pointerCount;
|
||||||
public final byte bit0Offset;
|
final byte bit0Offset;
|
||||||
public final int nestingLimit;
|
final int nestingLimit;
|
||||||
|
|
||||||
public StructReader(SegmentReader segment, int data,
|
public StructReader(SegmentReader segment, int data,
|
||||||
int pointers, int dataSize, short pointerCount,
|
int pointers, int dataSize, short pointerCount,
|
||||||
|
|
|
@ -4,11 +4,11 @@ import java.nio.ByteBuffer;
|
||||||
|
|
||||||
final class WireHelpers {
|
final class WireHelpers {
|
||||||
|
|
||||||
public static int roundBytesUpToWords(int bytes) {
|
static int roundBytesUpToWords(int bytes) {
|
||||||
return (bytes + 7) / 8;
|
return (bytes + 7) / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int roundBitsUpToWords(long bits) {
|
static int roundBitsUpToWords(long bits) {
|
||||||
//# This code assumes 64-bit words.
|
//# This code assumes 64-bit words.
|
||||||
return (int)((bits + 63) / ((long) Constants.BITS_PER_WORD));
|
return (int)((bits + 63) / ((long) Constants.BITS_PER_WORD));
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,10 @@ final class WireHelpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AllocateResult allocate(int refOffset,
|
static AllocateResult allocate(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
int amount, // in words
|
int amount, // in words
|
||||||
byte kind) {
|
byte kind) {
|
||||||
|
|
||||||
// TODO check for nullness, amount == 0 case.
|
// TODO check for nullness, amount == 0 case.
|
||||||
|
|
||||||
|
@ -67,8 +67,8 @@ final class WireHelpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FollowBuilderFarsResult followBuilderFars(long ref, int refTarget,
|
static FollowBuilderFarsResult followBuilderFars(long ref, int refTarget,
|
||||||
SegmentBuilder segment) {
|
SegmentBuilder segment) {
|
||||||
//# If `ref` is a far pointer, follow it. On return, `ref` will
|
//# If `ref` is a far pointer, follow it. On return, `ref` will
|
||||||
//# have been updated to point at a WirePointer that contains
|
//# have been updated to point at a WirePointer that contains
|
||||||
//# the type information about the target object, and a pointer
|
//# the type information about the target object, and a pointer
|
||||||
|
@ -109,7 +109,7 @@ final class WireHelpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FollowFarsResult followFars(long ref, int refTarget, SegmentReader segment) {
|
static FollowFarsResult followFars(long ref, int refTarget, SegmentReader segment) {
|
||||||
//# If the segment is null, this is an unchecked message,
|
//# If the segment is null, this is an unchecked message,
|
||||||
//# so there are no FAR pointers.
|
//# so there are no FAR pointers.
|
||||||
if (segment != null && WirePointer.kind(ref) == WirePointer.FAR) {
|
if (segment != null && WirePointer.kind(ref) == WirePointer.FAR) {
|
||||||
|
@ -137,7 +137,7 @@ final class WireHelpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void zeroObject(SegmentBuilder segment, int refOffset) {
|
static void zeroObject(SegmentBuilder segment, int refOffset) {
|
||||||
//# Zero out the pointed-to object. Use when the pointer is
|
//# Zero out the pointed-to object. Use when the pointer is
|
||||||
//# about to be overwritten making the target object no longer
|
//# about to be overwritten making the target object no longer
|
||||||
//# reachable.
|
//# reachable.
|
||||||
|
@ -145,9 +145,9 @@ final class WireHelpers {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StructBuilder initStructPointer(int refOffset,
|
static StructBuilder initStructPointer(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
StructSize size) {
|
StructSize size) {
|
||||||
AllocateResult allocation = allocate(refOffset, segment, size.total(), WirePointer.STRUCT);
|
AllocateResult allocation = allocate(refOffset, segment, size.total(), WirePointer.STRUCT);
|
||||||
StructPointer.setFromStructSize(allocation.segment.buffer, allocation.refOffset, size);
|
StructPointer.setFromStructSize(allocation.segment.buffer, allocation.refOffset, size);
|
||||||
return new StructBuilder(allocation.segment, allocation.ptr * Constants.BYTES_PER_WORD,
|
return new StructBuilder(allocation.segment, allocation.ptr * Constants.BYTES_PER_WORD,
|
||||||
|
@ -155,9 +155,9 @@ final class WireHelpers {
|
||||||
size.data * 64, size.pointers, (byte)0);
|
size.data * 64, size.pointers, (byte)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StructBuilder getWritableStructPointer(int refOffset,
|
static StructBuilder getWritableStructPointer(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
StructSize size) {
|
StructSize size) {
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
int target = WirePointer.target(refOffset, ref);
|
int target = WirePointer.target(refOffset, ref);
|
||||||
if (WirePointer.isNull(ref)) {
|
if (WirePointer.isNull(ref)) {
|
||||||
|
@ -179,10 +179,10 @@ final class WireHelpers {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ListBuilder initListPointer(int refOffset,
|
static ListBuilder initListPointer(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
int elementCount,
|
int elementCount,
|
||||||
byte elementSize) {
|
byte elementSize) {
|
||||||
assert elementSize != FieldSize.INLINE_COMPOSITE : "Should have called initStructListPointer instead";
|
assert elementSize != FieldSize.INLINE_COMPOSITE : "Should have called initStructListPointer instead";
|
||||||
|
|
||||||
int dataSize = FieldSize.dataBitsPerElement(elementSize);
|
int dataSize = FieldSize.dataBitsPerElement(elementSize);
|
||||||
|
@ -198,10 +198,10 @@ final class WireHelpers {
|
||||||
elementCount, step, dataSize, (short)pointerCount);
|
elementCount, step, dataSize, (short)pointerCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ListBuilder initStructListPointer(int refOffset,
|
static ListBuilder initStructListPointer(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
int elementCount,
|
int elementCount,
|
||||||
StructSize elementSize) {
|
StructSize elementSize) {
|
||||||
if (elementSize.preferredListEncoding != FieldSize.INLINE_COMPOSITE) {
|
if (elementSize.preferredListEncoding != FieldSize.INLINE_COMPOSITE) {
|
||||||
//# Small data-only struct. Allocate a list of primitives instead.
|
//# Small data-only struct. Allocate a list of primitives instead.
|
||||||
return initListPointer(refOffset, segment, elementCount,
|
return initListPointer(refOffset, segment, elementCount,
|
||||||
|
@ -227,9 +227,9 @@ final class WireHelpers {
|
||||||
elementSize.data * Constants.BITS_PER_WORD, elementSize.pointers);
|
elementSize.data * Constants.BITS_PER_WORD, elementSize.pointers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ListBuilder getWritableListPointer(int origRefOffset,
|
static ListBuilder getWritableListPointer(int origRefOffset,
|
||||||
SegmentBuilder origSegment,
|
SegmentBuilder origSegment,
|
||||||
byte elementSize) {
|
byte elementSize) {
|
||||||
assert elementSize != FieldSize.INLINE_COMPOSITE : "Use getStructList{Element,Field} for structs";
|
assert elementSize != FieldSize.INLINE_COMPOSITE : "Use getStructList{Element,Field} for structs";
|
||||||
|
|
||||||
long origRef = WirePointer.get(origSegment.buffer, origRefOffset);
|
long origRef = WirePointer.get(origSegment.buffer, origRefOffset);
|
||||||
|
@ -283,9 +283,9 @@ final class WireHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
// size is in bytes
|
// size is in bytes
|
||||||
public static Text.Builder initTextPointer(int refOffset,
|
static Text.Builder initTextPointer(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
int size) {
|
int size) {
|
||||||
//# The byte list must include a NUL terminator.
|
//# The byte list must include a NUL terminator.
|
||||||
int byteSize = size + 1;
|
int byteSize = size + 1;
|
||||||
|
|
||||||
|
@ -299,9 +299,9 @@ final class WireHelpers {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text.Builder setTextPointer(int refOffset,
|
static Text.Builder setTextPointer(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
Text.Reader value) {
|
Text.Reader value) {
|
||||||
Text.Builder builder = initTextPointer(refOffset, segment, value.size);
|
Text.Builder builder = initTextPointer(refOffset, segment, value.size);
|
||||||
|
|
||||||
// TODO is there a way to do this with bulk methods?
|
// TODO is there a way to do this with bulk methods?
|
||||||
|
@ -311,11 +311,11 @@ final class WireHelpers {
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text.Builder getWritableTextPointer(int refOffset,
|
static Text.Builder getWritableTextPointer(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
ByteBuffer defaultBuffer,
|
ByteBuffer defaultBuffer,
|
||||||
int defaultOffset,
|
int defaultOffset,
|
||||||
int defaultSize) {
|
int defaultSize) {
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
|
|
||||||
if (WirePointer.isNull(ref)) {
|
if (WirePointer.isNull(ref)) {
|
||||||
|
@ -350,9 +350,9 @@ final class WireHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
// size is in bytes
|
// size is in bytes
|
||||||
public static Data.Builder initDataPointer(int refOffset,
|
static Data.Builder initDataPointer(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
int size) {
|
int size) {
|
||||||
//# Allocate the space.
|
//# Allocate the space.
|
||||||
AllocateResult allocation = allocate(refOffset, segment, roundBytesUpToWords(size),
|
AllocateResult allocation = allocate(refOffset, segment, roundBytesUpToWords(size),
|
||||||
WirePointer.LIST);
|
WirePointer.LIST);
|
||||||
|
@ -363,9 +363,9 @@ final class WireHelpers {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data.Builder setDataPointer(int refOffset,
|
static Data.Builder setDataPointer(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
Data.Reader value) {
|
Data.Reader value) {
|
||||||
Data.Builder builder = initDataPointer(refOffset, segment, value.size);
|
Data.Builder builder = initDataPointer(refOffset, segment, value.size);
|
||||||
|
|
||||||
// TODO is there a way to do this with bulk methods?
|
// TODO is there a way to do this with bulk methods?
|
||||||
|
@ -375,11 +375,11 @@ final class WireHelpers {
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data.Builder getWritableDataPointer(int refOffset,
|
static Data.Builder getWritableDataPointer(int refOffset,
|
||||||
SegmentBuilder segment,
|
SegmentBuilder segment,
|
||||||
ByteBuffer defaultBuffer,
|
ByteBuffer defaultBuffer,
|
||||||
int defaultOffset,
|
int defaultOffset,
|
||||||
int defaultSize) {
|
int defaultSize) {
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
|
|
||||||
if (WirePointer.isNull(ref)) {
|
if (WirePointer.isNull(ref)) {
|
||||||
|
@ -411,9 +411,9 @@ final class WireHelpers {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StructReader readStructPointer(SegmentReader segment,
|
static StructReader readStructPointer(SegmentReader segment,
|
||||||
int refOffset,
|
int refOffset,
|
||||||
int nestingLimit) {
|
int nestingLimit) {
|
||||||
|
|
||||||
// TODO error handling. is_null
|
// TODO error handling. is_null
|
||||||
if (nestingLimit <= 0) {
|
if (nestingLimit <= 0) {
|
||||||
|
@ -442,11 +442,14 @@ final class WireHelpers {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SegmentBuilder setStructPointer(SegmentBuilder segment, int refOffset, StructReader value) {
|
||||||
|
throw new Error("setStructPointer is unimplemented");
|
||||||
|
};
|
||||||
|
|
||||||
public static ListReader readListPointer(SegmentReader segment,
|
static ListReader readListPointer(SegmentReader segment,
|
||||||
int refOffset,
|
int refOffset,
|
||||||
byte expectedElementSize,
|
byte expectedElementSize,
|
||||||
int nestingLimit) {
|
int nestingLimit) {
|
||||||
|
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
|
|
||||||
|
@ -528,11 +531,11 @@ final class WireHelpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text.Reader readTextPointer(SegmentReader segment,
|
static Text.Reader readTextPointer(SegmentReader segment,
|
||||||
int refOffset,
|
int refOffset,
|
||||||
ByteBuffer defaultBuffer,
|
ByteBuffer defaultBuffer,
|
||||||
int defaultOffset,
|
int defaultOffset,
|
||||||
int defaultSize) {
|
int defaultSize) {
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
|
|
||||||
if (WirePointer.isNull(ref)) {
|
if (WirePointer.isNull(ref)) {
|
||||||
|
@ -567,11 +570,11 @@ final class WireHelpers {
|
||||||
return new Text.Reader(resolved.segment.buffer, resolved.ptr, size - 1);
|
return new Text.Reader(resolved.segment.buffer, resolved.ptr, size - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data.Reader readDataPointer(SegmentReader segment,
|
static Data.Reader readDataPointer(SegmentReader segment,
|
||||||
int refOffset,
|
int refOffset,
|
||||||
ByteBuffer defaultBuffer,
|
ByteBuffer defaultBuffer,
|
||||||
int defaultOffset,
|
int defaultOffset,
|
||||||
int defaultSize) {
|
int defaultSize) {
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
|
|
||||||
if (WirePointer.isNull(ref)) {
|
if (WirePointer.isNull(ref)) {
|
||||||
|
|
Loading…
Reference in a new issue