Commit 917f459e authored by Kenton Varda's avatar Kenton Varda

Mass rename 'reference' -> 'pointer'. Been meaning to do this for a while --…

Mass rename 'reference' -> 'pointer'.  Been meaning to do this for a while -- all the documentation talks about 'pointers', not 'references'.
parent e550bee1
...@@ -77,12 +77,12 @@ internal::FieldSize elementSizeFor(schema::Type::Body::Which elementType) { ...@@ -77,12 +77,12 @@ internal::FieldSize elementSizeFor(schema::Type::Body::Which elementType) {
case schema::Type::Body::FLOAT32_TYPE: return internal::FieldSize::FOUR_BYTES; case schema::Type::Body::FLOAT32_TYPE: return internal::FieldSize::FOUR_BYTES;
case schema::Type::Body::FLOAT64_TYPE: return internal::FieldSize::EIGHT_BYTES; case schema::Type::Body::FLOAT64_TYPE: return internal::FieldSize::EIGHT_BYTES;
case schema::Type::Body::TEXT_TYPE: return internal::FieldSize::REFERENCE; case schema::Type::Body::TEXT_TYPE: return internal::FieldSize::POINTER;
case schema::Type::Body::DATA_TYPE: return internal::FieldSize::REFERENCE; case schema::Type::Body::DATA_TYPE: return internal::FieldSize::POINTER;
case schema::Type::Body::LIST_TYPE: return internal::FieldSize::REFERENCE; case schema::Type::Body::LIST_TYPE: return internal::FieldSize::POINTER;
case schema::Type::Body::ENUM_TYPE: return internal::FieldSize::TWO_BYTES; case schema::Type::Body::ENUM_TYPE: return internal::FieldSize::TWO_BYTES;
case schema::Type::Body::STRUCT_TYPE: return internal::FieldSize::INLINE_COMPOSITE; case schema::Type::Body::STRUCT_TYPE: return internal::FieldSize::INLINE_COMPOSITE;
case schema::Type::Body::INTERFACE_TYPE: return internal::FieldSize::REFERENCE; case schema::Type::Body::INTERFACE_TYPE: return internal::FieldSize::POINTER;
case schema::Type::Body::OBJECT_TYPE: FAIL_CHECK("List(Object) not supported."); break; case schema::Type::Body::OBJECT_TYPE: FAIL_CHECK("List(Object) not supported."); break;
} }
FAIL_CHECK("Can't get here."); FAIL_CHECK("Can't get here.");
...@@ -93,7 +93,7 @@ inline internal::StructSize structSizeFromSchema(StructSchema schema) { ...@@ -93,7 +93,7 @@ inline internal::StructSize structSizeFromSchema(StructSchema schema) {
auto node = schema.getProto().getBody().getStructNode(); auto node = schema.getProto().getBody().getStructNode();
return internal::StructSize( return internal::StructSize(
node.getDataSectionWordSize() * WORDS, node.getDataSectionWordSize() * WORDS,
node.getPointerSectionSize() * REFERENCES, node.getPointerSectionSize() * POINTERS,
static_cast<internal::FieldSize>(node.getPreferredListEncoding())); static_cast<internal::FieldSize>(node.getPreferredListEncoding()));
} }
...@@ -561,14 +561,14 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl( ...@@ -561,14 +561,14 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl(
case schema::Type::Body::TEXT_TYPE: { case schema::Type::Body::TEXT_TYPE: {
Text::Reader typedDval = dval.getTextValue(); Text::Reader typedDval = dval.getTextValue();
return DynamicValue::Reader( return DynamicValue::Reader(
reader.getBlobField<Text>(field.getOffset() * REFERENCES, reader.getBlobField<Text>(field.getOffset() * POINTERS,
typedDval.data(), typedDval.size() * BYTES)); typedDval.data(), typedDval.size() * BYTES));
} }
case schema::Type::Body::DATA_TYPE: { case schema::Type::Body::DATA_TYPE: {
Data::Reader typedDval = dval.getDataValue(); Data::Reader typedDval = dval.getDataValue();
return DynamicValue::Reader( return DynamicValue::Reader(
reader.getBlobField<Data>(field.getOffset() * REFERENCES, reader.getBlobField<Data>(field.getOffset() * POINTERS,
typedDval.data(), typedDval.size() * BYTES)); typedDval.data(), typedDval.size() * BYTES));
} }
...@@ -576,7 +576,7 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl( ...@@ -576,7 +576,7 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl(
auto elementType = type.getListType(); auto elementType = type.getListType();
return DynamicValue::Reader(DynamicList::Reader( return DynamicValue::Reader(DynamicList::Reader(
ListSchema::of(elementType, member.getContainingStruct()), ListSchema::of(elementType, member.getContainingStruct()),
reader.getListField(field.getOffset() * REFERENCES, reader.getListField(field.getOffset() * POINTERS,
elementSizeFor(elementType.getBody().which()), elementSizeFor(elementType.getBody().which()),
dval.getListValue<internal::TrustedMessage>()))); dval.getListValue<internal::TrustedMessage>())));
} }
...@@ -584,13 +584,13 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl( ...@@ -584,13 +584,13 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl(
case schema::Type::Body::STRUCT_TYPE: { case schema::Type::Body::STRUCT_TYPE: {
return DynamicValue::Reader(DynamicStruct::Reader( return DynamicValue::Reader(DynamicStruct::Reader(
member.getContainingStruct().getDependency(type.getStructType()).asStruct(), member.getContainingStruct().getDependency(type.getStructType()).asStruct(),
reader.getStructField(field.getOffset() * REFERENCES, reader.getStructField(field.getOffset() * POINTERS,
dval.getStructValue<internal::TrustedMessage>()))); dval.getStructValue<internal::TrustedMessage>())));
} }
case schema::Type::Body::OBJECT_TYPE: { case schema::Type::Body::OBJECT_TYPE: {
return DynamicValue::Reader(DynamicObject( return DynamicValue::Reader(DynamicObject(
reader.getObjectField(field.getOffset() * REFERENCES, reader.getObjectField(field.getOffset() * POINTERS,
dval.getObjectValue<internal::TrustedMessage>()))); dval.getObjectValue<internal::TrustedMessage>())));
} }
...@@ -654,21 +654,21 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl( ...@@ -654,21 +654,21 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl(
case schema::Type::Body::TEXT_TYPE: { case schema::Type::Body::TEXT_TYPE: {
Text::Reader typedDval = dval.getTextValue(); Text::Reader typedDval = dval.getTextValue();
return DynamicValue::Builder( return DynamicValue::Builder(
builder.getBlobField<Text>(field.getOffset() * REFERENCES, builder.getBlobField<Text>(field.getOffset() * POINTERS,
typedDval.data(), typedDval.size() * BYTES)); typedDval.data(), typedDval.size() * BYTES));
} }
case schema::Type::Body::DATA_TYPE: { case schema::Type::Body::DATA_TYPE: {
Data::Reader typedDval = dval.getDataValue(); Data::Reader typedDval = dval.getDataValue();
return DynamicValue::Builder( return DynamicValue::Builder(
builder.getBlobField<Data>(field.getOffset() * REFERENCES, builder.getBlobField<Data>(field.getOffset() * POINTERS,
typedDval.data(), typedDval.size() * BYTES)); typedDval.data(), typedDval.size() * BYTES));
} }
case schema::Type::Body::LIST_TYPE: case schema::Type::Body::LIST_TYPE:
return DynamicValue::Builder(DynamicList::Builder( return DynamicValue::Builder(DynamicList::Builder(
ListSchema::of(type.getListType(), member.getContainingStruct()), ListSchema::of(type.getListType(), member.getContainingStruct()),
builder.getListField(field.getOffset() * REFERENCES, builder.getListField(field.getOffset() * POINTERS,
dval.getListValue<internal::TrustedMessage>()))); dval.getListValue<internal::TrustedMessage>())));
case schema::Type::Body::STRUCT_TYPE: { case schema::Type::Body::STRUCT_TYPE: {
...@@ -677,7 +677,7 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl( ...@@ -677,7 +677,7 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl(
return DynamicValue::Builder(DynamicStruct::Builder( return DynamicValue::Builder(DynamicStruct::Builder(
structSchema, structSchema,
builder.getStructField( builder.getStructField(
field.getOffset() * REFERENCES, field.getOffset() * POINTERS,
structSizeFromSchema(structSchema), structSizeFromSchema(structSchema),
dval.getStructValue<internal::TrustedMessage>()))); dval.getStructValue<internal::TrustedMessage>())));
} }
...@@ -685,7 +685,7 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl( ...@@ -685,7 +685,7 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl(
case schema::Type::Body::OBJECT_TYPE: { case schema::Type::Body::OBJECT_TYPE: {
return DynamicValue::Builder(DynamicObject( return DynamicValue::Builder(DynamicObject(
builder.asReader().getObjectField( builder.asReader().getObjectField(
field.getOffset() * REFERENCES, field.getOffset() * POINTERS,
dval.getObjectValue<internal::TrustedMessage>()))); dval.getObjectValue<internal::TrustedMessage>())));
} }
...@@ -706,25 +706,25 @@ DynamicStruct::Builder DynamicStruct::Builder::getObjectImpl( ...@@ -706,25 +706,25 @@ DynamicStruct::Builder DynamicStruct::Builder::getObjectImpl(
internal::StructBuilder builder, StructSchema::Member field, StructSchema type) { internal::StructBuilder builder, StructSchema::Member field, StructSchema type) {
return DynamicStruct::Builder(type, return DynamicStruct::Builder(type,
builder.getStructField( builder.getStructField(
field.getProto().getBody().getFieldMember().getOffset() * REFERENCES, field.getProto().getBody().getFieldMember().getOffset() * POINTERS,
structSizeFromSchema(type), nullptr)); structSizeFromSchema(type), nullptr));
} }
DynamicList::Builder DynamicStruct::Builder::getObjectImpl( DynamicList::Builder DynamicStruct::Builder::getObjectImpl(
internal::StructBuilder builder, StructSchema::Member field, ListSchema type) { internal::StructBuilder builder, StructSchema::Member field, ListSchema type) {
return DynamicList::Builder(type, return DynamicList::Builder(type,
builder.getListField( builder.getListField(
field.getProto().getBody().getFieldMember().getOffset() * REFERENCES, field.getProto().getBody().getFieldMember().getOffset() * POINTERS,
nullptr)); nullptr));
} }
Text::Builder DynamicStruct::Builder::getObjectAsTextImpl( Text::Builder DynamicStruct::Builder::getObjectAsTextImpl(
internal::StructBuilder builder, StructSchema::Member field) { internal::StructBuilder builder, StructSchema::Member field) {
return builder.getBlobField<Text>( return builder.getBlobField<Text>(
field.getProto().getBody().getFieldMember().getOffset() * REFERENCES, nullptr, 0 * BYTES); field.getProto().getBody().getFieldMember().getOffset() * POINTERS, nullptr, 0 * BYTES);
} }
Data::Builder DynamicStruct::Builder::getObjectAsDataImpl( Data::Builder DynamicStruct::Builder::getObjectAsDataImpl(
internal::StructBuilder builder, StructSchema::Member field) { internal::StructBuilder builder, StructSchema::Member field) {
return builder.getBlobField<Data>( return builder.getBlobField<Data>(
field.getProto().getBody().getFieldMember().getOffset() * REFERENCES, nullptr, 0 * BYTES); field.getProto().getBody().getFieldMember().getOffset() * POINTERS, nullptr, 0 * BYTES);
} }
void DynamicStruct::Builder::setImpl( void DynamicStruct::Builder::setImpl(
...@@ -795,11 +795,11 @@ void DynamicStruct::Builder::setImpl( ...@@ -795,11 +795,11 @@ void DynamicStruct::Builder::setImpl(
} }
case schema::Type::Body::TEXT_TYPE: case schema::Type::Body::TEXT_TYPE:
builder.setBlobField<Text>(field.getOffset() * REFERENCES, value.as<Text>()); builder.setBlobField<Text>(field.getOffset() * POINTERS, value.as<Text>());
return; return;
case schema::Type::Body::DATA_TYPE: case schema::Type::Body::DATA_TYPE:
builder.setBlobField<Data>(field.getOffset() * REFERENCES, value.as<Data>()); builder.setBlobField<Data>(field.getOffset() * POINTERS, value.as<Data>());
return; return;
case schema::Type::Body::LIST_TYPE: { case schema::Type::Body::LIST_TYPE: {
...@@ -893,7 +893,7 @@ DynamicStruct::Builder DynamicStruct::Builder::initFieldImpl( ...@@ -893,7 +893,7 @@ DynamicStruct::Builder DynamicStruct::Builder::initFieldImpl(
internal::StructBuilder builder, StructSchema::Member field, StructSchema type) { internal::StructBuilder builder, StructSchema::Member field, StructSchema type) {
return DynamicStruct::Builder( return DynamicStruct::Builder(
type, builder.initStructField( type, builder.initStructField(
field.getProto().getBody().getFieldMember().getOffset() * REFERENCES, field.getProto().getBody().getFieldMember().getOffset() * POINTERS,
structSizeFromSchema(type))); structSizeFromSchema(type)));
} }
DynamicList::Builder DynamicStruct::Builder::initFieldImpl( DynamicList::Builder DynamicStruct::Builder::initFieldImpl(
...@@ -902,12 +902,12 @@ DynamicList::Builder DynamicStruct::Builder::initFieldImpl( ...@@ -902,12 +902,12 @@ DynamicList::Builder DynamicStruct::Builder::initFieldImpl(
if (type.whichElementType() == schema::Type::Body::STRUCT_TYPE) { if (type.whichElementType() == schema::Type::Body::STRUCT_TYPE) {
return DynamicList::Builder( return DynamicList::Builder(
type, builder.initStructListField( type, builder.initStructListField(
field.getProto().getBody().getFieldMember().getOffset() * REFERENCES, size * ELEMENTS, field.getProto().getBody().getFieldMember().getOffset() * POINTERS, size * ELEMENTS,
structSizeFromSchema(type.getStructElementType()))); structSizeFromSchema(type.getStructElementType())));
} else { } else {
return DynamicList::Builder( return DynamicList::Builder(
type, builder.initListField( type, builder.initListField(
field.getProto().getBody().getFieldMember().getOffset() * REFERENCES, field.getProto().getBody().getFieldMember().getOffset() * POINTERS,
elementSizeFor(type.whichElementType()), elementSizeFor(type.whichElementType()),
size * ELEMENTS)); size * ELEMENTS));
} }
...@@ -915,12 +915,12 @@ DynamicList::Builder DynamicStruct::Builder::initFieldImpl( ...@@ -915,12 +915,12 @@ DynamicList::Builder DynamicStruct::Builder::initFieldImpl(
Text::Builder DynamicStruct::Builder::initFieldAsTextImpl( Text::Builder DynamicStruct::Builder::initFieldAsTextImpl(
internal::StructBuilder builder, StructSchema::Member field, uint size) { internal::StructBuilder builder, StructSchema::Member field, uint size) {
return builder.initBlobField<Text>( return builder.initBlobField<Text>(
field.getProto().getBody().getFieldMember().getOffset() * REFERENCES, size * BYTES); field.getProto().getBody().getFieldMember().getOffset() * POINTERS, size * BYTES);
} }
Data::Builder DynamicStruct::Builder::initFieldAsDataImpl( Data::Builder DynamicStruct::Builder::initFieldAsDataImpl(
internal::StructBuilder builder, StructSchema::Member field, uint size) { internal::StructBuilder builder, StructSchema::Member field, uint size) {
return builder.initBlobField<Data>( return builder.initBlobField<Data>(
field.getProto().getBody().getFieldMember().getOffset() * REFERENCES, size * BYTES); field.getProto().getBody().getFieldMember().getOffset() * POINTERS, size * BYTES);
} }
// ======================================================================================= // =======================================================================================
...@@ -1362,41 +1362,41 @@ DynamicStruct::Builder MessageBuilder::getRoot<DynamicStruct>(StructSchema schem ...@@ -1362,41 +1362,41 @@ DynamicStruct::Builder MessageBuilder::getRoot<DynamicStruct>(StructSchema schem
namespace internal { namespace internal {
DynamicStruct::Reader PointerHelpers<DynamicStruct, Kind::UNKNOWN>::getDynamic( DynamicStruct::Reader PointerHelpers<DynamicStruct, Kind::UNKNOWN>::getDynamic(
StructReader reader, WireReferenceCount index, StructSchema schema) { StructReader reader, WirePointerCount index, StructSchema schema) {
return DynamicStruct::Reader(schema, reader.getStructField(index, nullptr)); return DynamicStruct::Reader(schema, reader.getStructField(index, nullptr));
} }
DynamicStruct::Builder PointerHelpers<DynamicStruct, Kind::UNKNOWN>::getDynamic( DynamicStruct::Builder PointerHelpers<DynamicStruct, Kind::UNKNOWN>::getDynamic(
StructBuilder builder, WireReferenceCount index, StructSchema schema) { StructBuilder builder, WirePointerCount index, StructSchema schema) {
return DynamicStruct::Builder(schema, builder.getStructField( return DynamicStruct::Builder(schema, builder.getStructField(
index, structSizeFromSchema(schema), nullptr)); index, structSizeFromSchema(schema), nullptr));
} }
void PointerHelpers<DynamicStruct, Kind::UNKNOWN>::set( void PointerHelpers<DynamicStruct, Kind::UNKNOWN>::set(
StructBuilder builder, WireReferenceCount index, DynamicStruct::Reader value) { StructBuilder builder, WirePointerCount index, DynamicStruct::Reader value) {
// TODO(now): schemaless copy // TODO(now): schemaless copy
FAIL_CHECK("Unimplemented: copyFrom()"); FAIL_CHECK("Unimplemented: copyFrom()");
} }
DynamicStruct::Builder PointerHelpers<DynamicStruct, Kind::UNKNOWN>::init( DynamicStruct::Builder PointerHelpers<DynamicStruct, Kind::UNKNOWN>::init(
StructBuilder builder, WireReferenceCount index, StructSchema schema) { StructBuilder builder, WirePointerCount index, StructSchema schema) {
return DynamicStruct::Builder(schema, return DynamicStruct::Builder(schema,
builder.initStructField(index, structSizeFromSchema(schema))); builder.initStructField(index, structSizeFromSchema(schema)));
} }
DynamicList::Reader PointerHelpers<DynamicList, Kind::UNKNOWN>::getDynamic( DynamicList::Reader PointerHelpers<DynamicList, Kind::UNKNOWN>::getDynamic(
StructReader reader, WireReferenceCount index, ListSchema schema) { StructReader reader, WirePointerCount index, ListSchema schema) {
return DynamicList::Reader(schema, return DynamicList::Reader(schema,
reader.getListField(index, elementSizeFor(schema.whichElementType()), nullptr)); reader.getListField(index, elementSizeFor(schema.whichElementType()), nullptr));
} }
DynamicList::Builder PointerHelpers<DynamicList, Kind::UNKNOWN>::getDynamic( DynamicList::Builder PointerHelpers<DynamicList, Kind::UNKNOWN>::getDynamic(
StructBuilder builder, WireReferenceCount index, ListSchema schema) { StructBuilder builder, WirePointerCount index, ListSchema schema) {
return DynamicList::Builder(schema, builder.getListField(index, nullptr)); return DynamicList::Builder(schema, builder.getListField(index, nullptr));
} }
void PointerHelpers<DynamicList, Kind::UNKNOWN>::set( void PointerHelpers<DynamicList, Kind::UNKNOWN>::set(
StructBuilder builder, WireReferenceCount index, DynamicList::Reader value) { StructBuilder builder, WirePointerCount index, DynamicList::Reader value) {
// TODO(now): schemaless copy // TODO(now): schemaless copy
FAIL_CHECK("Unimplemented: copyFrom()"); FAIL_CHECK("Unimplemented: copyFrom()");
} }
DynamicList::Builder PointerHelpers<DynamicList, Kind::UNKNOWN>::init( DynamicList::Builder PointerHelpers<DynamicList, Kind::UNKNOWN>::init(
StructBuilder builder, WireReferenceCount index, ListSchema schema, uint size) { StructBuilder builder, WirePointerCount index, ListSchema schema, uint size) {
if (schema.whichElementType() == schema::Type::Body::STRUCT_TYPE) { if (schema.whichElementType() == schema::Type::Body::STRUCT_TYPE) {
return DynamicList::Builder(schema, return DynamicList::Builder(schema,
builder.initStructListField(index, size * ELEMENTS, builder.initStructListField(index, size * ELEMENTS,
......
...@@ -656,13 +656,13 @@ struct PointerHelpers<DynamicStruct, Kind::UNKNOWN> { ...@@ -656,13 +656,13 @@ struct PointerHelpers<DynamicStruct, Kind::UNKNOWN> {
// non-dynamic types PointerHelpers::get() takes a default value as the third argument, and we // non-dynamic types PointerHelpers::get() takes a default value as the third argument, and we
// don't want people to accidentally be able to provide their own default value. // don't want people to accidentally be able to provide their own default value.
static DynamicStruct::Reader getDynamic( static DynamicStruct::Reader getDynamic(
StructReader reader, WireReferenceCount index, StructSchema schema); StructReader reader, WirePointerCount index, StructSchema schema);
static DynamicStruct::Builder getDynamic( static DynamicStruct::Builder getDynamic(
StructBuilder builder, WireReferenceCount index, StructSchema schema); StructBuilder builder, WirePointerCount index, StructSchema schema);
static void set( static void set(
StructBuilder builder, WireReferenceCount index, DynamicStruct::Reader value); StructBuilder builder, WirePointerCount index, DynamicStruct::Reader value);
static DynamicStruct::Builder init( static DynamicStruct::Builder init(
StructBuilder builder, WireReferenceCount index, StructSchema schema); StructBuilder builder, WirePointerCount index, StructSchema schema);
}; };
template <> template <>
...@@ -671,13 +671,13 @@ struct PointerHelpers<DynamicList, Kind::UNKNOWN> { ...@@ -671,13 +671,13 @@ struct PointerHelpers<DynamicList, Kind::UNKNOWN> {
// non-dynamic types PointerHelpers::get() takes a default value as the third argument, and we // non-dynamic types PointerHelpers::get() takes a default value as the third argument, and we
// don't want people to accidentally be able to provide their own default value. // don't want people to accidentally be able to provide their own default value.
static DynamicList::Reader getDynamic( static DynamicList::Reader getDynamic(
StructReader reader, WireReferenceCount index, ListSchema schema); StructReader reader, WirePointerCount index, ListSchema schema);
static DynamicList::Builder getDynamic( static DynamicList::Builder getDynamic(
StructBuilder builder, WireReferenceCount index, ListSchema schema); StructBuilder builder, WirePointerCount index, ListSchema schema);
static void set( static void set(
StructBuilder builder, WireReferenceCount index, DynamicList::Reader value); StructBuilder builder, WirePointerCount index, DynamicList::Reader value);
static DynamicList::Builder init( static DynamicList::Builder init(
StructBuilder builder, WireReferenceCount index, ListSchema schema, uint size); StructBuilder builder, WirePointerCount index, ListSchema schema, uint size);
}; };
} // namespace internal } // namespace internal
......
...@@ -40,64 +40,64 @@ namespace internal { ...@@ -40,64 +40,64 @@ namespace internal {
template <typename T> template <typename T>
struct PointerHelpers<T, Kind::STRUCT> { struct PointerHelpers<T, Kind::STRUCT> {
static inline typename T::Reader get(StructReader reader, WireReferenceCount index, static inline typename T::Reader get(StructReader reader, WirePointerCount index,
const word* defaultValue = nullptr) { const word* defaultValue = nullptr) {
return typename T::Reader(reader.getStructField(index, defaultValue)); return typename T::Reader(reader.getStructField(index, defaultValue));
} }
static inline typename T::Builder get(StructBuilder builder, WireReferenceCount index, static inline typename T::Builder get(StructBuilder builder, WirePointerCount index,
const word* defaultValue = nullptr) { const word* defaultValue = nullptr) {
return typename T::Builder(builder.getStructField(index, structSize<T>(), defaultValue)); return typename T::Builder(builder.getStructField(index, structSize<T>(), defaultValue));
} }
static inline void set(StructBuilder builder, WireReferenceCount index, static inline void set(StructBuilder builder, WirePointerCount index,
typename T::Reader value) { typename T::Reader value) {
// TODO(now): schemaless copy // TODO(now): schemaless copy
CAPNPROTO_INLINE_PRECOND(false, "Not implemented: set() for struct fields."); CAPNPROTO_INLINE_PRECOND(false, "Not implemented: set() for struct fields.");
} }
static inline typename T::Builder init(StructBuilder builder, WireReferenceCount index) { static inline typename T::Builder init(StructBuilder builder, WirePointerCount index) {
return typename T::Builder(builder.initStructField(index, structSize<T>())); return typename T::Builder(builder.initStructField(index, structSize<T>()));
} }
}; };
template <typename T> template <typename T>
struct PointerHelpers<List<T>, Kind::LIST> { struct PointerHelpers<List<T>, Kind::LIST> {
static inline typename List<T>::Reader get(StructReader reader, WireReferenceCount index, static inline typename List<T>::Reader get(StructReader reader, WirePointerCount index,
const word* defaultValue = nullptr) { const word* defaultValue = nullptr) {
return typename List<T>::Reader(List<T>::getAsFieldOf(reader, index, defaultValue)); return typename List<T>::Reader(List<T>::getAsFieldOf(reader, index, defaultValue));
} }
static inline typename List<T>::Builder get(StructBuilder builder, WireReferenceCount index, static inline typename List<T>::Builder get(StructBuilder builder, WirePointerCount index,
const word* defaultValue = nullptr) { const word* defaultValue = nullptr) {
return typename List<T>::Builder(List<T>::getAsFieldOf(builder, index, defaultValue)); return typename List<T>::Builder(List<T>::getAsFieldOf(builder, index, defaultValue));
} }
static inline void set(StructBuilder builder, WireReferenceCount index, static inline void set(StructBuilder builder, WirePointerCount index,
typename List<T>::Reader value) { typename List<T>::Reader value) {
init(builder, index, value.size()).copyFrom(value); init(builder, index, value.size()).copyFrom(value);
} }
static inline void set(StructBuilder builder, WireReferenceCount index, static inline void set(StructBuilder builder, WirePointerCount index,
std::initializer_list<ReaderFor<T>> value) { std::initializer_list<ReaderFor<T>> value) {
init(builder, index, value.size()).copyFrom(value); init(builder, index, value.size()).copyFrom(value);
} }
static inline typename List<T>::Builder init( static inline typename List<T>::Builder init(
StructBuilder builder, WireReferenceCount index, uint size) { StructBuilder builder, WirePointerCount index, uint size) {
return typename List<T>::Builder(List<T>::initAsFieldOf(builder, index, size)); return typename List<T>::Builder(List<T>::initAsFieldOf(builder, index, size));
} }
}; };
template <typename T> template <typename T>
struct PointerHelpers<T, Kind::BLOB> { struct PointerHelpers<T, Kind::BLOB> {
static inline typename T::Reader get(StructReader reader, WireReferenceCount index, static inline typename T::Reader get(StructReader reader, WirePointerCount index,
const void* defaultValue = nullptr, const void* defaultValue = nullptr,
uint defaultBytes = 0) { uint defaultBytes = 0) {
return reader.getBlobField<T>(index, defaultValue, defaultBytes * BYTES); return reader.getBlobField<T>(index, defaultValue, defaultBytes * BYTES);
} }
static inline typename T::Builder get(StructBuilder builder, WireReferenceCount index, static inline typename T::Builder get(StructBuilder builder, WirePointerCount index,
const void* defaultValue = nullptr, const void* defaultValue = nullptr,
uint defaultBytes = 0) { uint defaultBytes = 0) {
return builder.getBlobField<T>(index, defaultValue, defaultBytes * BYTES); return builder.getBlobField<T>(index, defaultValue, defaultBytes * BYTES);
} }
static inline void set(StructBuilder builder, WireReferenceCount index, typename T::Reader value) { static inline void set(StructBuilder builder, WirePointerCount index, typename T::Reader value) {
builder.setBlobField<T>(index, value); builder.setBlobField<T>(index, value);
} }
static inline typename T::Builder init(StructBuilder builder, WireReferenceCount index, uint size) { static inline typename T::Builder init(StructBuilder builder, WirePointerCount index, uint size) {
return builder.initBlobField<T>(index, size * BYTES); return builder.initBlobField<T>(index, size * BYTES);
} }
}; };
...@@ -114,7 +114,7 @@ struct PointerHelpers<TrustedMessage> { ...@@ -114,7 +114,7 @@ struct PointerHelpers<TrustedMessage> {
// itself trusted. This hack is currently private. It is used to locate default values within // itself trusted. This hack is currently private. It is used to locate default values within
// encoded schemas. // encoded schemas.
static inline const word* get(StructReader reader, WireReferenceCount index) { static inline const word* get(StructReader reader, WirePointerCount index) {
return reader.getTrustedPointer(index); return reader.getTrustedPointer(index);
} }
}; };
...@@ -177,7 +177,7 @@ inline constexpr uint64_t typeId() { return internal::TypeIdFor<T>::typeId; } ...@@ -177,7 +177,7 @@ inline constexpr uint64_t typeId() { return internal::TypeIdFor<T>::typeId; }
template <> struct KindOf<type> { static constexpr Kind kind = Kind::STRUCT; }; \ template <> struct KindOf<type> { static constexpr Kind kind = Kind::STRUCT; }; \
template <> struct StructSizeFor<type> { \ template <> struct StructSizeFor<type> { \
static constexpr StructSize value = StructSize( \ static constexpr StructSize value = StructSize( \
dataWordSize * WORDS, pointerCount * REFERENCES, FieldSize::preferredElementEncoding); \ dataWordSize * WORDS, pointerCount * POINTERS, FieldSize::preferredElementEncoding); \
}; \ }; \
template <> struct TypeIdFor<type> { static constexpr uint64_t typeId = 0x##id; }; \ template <> struct TypeIdFor<type> { static constexpr uint64_t typeId = 0x##id; }; \
template <> struct RawSchemaFor<type> { \ template <> struct RawSchemaFor<type> { \
......
...@@ -40,7 +40,7 @@ namespace { ...@@ -40,7 +40,7 @@ namespace {
TEST(WireFormat, SimpleRawDataStruct) { TEST(WireFormat, SimpleRawDataStruct) {
AlignedData<2> data = {{ AlignedData<2> data = {{
// Struct ref, offset = 1, dataSize = 1, referenceCount = 0 // Struct ref, offset = 1, dataSize = 1, pointerCount = 0
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
// Content for the data segment. // Content for the data segment.
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
...@@ -103,7 +103,7 @@ static const AlignedData<2> STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT = ...@@ -103,7 +103,7 @@ static const AlignedData<2> STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT =
{{0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,0}}; {{0,0,0,0,1,0,0,0, 0,0,0,0,0,0,0,0}};
static constexpr StructSize STRUCTLIST_ELEMENT_SIZE( static constexpr StructSize STRUCTLIST_ELEMENT_SIZE(
1 * WORDS, 1 * REFERENCES, FieldSize::INLINE_COMPOSITE); 1 * WORDS, 1 * POINTERS, FieldSize::INLINE_COMPOSITE);
static void setupStruct(StructBuilder builder) { static void setupStruct(StructBuilder builder) {
builder.setDataField<uint64_t>(0 * ELEMENTS, 0x1011121314151617ull); builder.setDataField<uint64_t>(0 * ELEMENTS, 0x1011121314151617ull);
...@@ -121,12 +121,12 @@ static void setupStruct(StructBuilder builder) { ...@@ -121,12 +121,12 @@ static void setupStruct(StructBuilder builder) {
{ {
StructBuilder subStruct = builder.initStructField( StructBuilder subStruct = builder.initStructField(
0 * REFERENCES, StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES)); 0 * POINTERS, StructSize(1 * WORDS, 0 * POINTERS, FieldSize::EIGHT_BYTES));
subStruct.setDataField<uint32_t>(0 * ELEMENTS, 123); subStruct.setDataField<uint32_t>(0 * ELEMENTS, 123);
} }
{ {
ListBuilder list = builder.initListField(1 * REFERENCES, FieldSize::FOUR_BYTES, 3 * ELEMENTS); ListBuilder list = builder.initListField(1 * POINTERS, FieldSize::FOUR_BYTES, 3 * ELEMENTS);
EXPECT_EQ(3 * ELEMENTS, list.size()); EXPECT_EQ(3 * ELEMENTS, list.size());
list.setDataElement<int32_t>(0 * ELEMENTS, 200); list.setDataElement<int32_t>(0 * ELEMENTS, 200);
list.setDataElement<int32_t>(1 * ELEMENTS, 201); list.setDataElement<int32_t>(1 * ELEMENTS, 201);
...@@ -135,19 +135,19 @@ static void setupStruct(StructBuilder builder) { ...@@ -135,19 +135,19 @@ static void setupStruct(StructBuilder builder) {
{ {
ListBuilder list = builder.initStructListField( ListBuilder list = builder.initStructListField(
2 * REFERENCES, 4 * ELEMENTS, STRUCTLIST_ELEMENT_SIZE); 2 * POINTERS, 4 * ELEMENTS, STRUCTLIST_ELEMENT_SIZE);
EXPECT_EQ(4 * ELEMENTS, list.size()); EXPECT_EQ(4 * ELEMENTS, list.size());
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
StructBuilder element = list.getStructElement(i * ELEMENTS); StructBuilder element = list.getStructElement(i * ELEMENTS);
element.setDataField<int32_t>(0 * ELEMENTS, 300 + i); element.setDataField<int32_t>(0 * ELEMENTS, 300 + i);
element.initStructField(0 * REFERENCES, element.initStructField(0 * POINTERS,
StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES)) StructSize(1 * WORDS, 0 * POINTERS, FieldSize::EIGHT_BYTES))
.setDataField<int32_t>(0 * ELEMENTS, 400 + i); .setDataField<int32_t>(0 * ELEMENTS, 400 + i);
} }
} }
{ {
ListBuilder list = builder.initListField(3 * REFERENCES, FieldSize::REFERENCE, 5 * ELEMENTS); ListBuilder list = builder.initListField(3 * POINTERS, FieldSize::POINTER, 5 * ELEMENTS);
EXPECT_EQ(5 * ELEMENTS, list.size()); EXPECT_EQ(5 * ELEMENTS, list.size());
for (uint i = 0; i < 5; i++) { for (uint i = 0; i < 5; i++) {
ListBuilder element = list.initListElement( ListBuilder element = list.initListElement(
...@@ -176,13 +176,13 @@ static void checkStruct(StructBuilder builder) { ...@@ -176,13 +176,13 @@ static void checkStruct(StructBuilder builder) {
{ {
StructBuilder subStruct = builder.getStructField( StructBuilder subStruct = builder.getStructField(
0 * REFERENCES, StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES), 0 * POINTERS, StructSize(1 * WORDS, 0 * POINTERS, FieldSize::EIGHT_BYTES),
SUBSTRUCT_DEFAULT.words); SUBSTRUCT_DEFAULT.words);
EXPECT_EQ(123u, subStruct.getDataField<uint32_t>(0 * ELEMENTS)); EXPECT_EQ(123u, subStruct.getDataField<uint32_t>(0 * ELEMENTS));
} }
{ {
ListBuilder list = builder.getListField(1 * REFERENCES, nullptr); ListBuilder list = builder.getListField(1 * POINTERS, nullptr);
ASSERT_EQ(3 * ELEMENTS, list.size()); ASSERT_EQ(3 * ELEMENTS, list.size());
EXPECT_EQ(200, list.getDataElement<int32_t>(0 * ELEMENTS)); EXPECT_EQ(200, list.getDataElement<int32_t>(0 * ELEMENTS));
EXPECT_EQ(201, list.getDataElement<int32_t>(1 * ELEMENTS)); EXPECT_EQ(201, list.getDataElement<int32_t>(1 * ELEMENTS));
...@@ -190,21 +190,21 @@ static void checkStruct(StructBuilder builder) { ...@@ -190,21 +190,21 @@ static void checkStruct(StructBuilder builder) {
} }
{ {
ListBuilder list = builder.getListField(2 * REFERENCES, nullptr); ListBuilder list = builder.getListField(2 * POINTERS, nullptr);
ASSERT_EQ(4 * ELEMENTS, list.size()); ASSERT_EQ(4 * ELEMENTS, list.size());
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
StructBuilder element = list.getStructElement(i * ELEMENTS); StructBuilder element = list.getStructElement(i * ELEMENTS);
EXPECT_EQ(300 + i, element.getDataField<int32_t>(0 * ELEMENTS)); EXPECT_EQ(300 + i, element.getDataField<int32_t>(0 * ELEMENTS));
EXPECT_EQ(400 + i, EXPECT_EQ(400 + i,
element.getStructField(0 * REFERENCES, element.getStructField(0 * POINTERS,
StructSize(1 * WORDS, 0 * REFERENCES, FieldSize::EIGHT_BYTES), StructSize(1 * WORDS, 0 * POINTERS, FieldSize::EIGHT_BYTES),
STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT.words) STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT.words)
.getDataField<int32_t>(0 * ELEMENTS)); .getDataField<int32_t>(0 * ELEMENTS));
} }
} }
{ {
ListBuilder list = builder.getListField(3 * REFERENCES, nullptr); ListBuilder list = builder.getListField(3 * POINTERS, nullptr);
ASSERT_EQ(5 * ELEMENTS, list.size()); ASSERT_EQ(5 * ELEMENTS, list.size());
for (uint i = 0; i < 5; i++) { for (uint i = 0; i < 5; i++) {
ListBuilder element = list.getListElement(i * ELEMENTS); ListBuilder element = list.getListElement(i * ELEMENTS);
...@@ -231,12 +231,12 @@ static void checkStruct(StructReader reader) { ...@@ -231,12 +231,12 @@ static void checkStruct(StructReader reader) {
EXPECT_FALSE(reader.getDataField<bool>(127 * ELEMENTS)); EXPECT_FALSE(reader.getDataField<bool>(127 * ELEMENTS));
{ {
StructReader subStruct = reader.getStructField(0 * REFERENCES, SUBSTRUCT_DEFAULT.words); StructReader subStruct = reader.getStructField(0 * POINTERS, SUBSTRUCT_DEFAULT.words);
EXPECT_EQ(123u, subStruct.getDataField<uint32_t>(0 * ELEMENTS)); EXPECT_EQ(123u, subStruct.getDataField<uint32_t>(0 * ELEMENTS));
} }
{ {
ListReader list = reader.getListField(1 * REFERENCES, FieldSize::FOUR_BYTES, nullptr); ListReader list = reader.getListField(1 * POINTERS, FieldSize::FOUR_BYTES, nullptr);
ASSERT_EQ(3 * ELEMENTS, list.size()); ASSERT_EQ(3 * ELEMENTS, list.size());
EXPECT_EQ(200, list.getDataElement<int32_t>(0 * ELEMENTS)); EXPECT_EQ(200, list.getDataElement<int32_t>(0 * ELEMENTS));
EXPECT_EQ(201, list.getDataElement<int32_t>(1 * ELEMENTS)); EXPECT_EQ(201, list.getDataElement<int32_t>(1 * ELEMENTS));
...@@ -244,20 +244,20 @@ static void checkStruct(StructReader reader) { ...@@ -244,20 +244,20 @@ static void checkStruct(StructReader reader) {
} }
{ {
ListReader list = reader.getListField(2 * REFERENCES, FieldSize::INLINE_COMPOSITE, nullptr); ListReader list = reader.getListField(2 * POINTERS, FieldSize::INLINE_COMPOSITE, nullptr);
ASSERT_EQ(4 * ELEMENTS, list.size()); ASSERT_EQ(4 * ELEMENTS, list.size());
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
StructReader element = list.getStructElement(i * ELEMENTS); StructReader element = list.getStructElement(i * ELEMENTS);
EXPECT_EQ(300 + i, element.getDataField<int32_t>(0 * ELEMENTS)); EXPECT_EQ(300 + i, element.getDataField<int32_t>(0 * ELEMENTS));
EXPECT_EQ(400 + i, EXPECT_EQ(400 + i,
element.getStructField(0 * REFERENCES, STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT.words) element.getStructField(0 * POINTERS, STRUCTLIST_ELEMENT_SUBSTRUCT_DEFAULT.words)
.getDataField<int32_t>(0 * ELEMENTS)); .getDataField<int32_t>(0 * ELEMENTS));
} }
} }
{ {
// TODO: Use valid default value. // TODO: Use valid default value.
ListReader list = reader.getListField(3 * REFERENCES, FieldSize::REFERENCE, nullptr); ListReader list = reader.getListField(3 * POINTERS, FieldSize::POINTER, nullptr);
ASSERT_EQ(5 * ELEMENTS, list.size()); ASSERT_EQ(5 * ELEMENTS, list.size());
for (uint i = 0; i < 5; i++) { for (uint i = 0; i < 5; i++) {
ListReader element = list.getListElement(i * ELEMENTS, FieldSize::TWO_BYTES); ListReader element = list.getListElement(i * ELEMENTS, FieldSize::TWO_BYTES);
...@@ -276,11 +276,11 @@ TEST(WireFormat, StructRoundTrip_OneSegment) { ...@@ -276,11 +276,11 @@ TEST(WireFormat, StructRoundTrip_OneSegment) {
word* rootLocation = segment->allocate(1 * WORDS); word* rootLocation = segment->allocate(1 * WORDS);
StructBuilder builder = StructBuilder::initRoot( StructBuilder builder = StructBuilder::initRoot(
segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, FieldSize::INLINE_COMPOSITE)); segment, rootLocation, StructSize(2 * WORDS, 4 * POINTERS, FieldSize::INLINE_COMPOSITE));
setupStruct(builder); setupStruct(builder);
// word count: // word count:
// 1 root reference // 1 root pointer
// 6 root struct // 6 root struct
// 1 sub message // 1 sub message
// 2 3-element int32 list // 2 3-element int32 list
...@@ -288,10 +288,10 @@ TEST(WireFormat, StructRoundTrip_OneSegment) { ...@@ -288,10 +288,10 @@ TEST(WireFormat, StructRoundTrip_OneSegment) {
// 1 tag // 1 tag
// 12 4x struct // 12 4x struct
// 1 data segment // 1 data segment
// 1 reference segment // 1 pointer segment
// 1 sub-struct // 1 sub-struct
// 11 list list // 11 list list
// 5 references to sub-lists // 5 pointers to sub-lists
// 6 sub-lists (4x 1 word, 1x 2 words) // 6 sub-lists (4x 1 word, 1x 2 words)
// ----- // -----
// 34 // 34
...@@ -312,7 +312,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) { ...@@ -312,7 +312,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) {
word* rootLocation = segment->allocate(1 * WORDS); word* rootLocation = segment->allocate(1 * WORDS);
StructBuilder builder = StructBuilder::initRoot( StructBuilder builder = StructBuilder::initRoot(
segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, FieldSize::INLINE_COMPOSITE)); segment, rootLocation, StructSize(2 * WORDS, 4 * POINTERS, FieldSize::INLINE_COMPOSITE));
setupStruct(builder); setupStruct(builder);
// Verify that we made 15 segments. // Verify that we made 15 segments.
...@@ -320,7 +320,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) { ...@@ -320,7 +320,7 @@ TEST(WireFormat, StructRoundTrip_OneSegmentPerAllocation) {
ASSERT_EQ(15u, segments.size()); ASSERT_EQ(15u, segments.size());
// Check that each segment has the expected size. Recall that the first word of each segment will // Check that each segment has the expected size. Recall that the first word of each segment will
// actually be a reference to the first thing allocated within that segment. // actually be a pointer to the first thing allocated within that segment.
EXPECT_EQ( 1u, segments[ 0].size()); // root ref EXPECT_EQ( 1u, segments[ 0].size()); // root ref
EXPECT_EQ( 7u, segments[ 1].size()); // root struct EXPECT_EQ( 7u, segments[ 1].size()); // root struct
EXPECT_EQ( 2u, segments[ 2].size()); // sub-struct EXPECT_EQ( 2u, segments[ 2].size()); // sub-struct
...@@ -349,7 +349,7 @@ TEST(WireFormat, StructRoundTrip_MultipleSegmentsWithMultipleAllocations) { ...@@ -349,7 +349,7 @@ TEST(WireFormat, StructRoundTrip_MultipleSegmentsWithMultipleAllocations) {
word* rootLocation = segment->allocate(1 * WORDS); word* rootLocation = segment->allocate(1 * WORDS);
StructBuilder builder = StructBuilder::initRoot( StructBuilder builder = StructBuilder::initRoot(
segment, rootLocation, StructSize(2 * WORDS, 4 * REFERENCES, FieldSize::INLINE_COMPOSITE)); segment, rootLocation, StructSize(2 * WORDS, 4 * POINTERS, FieldSize::INLINE_COMPOSITE));
setupStruct(builder); setupStruct(builder);
// Verify that we made 6 segments. // Verify that we made 6 segments.
......
...@@ -34,28 +34,28 @@ namespace internal { ...@@ -34,28 +34,28 @@ namespace internal {
// ======================================================================================= // =======================================================================================
struct WireReference { struct WirePointer {
// A reference, in exactly the format in which it appears on the wire. // A pointer, in exactly the format in which it appears on the wire.
// Copying and moving is not allowed because the offset would become wrong. // Copying and moving is not allowed because the offset would become wrong.
WireReference(const WireReference& other) = delete; WirePointer(const WirePointer& other) = delete;
WireReference(WireReference&& other) = delete; WirePointer(WirePointer&& other) = delete;
WireReference& operator=(const WireReference& other) = delete; WirePointer& operator=(const WirePointer& other) = delete;
WireReference& operator=(WireReference&& other) = delete; WirePointer& operator=(WirePointer&& other) = delete;
// ----------------------------------------------------------------- // -----------------------------------------------------------------
// Common part of all references: kind + offset // Common part of all pointers: kind + offset
// //
// Actually this is not terribly common. The "offset" could actually be different things // Actually this is not terribly common. The "offset" could actually be different things
// depending on the context: // depending on the context:
// - For a regular (e.g. struct/list) reference, a signed word offset from the word immediately // - For a regular (e.g. struct/list) pointer, a signed word offset from the word immediately
// following the reference pointer. (The off-by-one means the offset is more often zero, saving // following the pointer pointer. (The off-by-one means the offset is more often zero, saving
// bytes on the wire when packed.) // bytes on the wire when packed.)
// - For an inline composite list tag (not really a reference, but structured similarly), an // - For an inline composite list tag (not really a pointer, but structured similarly), an
// element count. // element count.
// - For a FAR reference, an unsigned offset into the target segment. // - For a FAR pointer, an unsigned offset into the target segment.
// - For a FAR landing pad, zero indicates that the target value immediately follows the pad while // - For a FAR landing pad, zero indicates that the target value immediately follows the pad while
// 1 indicates that the pad is followed by another FAR reference that actually points at the // 1 indicates that the pad is followed by another FAR pointer that actually points at the
// value. // value.
enum Kind { enum Kind {
...@@ -103,12 +103,12 @@ struct WireReference { ...@@ -103,12 +103,12 @@ struct WireReference {
CAPNPROTO_ALWAYS_INLINE(WordCount farPositionInSegment() const) { CAPNPROTO_ALWAYS_INLINE(WordCount farPositionInSegment() const) {
DPRECOND(kind() == FAR, DPRECOND(kind() == FAR,
"positionInSegment() should only be called on FAR references."); "positionInSegment() should only be called on FAR pointers.");
return (offsetAndKind.get() >> 3) * WORDS; return (offsetAndKind.get() >> 3) * WORDS;
} }
CAPNPROTO_ALWAYS_INLINE(bool isDoubleFar() const) { CAPNPROTO_ALWAYS_INLINE(bool isDoubleFar() const) {
DPRECOND(kind() == FAR, DPRECOND(kind() == FAR,
"isDoubleFar() should only be called on FAR references."); "isDoubleFar() should only be called on FAR pointers.");
return (offsetAndKind.get() >> 2) & 1; return (offsetAndKind.get() >> 2) & 1;
} }
CAPNPROTO_ALWAYS_INLINE(void setFar(bool isDoubleFar, WordCount pos)) { CAPNPROTO_ALWAYS_INLINE(void setFar(bool isDoubleFar, WordCount pos)) {
...@@ -117,26 +117,26 @@ struct WireReference { ...@@ -117,26 +117,26 @@ struct WireReference {
} }
// ----------------------------------------------------------------- // -----------------------------------------------------------------
// Part of reference that depends on the kind. // Part of pointer that depends on the kind.
union { union {
uint32_t upper32Bits; uint32_t upper32Bits;
struct { struct {
WireValue<WordCount16> dataSize; WireValue<WordCount16> dataSize;
WireValue<WireReferenceCount16> refCount; WireValue<WirePointerCount16> ptrCount;
inline WordCount wordSize() const { inline WordCount wordSize() const {
return dataSize.get() + refCount.get() * WORDS_PER_REFERENCE; return dataSize.get() + ptrCount.get() * WORDS_PER_POINTER;
} }
CAPNPROTO_ALWAYS_INLINE(void set(WordCount ds, WireReferenceCount rc)) { CAPNPROTO_ALWAYS_INLINE(void set(WordCount ds, WirePointerCount rc)) {
dataSize.set(ds); dataSize.set(ds);
refCount.set(rc); ptrCount.set(rc);
} }
CAPNPROTO_ALWAYS_INLINE(void set(StructSize size)) { CAPNPROTO_ALWAYS_INLINE(void set(StructSize size)) {
dataSize.set(size.data); dataSize.set(size.data);
refCount.set(size.pointers); ptrCount.set(size.pointers);
} }
} structRef; } structRef;
// Also covers capabilities. // Also covers capabilities.
...@@ -183,14 +183,14 @@ struct WireReference { ...@@ -183,14 +183,14 @@ struct WireReference {
return (offsetAndKind.get() == 0) & (upper32Bits == 0); return (offsetAndKind.get() == 0) & (upper32Bits == 0);
} }
}; };
static_assert(sizeof(WireReference) == sizeof(word), static_assert(sizeof(WirePointer) == sizeof(word),
"capnproto::WireReference is not exactly one word. This will probably break everything."); "capnproto::WirePointer is not exactly one word. This will probably break everything.");
static_assert(REFERENCES * WORDS_PER_REFERENCE * BYTES_PER_WORD / BYTES == sizeof(WireReference), static_assert(POINTERS * WORDS_PER_POINTER * BYTES_PER_WORD / BYTES == sizeof(WirePointer),
"WORDS_PER_REFERENCE is wrong."); "WORDS_PER_POINTER is wrong.");
static_assert(REFERENCES * BYTES_PER_REFERENCE / BYTES == sizeof(WireReference), static_assert(POINTERS * BYTES_PER_POINTER / BYTES == sizeof(WirePointer),
"BYTES_PER_REFERENCE is wrong."); "BYTES_PER_POINTER is wrong.");
static_assert(REFERENCES * BITS_PER_REFERENCE / BITS_PER_BYTE / BYTES == sizeof(WireReference), static_assert(POINTERS * BITS_PER_POINTER / BITS_PER_BYTE / BYTES == sizeof(WirePointer),
"BITS_PER_REFERENCE is wrong."); "BITS_PER_POINTER is wrong.");
// ======================================================================================= // =======================================================================================
...@@ -210,39 +210,39 @@ struct WireHelpers { ...@@ -210,39 +210,39 @@ struct WireHelpers {
} }
static CAPNPROTO_ALWAYS_INLINE(word* allocate( static CAPNPROTO_ALWAYS_INLINE(word* allocate(
WireReference*& ref, SegmentBuilder*& segment, WordCount amount, WirePointer*& ref, SegmentBuilder*& segment, WordCount amount,
WireReference::Kind kind)) { WirePointer::Kind kind)) {
word* ptr = segment->allocate(amount); word* ptr = segment->allocate(amount);
if (ptr == nullptr) { if (ptr == nullptr) {
// Need to allocate in a new segment. We'll need to allocate an extra reference worth of // Need to allocate in a new segment. We'll need to allocate an extra pointer worth of
// space to act as the landing pad for a far reference. // space to act as the landing pad for a far pointer.
WordCount amountPlusRef = amount + REFERENCE_SIZE_IN_WORDS; WordCount amountPlusRef = amount + POINTER_SIZE_IN_WORDS;
segment = segment->getArena()->getSegmentWithAvailable(amountPlusRef); segment = segment->getArena()->getSegmentWithAvailable(amountPlusRef);
ptr = segment->allocate(amountPlusRef); ptr = segment->allocate(amountPlusRef);
// Set up the original reference to be a far reference to the new segment. // Set up the original pointer to be a far pointer to the new segment.
ref->setFar(false, segment->getOffsetTo(ptr)); ref->setFar(false, segment->getOffsetTo(ptr));
ref->farRef.set(segment->getSegmentId()); ref->farRef.set(segment->getSegmentId());
// Initialize the landing pad to indicate that the data immediately follows the pad. // Initialize the landing pad to indicate that the data immediately follows the pad.
ref = reinterpret_cast<WireReference*>(ptr); ref = reinterpret_cast<WirePointer*>(ptr);
ref->setKindAndTarget(kind, ptr + REFERENCE_SIZE_IN_WORDS); ref->setKindAndTarget(kind, ptr + POINTER_SIZE_IN_WORDS);
// Allocated space follows new reference. // Allocated space follows new pointer.
return ptr + REFERENCE_SIZE_IN_WORDS; return ptr + POINTER_SIZE_IN_WORDS;
} else { } else {
ref->setKindAndTarget(kind, ptr); ref->setKindAndTarget(kind, ptr);
return ptr; return ptr;
} }
} }
static CAPNPROTO_ALWAYS_INLINE(word* followFars(WireReference*& ref, SegmentBuilder*& segment)) { static CAPNPROTO_ALWAYS_INLINE(word* followFars(WirePointer*& ref, SegmentBuilder*& segment)) {
if (ref->kind() == WireReference::FAR) { if (ref->kind() == WirePointer::FAR) {
segment = segment->getArena()->getSegment(ref->farRef.segmentId.get()); segment = segment->getArena()->getSegment(ref->farRef.segmentId.get());
WireReference* pad = WirePointer* pad =
reinterpret_cast<WireReference*>(segment->getPtrUnchecked(ref->farPositionInSegment())); reinterpret_cast<WirePointer*>(segment->getPtrUnchecked(ref->farPositionInSegment()));
if (!ref->isDoubleFar()) { if (!ref->isDoubleFar()) {
ref = pad; ref = pad;
return pad->target(); return pad->target();
...@@ -260,8 +260,8 @@ struct WireHelpers { ...@@ -260,8 +260,8 @@ struct WireHelpers {
} }
static CAPNPROTO_ALWAYS_INLINE( static CAPNPROTO_ALWAYS_INLINE(
const word* followFars(const WireReference*& ref, SegmentReader*& segment)) { const word* followFars(const WirePointer*& ref, SegmentReader*& segment)) {
if (ref->kind() == WireReference::FAR) { if (ref->kind() == WirePointer::FAR) {
// Look up the segment containing the landing pad. // Look up the segment containing the landing pad.
segment = segment->getArena()->tryGetSegment(ref->farRef.segmentId.get()); segment = segment->getArena()->tryGetSegment(ref->farRef.segmentId.get());
VALIDATE_INPUT(segment != nullptr, "Message contains far pointer to unknown segment.") { VALIDATE_INPUT(segment != nullptr, "Message contains far pointer to unknown segment.") {
...@@ -270,13 +270,13 @@ struct WireHelpers { ...@@ -270,13 +270,13 @@ struct WireHelpers {
// Find the landing pad and check that it is within bounds. // Find the landing pad and check that it is within bounds.
const word* ptr = segment->getStartPtr() + ref->farPositionInSegment(); const word* ptr = segment->getStartPtr() + ref->farPositionInSegment();
WordCount padWords = (1 + ref->isDoubleFar()) * REFERENCE_SIZE_IN_WORDS; WordCount padWords = (1 + ref->isDoubleFar()) * POINTER_SIZE_IN_WORDS;
VALIDATE_INPUT(segment->containsInterval(ptr, ptr + padWords), VALIDATE_INPUT(segment->containsInterval(ptr, ptr + padWords),
"Message contains out-of-bounds far pointer.") { "Message contains out-of-bounds far pointer.") {
return nullptr; return nullptr;
} }
const WireReference* pad = reinterpret_cast<const WireReference*>(ptr); const WirePointer* pad = reinterpret_cast<const WirePointer*>(ptr);
// If this is not a double-far then the landing pad is our final pointer. // If this is not a double-far then the landing pad is our final pointer.
if (!ref->isDoubleFar()) { if (!ref->isDoubleFar()) {
...@@ -304,40 +304,40 @@ struct WireHelpers { ...@@ -304,40 +304,40 @@ struct WireHelpers {
static CAPNPROTO_ALWAYS_INLINE( static CAPNPROTO_ALWAYS_INLINE(
void copyStruct(SegmentBuilder* segment, word* dst, const word* src, void copyStruct(SegmentBuilder* segment, word* dst, const word* src,
WordCount dataSize, WireReferenceCount referenceCount)) { WordCount dataSize, WirePointerCount pointerCount)) {
memcpy(dst, src, dataSize * BYTES_PER_WORD / BYTES); memcpy(dst, src, dataSize * BYTES_PER_WORD / BYTES);
const WireReference* srcRefs = reinterpret_cast<const WireReference*>(src + dataSize); const WirePointer* srcRefs = reinterpret_cast<const WirePointer*>(src + dataSize);
WireReference* dstRefs = reinterpret_cast<WireReference*>(dst + dataSize); WirePointer* dstRefs = reinterpret_cast<WirePointer*>(dst + dataSize);
for (uint i = 0; i < referenceCount / REFERENCES; i++) { for (uint i = 0; i < pointerCount / POINTERS; i++) {
SegmentBuilder* subSegment = segment; SegmentBuilder* subSegment = segment;
WireReference* dstRef = dstRefs + i; WirePointer* dstRef = dstRefs + i;
copyMessage(subSegment, dstRef, srcRefs + i); copyMessage(subSegment, dstRef, srcRefs + i);
} }
} }
static word* copyMessage( static word* copyMessage(
SegmentBuilder*& segment, WireReference*& dst, const WireReference* src) { SegmentBuilder*& segment, WirePointer*& dst, const WirePointer* src) {
// Not always-inline because it's recursive. // Not always-inline because it's recursive.
switch (src->kind()) { switch (src->kind()) {
case WireReference::STRUCT: { case WirePointer::STRUCT: {
if (src->isNull()) { if (src->isNull()) {
memset(dst, 0, sizeof(WireReference)); memset(dst, 0, sizeof(WirePointer));
return nullptr; return nullptr;
} else { } else {
const word* srcPtr = src->target(); const word* srcPtr = src->target();
word* dstPtr = allocate(dst, segment, src->structRef.wordSize(), WireReference::STRUCT); word* dstPtr = allocate(dst, segment, src->structRef.wordSize(), WirePointer::STRUCT);
copyStruct(segment, dstPtr, srcPtr, src->structRef.dataSize.get(), copyStruct(segment, dstPtr, srcPtr, src->structRef.dataSize.get(),
src->structRef.refCount.get()); src->structRef.ptrCount.get());
dst->structRef.set(src->structRef.dataSize.get(), src->structRef.refCount.get()); dst->structRef.set(src->structRef.dataSize.get(), src->structRef.ptrCount.get());
return dstPtr; return dstPtr;
} }
} }
case WireReference::LIST: { case WirePointer::LIST: {
switch (src->listRef.elementSize()) { switch (src->listRef.elementSize()) {
case FieldSize::VOID: case FieldSize::VOID:
case FieldSize::BIT: case FieldSize::BIT:
...@@ -349,52 +349,52 @@ struct WireHelpers { ...@@ -349,52 +349,52 @@ struct WireHelpers {
ElementCount64(src->listRef.elementCount()) * ElementCount64(src->listRef.elementCount()) *
dataBitsPerElement(src->listRef.elementSize())); dataBitsPerElement(src->listRef.elementSize()));
const word* srcPtr = src->target(); const word* srcPtr = src->target();
word* dstPtr = allocate(dst, segment, wordCount, WireReference::LIST); word* dstPtr = allocate(dst, segment, wordCount, WirePointer::LIST);
memcpy(dstPtr, srcPtr, wordCount * BYTES_PER_WORD / BYTES); memcpy(dstPtr, srcPtr, wordCount * BYTES_PER_WORD / BYTES);
dst->listRef.set(src->listRef.elementSize(), src->listRef.elementCount()); dst->listRef.set(src->listRef.elementSize(), src->listRef.elementCount());
return dstPtr; return dstPtr;
} }
case FieldSize::REFERENCE: { case FieldSize::POINTER: {
const WireReference* srcRefs = reinterpret_cast<const WireReference*>(src->target()); const WirePointer* srcRefs = reinterpret_cast<const WirePointer*>(src->target());
WireReference* dstRefs = reinterpret_cast<WireReference*>( WirePointer* dstRefs = reinterpret_cast<WirePointer*>(
allocate(dst, segment, src->listRef.elementCount() * allocate(dst, segment, src->listRef.elementCount() *
(1 * REFERENCES / ELEMENTS) * WORDS_PER_REFERENCE, (1 * POINTERS / ELEMENTS) * WORDS_PER_POINTER,
WireReference::LIST)); WirePointer::LIST));
uint n = src->listRef.elementCount() / ELEMENTS; uint n = src->listRef.elementCount() / ELEMENTS;
for (uint i = 0; i < n; i++) { for (uint i = 0; i < n; i++) {
SegmentBuilder* subSegment = segment; SegmentBuilder* subSegment = segment;
WireReference* dstRef = dstRefs + i; WirePointer* dstRef = dstRefs + i;
copyMessage(subSegment, dstRef, srcRefs + i); copyMessage(subSegment, dstRef, srcRefs + i);
} }
dst->listRef.set(FieldSize::REFERENCE, src->listRef.elementCount()); dst->listRef.set(FieldSize::POINTER, src->listRef.elementCount());
return reinterpret_cast<word*>(dstRefs); return reinterpret_cast<word*>(dstRefs);
} }
case FieldSize::INLINE_COMPOSITE: { case FieldSize::INLINE_COMPOSITE: {
const word* srcPtr = src->target(); const word* srcPtr = src->target();
word* dstPtr = allocate(dst, segment, word* dstPtr = allocate(dst, segment,
src->listRef.inlineCompositeWordCount() + REFERENCE_SIZE_IN_WORDS, src->listRef.inlineCompositeWordCount() + POINTER_SIZE_IN_WORDS,
WireReference::LIST); WirePointer::LIST);
dst->listRef.setInlineComposite(src->listRef.inlineCompositeWordCount()); dst->listRef.setInlineComposite(src->listRef.inlineCompositeWordCount());
const WireReference* srcTag = reinterpret_cast<const WireReference*>(srcPtr); const WirePointer* srcTag = reinterpret_cast<const WirePointer*>(srcPtr);
memcpy(dstPtr, srcTag, sizeof(WireReference)); memcpy(dstPtr, srcTag, sizeof(WirePointer));
const word* srcElement = srcPtr + REFERENCE_SIZE_IN_WORDS; const word* srcElement = srcPtr + POINTER_SIZE_IN_WORDS;
word* dstElement = dstPtr + REFERENCE_SIZE_IN_WORDS; word* dstElement = dstPtr + POINTER_SIZE_IN_WORDS;
CHECK(srcTag->kind() == WireReference::STRUCT, CHECK(srcTag->kind() == WirePointer::STRUCT,
"INLINE_COMPOSITE of lists is not yet supported."); "INLINE_COMPOSITE of lists is not yet supported.");
uint n = srcTag->inlineCompositeListElementCount() / ELEMENTS; uint n = srcTag->inlineCompositeListElementCount() / ELEMENTS;
for (uint i = 0; i < n; i++) { for (uint i = 0; i < n; i++) {
copyStruct(segment, dstElement, srcElement, copyStruct(segment, dstElement, srcElement,
srcTag->structRef.dataSize.get(), srcTag->structRef.refCount.get()); srcTag->structRef.dataSize.get(), srcTag->structRef.ptrCount.get());
srcElement += srcTag->structRef.wordSize(); srcElement += srcTag->structRef.wordSize();
dstElement += srcTag->structRef.wordSize(); dstElement += srcTag->structRef.wordSize();
} }
...@@ -411,18 +411,18 @@ struct WireHelpers { ...@@ -411,18 +411,18 @@ struct WireHelpers {
return nullptr; return nullptr;
} }
static void transferPointer(SegmentBuilder* dstSegment, WireReference* dst, static void transferPointer(SegmentBuilder* dstSegment, WirePointer* dst,
SegmentBuilder* srcSegment, WireReference* src) { SegmentBuilder* srcSegment, WirePointer* src) {
// Make *dst point to the same object as *src. Both must reside in the same message, but can // Make *dst point to the same object as *src. Both must reside in the same message, but can
// be in different segments. Not always-inline because this is rarely used. // be in different segments. Not always-inline because this is rarely used.
if (src->isNull()) { if (src->isNull()) {
memset(dst, 0, sizeof(WireReference)); memset(dst, 0, sizeof(WirePointer));
} else if (src->kind() == WireReference::FAR) { } else if (src->kind() == WirePointer::FAR) {
// Far pointers are position-independent, so we can just copy. // Far pointers are position-independent, so we can just copy.
memcpy(dst, src, sizeof(WireReference)); memcpy(dst, src, sizeof(WirePointer));
} else if (dstSegment == srcSegment) { } else if (dstSegment == srcSegment) {
// Same segment, so create a direct reference. // Same segment, so create a direct pointer.
dst->setKindAndTarget(src->kind(), src->target()); dst->setKindAndTarget(src->kind(), src->target());
// We can just copy the upper 32 bits. (Use memcpy() to comply with aliasing rules.) // We can just copy the upper 32 bits. (Use memcpy() to comply with aliasing rules.)
...@@ -431,12 +431,12 @@ struct WireHelpers { ...@@ -431,12 +431,12 @@ struct WireHelpers {
// Need to create a far pointer. Try to allocate it in the same segment as the source, so // Need to create a far pointer. Try to allocate it in the same segment as the source, so
// that it doesn't need to be a double-far. // that it doesn't need to be a double-far.
WireReference* landingPad = WirePointer* landingPad =
reinterpret_cast<WireReference*>(srcSegment->allocate(1 * WORDS)); reinterpret_cast<WirePointer*>(srcSegment->allocate(1 * WORDS));
if (landingPad == nullptr) { if (landingPad == nullptr) {
// Darn, need a double-far. // Darn, need a double-far.
SegmentBuilder* farSegment = srcSegment->getArena()->getSegmentWithAvailable(2 * WORDS); SegmentBuilder* farSegment = srcSegment->getArena()->getSegmentWithAvailable(2 * WORDS);
landingPad = reinterpret_cast<WireReference*>(farSegment->allocate(2 * WORDS)); landingPad = reinterpret_cast<WirePointer*>(farSegment->allocate(2 * WORDS));
DCHECK(landingPad != nullptr, DCHECK(landingPad != nullptr,
"getSegmentWithAvailable() returned segment without space available."); "getSegmentWithAvailable() returned segment without space available.");
...@@ -461,48 +461,48 @@ struct WireHelpers { ...@@ -461,48 +461,48 @@ struct WireHelpers {
// ----------------------------------------------------------------- // -----------------------------------------------------------------
static CAPNPROTO_ALWAYS_INLINE(StructBuilder initStructReference( static CAPNPROTO_ALWAYS_INLINE(StructBuilder initStructPointer(
WireReference* ref, SegmentBuilder* segment, StructSize size)) { WirePointer* ref, SegmentBuilder* segment, StructSize size)) {
// Allocate space for the new struct. Newly-allocated space is automatically zeroed. // Allocate space for the new struct. Newly-allocated space is automatically zeroed.
word* ptr = allocate(ref, segment, size.total(), WireReference::STRUCT); word* ptr = allocate(ref, segment, size.total(), WirePointer::STRUCT);
// Initialize the reference. // Initialize the pointer.
ref->structRef.set(size); ref->structRef.set(size);
// Build the StructBuilder. // Build the StructBuilder.
return StructBuilder(segment, ptr, reinterpret_cast<WireReference*>(ptr + size.data), return StructBuilder(segment, ptr, reinterpret_cast<WirePointer*>(ptr + size.data),
size.data * BITS_PER_WORD, size.pointers, 0 * BITS); size.data * BITS_PER_WORD, size.pointers, 0 * BITS);
} }
static CAPNPROTO_ALWAYS_INLINE(StructBuilder getWritableStructReference( static CAPNPROTO_ALWAYS_INLINE(StructBuilder getWritableStructPointer(
WireReference* ref, SegmentBuilder* segment, StructSize size, const word* defaultValue)) { WirePointer* ref, SegmentBuilder* segment, StructSize size, const word* defaultValue)) {
word* ptr; word* ptr;
if (ref->isNull()) { if (ref->isNull()) {
useDefault: useDefault:
if (defaultValue == nullptr || if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) { reinterpret_cast<const WirePointer*>(defaultValue)->isNull()) {
ptr = allocate(ref, segment, size.total(), WireReference::STRUCT); ptr = allocate(ref, segment, size.total(), WirePointer::STRUCT);
ref->structRef.set(size); ref->structRef.set(size);
} else { } else {
ptr = copyMessage(segment, ref, reinterpret_cast<const WireReference*>(defaultValue)); ptr = copyMessage(segment, ref, reinterpret_cast<const WirePointer*>(defaultValue));
} }
return StructBuilder(segment, ptr, reinterpret_cast<WireReference*>(ptr + size.data), return StructBuilder(segment, ptr, reinterpret_cast<WirePointer*>(ptr + size.data),
size.data * BITS_PER_WORD, size.pointers, 0 * BITS); size.data * BITS_PER_WORD, size.pointers, 0 * BITS);
} else { } else {
WireReference* oldRef = ref; WirePointer* oldRef = ref;
SegmentBuilder* oldSegment = segment; SegmentBuilder* oldSegment = segment;
word* oldPtr = followFars(oldRef, oldSegment); word* oldPtr = followFars(oldRef, oldSegment);
VALIDATE_INPUT(oldRef->kind() == WireReference::STRUCT, VALIDATE_INPUT(oldRef->kind() == WirePointer::STRUCT,
"Message contains non-struct reference where struct reference was expected.") { "Message contains non-struct pointer where struct pointer was expected.") {
goto useDefault; goto useDefault;
} }
WordCount oldDataSize = oldRef->structRef.dataSize.get(); WordCount oldDataSize = oldRef->structRef.dataSize.get();
WireReferenceCount oldPointerCount = oldRef->structRef.refCount.get(); WirePointerCount oldPointerCount = oldRef->structRef.ptrCount.get();
WireReference* oldPointerSection = WirePointer* oldPointerSection =
reinterpret_cast<WireReference*>(oldPtr + oldDataSize); reinterpret_cast<WirePointer*>(oldPtr + oldDataSize);
if (oldDataSize < size.data || oldPointerCount < size.pointers) { if (oldDataSize < size.data || oldPointerCount < size.pointers) {
// The space allocated for this struct is too small. Unlike with readers, we can't just // The space allocated for this struct is too small. Unlike with readers, we can't just
...@@ -510,19 +510,19 @@ struct WireHelpers { ...@@ -510,19 +510,19 @@ struct WireHelpers {
// Instead, we have to copy the struct to a new space now. // Instead, we have to copy the struct to a new space now.
WordCount newDataSize = std::max<WordCount>(oldDataSize, size.data); WordCount newDataSize = std::max<WordCount>(oldDataSize, size.data);
WireReferenceCount newPointerCount = WirePointerCount newPointerCount =
std::max<WireReferenceCount>(oldPointerCount, size.pointers); std::max<WirePointerCount>(oldPointerCount, size.pointers);
WordCount totalSize = newDataSize + newPointerCount * WORDS_PER_REFERENCE; WordCount totalSize = newDataSize + newPointerCount * WORDS_PER_POINTER;
ptr = allocate(ref, segment, totalSize, WireReference::STRUCT); ptr = allocate(ref, segment, totalSize, WirePointer::STRUCT);
ref->structRef.set(newDataSize, newPointerCount); ref->structRef.set(newDataSize, newPointerCount);
// Copy data section. // Copy data section.
memcpy(ptr, oldPtr, oldDataSize * BYTES_PER_WORD / BYTES); memcpy(ptr, oldPtr, oldDataSize * BYTES_PER_WORD / BYTES);
// Copy pointer section. // Copy pointer section.
WireReference* newPointerSection = reinterpret_cast<WireReference*>(ptr + newDataSize); WirePointer* newPointerSection = reinterpret_cast<WirePointer*>(ptr + newDataSize);
for (uint i = 0; i < oldPointerCount / REFERENCES; i++) { for (uint i = 0; i < oldPointerCount / POINTERS; i++) {
transferPointer(segment, newPointerSection + i, oldSegment, oldPointerSection + i); transferPointer(segment, newPointerSection + i, oldSegment, oldPointerSection + i);
} }
...@@ -535,233 +535,233 @@ struct WireHelpers { ...@@ -535,233 +535,233 @@ struct WireHelpers {
} }
} }
static CAPNPROTO_ALWAYS_INLINE(ListBuilder initListReference( static CAPNPROTO_ALWAYS_INLINE(ListBuilder initListPointer(
WireReference* ref, SegmentBuilder* segment, ElementCount elementCount, WirePointer* ref, SegmentBuilder* segment, ElementCount elementCount,
FieldSize elementSize)) { FieldSize elementSize)) {
DPRECOND(elementSize != FieldSize::INLINE_COMPOSITE, DPRECOND(elementSize != FieldSize::INLINE_COMPOSITE,
"Should have called initStructListReference() instead."); "Should have called initStructListPointer() instead.");
BitCount dataSize = dataBitsPerElement(elementSize) * ELEMENTS; BitCount dataSize = dataBitsPerElement(elementSize) * ELEMENTS;
WireReferenceCount referenceCount = pointersPerElement(elementSize) * ELEMENTS; WirePointerCount pointerCount = pointersPerElement(elementSize) * ELEMENTS;
auto step = (dataSize + referenceCount * BITS_PER_REFERENCE) / ELEMENTS; auto step = (dataSize + pointerCount * BITS_PER_POINTER) / ELEMENTS;
// Calculate size of the list. // Calculate size of the list.
WordCount wordCount = roundUpToWords(ElementCount64(elementCount) * step); WordCount wordCount = roundUpToWords(ElementCount64(elementCount) * step);
// Allocate the list. // Allocate the list.
word* ptr = allocate(ref, segment, wordCount, WireReference::LIST); word* ptr = allocate(ref, segment, wordCount, WirePointer::LIST);
// Initialize the reference. // Initialize the pointer.
ref->listRef.set(elementSize, elementCount); ref->listRef.set(elementSize, elementCount);
// Build the ListBuilder. // Build the ListBuilder.
return ListBuilder(segment, ptr, step, elementCount, dataSize, referenceCount); return ListBuilder(segment, ptr, step, elementCount, dataSize, pointerCount);
} }
static CAPNPROTO_ALWAYS_INLINE(ListBuilder initStructListReference( static CAPNPROTO_ALWAYS_INLINE(ListBuilder initStructListPointer(
WireReference* ref, SegmentBuilder* segment, ElementCount elementCount, WirePointer* ref, SegmentBuilder* segment, ElementCount 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 initListReference(ref, segment, elementCount, elementSize.preferredListEncoding); return initListPointer(ref, segment, elementCount, elementSize.preferredListEncoding);
} }
auto wordsPerElement = elementSize.total() / ELEMENTS; auto wordsPerElement = elementSize.total() / ELEMENTS;
// Allocate the list, prefixed by a single WireReference. // Allocate the list, prefixed by a single WirePointer.
WordCount wordCount = elementCount * wordsPerElement; WordCount wordCount = elementCount * wordsPerElement;
word* ptr = allocate(ref, segment, REFERENCE_SIZE_IN_WORDS + wordCount, WireReference::LIST); word* ptr = allocate(ref, segment, POINTER_SIZE_IN_WORDS + wordCount, WirePointer::LIST);
// Initialize the reference. // Initialize the pointer.
// INLINE_COMPOSITE lists replace the element count with the word count. // INLINE_COMPOSITE lists replace the element count with the word count.
ref->listRef.setInlineComposite(wordCount); ref->listRef.setInlineComposite(wordCount);
// Initialize the list tag. // Initialize the list tag.
reinterpret_cast<WireReference*>(ptr)->setKindAndInlineCompositeListElementCount( reinterpret_cast<WirePointer*>(ptr)->setKindAndInlineCompositeListElementCount(
WireReference::STRUCT, elementCount); WirePointer::STRUCT, elementCount);
reinterpret_cast<WireReference*>(ptr)->structRef.set(elementSize); reinterpret_cast<WirePointer*>(ptr)->structRef.set(elementSize);
ptr += REFERENCE_SIZE_IN_WORDS; ptr += POINTER_SIZE_IN_WORDS;
// Build the ListBuilder. // Build the ListBuilder.
return ListBuilder(segment, ptr, wordsPerElement * BITS_PER_WORD, elementCount, return ListBuilder(segment, ptr, wordsPerElement * BITS_PER_WORD, elementCount,
elementSize.data * BITS_PER_WORD, elementSize.pointers); elementSize.data * BITS_PER_WORD, elementSize.pointers);
} }
static CAPNPROTO_ALWAYS_INLINE(ListBuilder getWritableListReference( static CAPNPROTO_ALWAYS_INLINE(ListBuilder getWritableListPointer(
WireReference* ref, SegmentBuilder* segment, const word* defaultValue)) { WirePointer* ref, SegmentBuilder* segment, const word* defaultValue)) {
const WireReference* defaultRef = reinterpret_cast<const WireReference*>(defaultValue); const WirePointer* defaultRef = reinterpret_cast<const WirePointer*>(defaultValue);
word* ptr; word* ptr;
if (ref->isNull()) { if (ref->isNull()) {
if (defaultValue == nullptr || if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) { reinterpret_cast<const WirePointer*>(defaultValue)->isNull()) {
return ListBuilder(); return ListBuilder();
} }
ptr = copyMessage(segment, ref, defaultRef); ptr = copyMessage(segment, ref, defaultRef);
} else { } else {
ptr = followFars(ref, segment); ptr = followFars(ref, segment);
PRECOND(ref->kind() == WireReference::LIST, PRECOND(ref->kind() == WirePointer::LIST,
"Called getList{Field,Element}() but existing reference is not a list."); "Called getList{Field,Element}() but existing pointer is not a list.");
} }
if (ref->listRef.elementSize() == FieldSize::INLINE_COMPOSITE) { if (ref->listRef.elementSize() == FieldSize::INLINE_COMPOSITE) {
// Read the tag to get the actual element count. // Read the tag to get the actual element count.
WireReference* tag = reinterpret_cast<WireReference*>(ptr); WirePointer* tag = reinterpret_cast<WirePointer*>(ptr);
PRECOND(tag->kind() == WireReference::STRUCT, PRECOND(tag->kind() == WirePointer::STRUCT,
"INLINE_COMPOSITE list with non-STRUCT elements not supported."); "INLINE_COMPOSITE list with non-STRUCT elements not supported.");
// First list element is at tag + 1 reference. // First list element is at tag + 1 pointer.
return ListBuilder(segment, tag + 1, tag->structRef.wordSize() * BITS_PER_WORD / ELEMENTS, return ListBuilder(segment, tag + 1, tag->structRef.wordSize() * BITS_PER_WORD / ELEMENTS,
tag->inlineCompositeListElementCount(), tag->inlineCompositeListElementCount(),
tag->structRef.dataSize.get() * BITS_PER_WORD, tag->structRef.dataSize.get() * BITS_PER_WORD,
tag->structRef.refCount.get()); tag->structRef.ptrCount.get());
} else { } else {
BitCount dataSize = dataBitsPerElement(ref->listRef.elementSize()) * ELEMENTS; BitCount dataSize = dataBitsPerElement(ref->listRef.elementSize()) * ELEMENTS;
WireReferenceCount referenceCount = pointersPerElement(ref->listRef.elementSize()) * ELEMENTS; WirePointerCount pointerCount = pointersPerElement(ref->listRef.elementSize()) * ELEMENTS;
auto step = (dataSize + referenceCount * BITS_PER_REFERENCE) / ELEMENTS; auto step = (dataSize + pointerCount * BITS_PER_POINTER) / ELEMENTS;
return ListBuilder(segment, ptr, step, ref->listRef.elementCount(), dataSize, referenceCount); return ListBuilder(segment, ptr, step, ref->listRef.elementCount(), dataSize, pointerCount);
} }
} }
static CAPNPROTO_ALWAYS_INLINE(Text::Builder initTextReference( static CAPNPROTO_ALWAYS_INLINE(Text::Builder initTextPointer(
WireReference* ref, SegmentBuilder* segment, ByteCount size)) { WirePointer* ref, SegmentBuilder* segment, ByteCount size)) {
// The byte list must include a NUL terminator. // The byte list must include a NUL terminator.
ByteCount byteSize = size + 1 * BYTES; ByteCount byteSize = size + 1 * BYTES;
// Allocate the space. // Allocate the space.
word* ptr = allocate(ref, segment, roundUpToWords(byteSize), WireReference::LIST); word* ptr = allocate(ref, segment, roundUpToWords(byteSize), WirePointer::LIST);
// Initialize the reference. // Initialize the pointer.
ref->listRef.set(FieldSize::BYTE, byteSize * (1 * ELEMENTS / BYTES)); ref->listRef.set(FieldSize::BYTE, byteSize * (1 * ELEMENTS / BYTES));
// Build the Text::Builder. This will initialize the NUL terminator. // Build the Text::Builder. This will initialize the NUL terminator.
return Text::Builder(reinterpret_cast<char*>(ptr), size / BYTES); return Text::Builder(reinterpret_cast<char*>(ptr), size / BYTES);
} }
static CAPNPROTO_ALWAYS_INLINE(void setTextReference( static CAPNPROTO_ALWAYS_INLINE(void setTextPointer(
WireReference* ref, SegmentBuilder* segment, Text::Reader value)) { WirePointer* ref, SegmentBuilder* segment, Text::Reader value)) {
initTextReference(ref, segment, value.size() * BYTES).copyFrom(value); initTextPointer(ref, segment, value.size() * BYTES).copyFrom(value);
} }
static CAPNPROTO_ALWAYS_INLINE(Text::Builder getWritableTextReference( static CAPNPROTO_ALWAYS_INLINE(Text::Builder getWritableTextPointer(
WireReference* ref, SegmentBuilder* segment, WirePointer* ref, SegmentBuilder* segment,
const void* defaultValue, ByteCount defaultSize)) { const void* defaultValue, ByteCount defaultSize)) {
if (ref->isNull()) { if (ref->isNull()) {
Text::Builder builder = initTextReference(ref, segment, defaultSize); Text::Builder builder = initTextPointer(ref, segment, defaultSize);
builder.copyFrom(defaultValue); builder.copyFrom(defaultValue);
return builder; return builder;
} else { } else {
word* ptr = followFars(ref, segment); word* ptr = followFars(ref, segment);
PRECOND(ref->kind() == WireReference::LIST, PRECOND(ref->kind() == WirePointer::LIST,
"Called getText{Field,Element}() but existing reference is not a list."); "Called getText{Field,Element}() but existing pointer is not a list.");
PRECOND(ref->listRef.elementSize() == FieldSize::BYTE, PRECOND(ref->listRef.elementSize() == FieldSize::BYTE,
"Called getText{Field,Element}() but existing list reference is not byte-sized."); "Called getText{Field,Element}() but existing list pointer is not byte-sized.");
// Subtract 1 from the size for the NUL terminator. // Subtract 1 from the size for the NUL terminator.
return Text::Builder(reinterpret_cast<char*>(ptr), ref->listRef.elementCount() / ELEMENTS - 1); return Text::Builder(reinterpret_cast<char*>(ptr), ref->listRef.elementCount() / ELEMENTS - 1);
} }
} }
static CAPNPROTO_ALWAYS_INLINE(Data::Builder initDataReference( static CAPNPROTO_ALWAYS_INLINE(Data::Builder initDataPointer(
WireReference* ref, SegmentBuilder* segment, ByteCount size)) { WirePointer* ref, SegmentBuilder* segment, ByteCount size)) {
// Allocate the space. // Allocate the space.
word* ptr = allocate(ref, segment, roundUpToWords(size), WireReference::LIST); word* ptr = allocate(ref, segment, roundUpToWords(size), WirePointer::LIST);
// Initialize the reference. // Initialize the pointer.
ref->listRef.set(FieldSize::BYTE, size * (1 * ELEMENTS / BYTES)); ref->listRef.set(FieldSize::BYTE, size * (1 * ELEMENTS / BYTES));
// Build the Data::Builder. // Build the Data::Builder.
return Data::Builder(reinterpret_cast<char*>(ptr), size / BYTES); return Data::Builder(reinterpret_cast<char*>(ptr), size / BYTES);
} }
static CAPNPROTO_ALWAYS_INLINE(void setDataReference( static CAPNPROTO_ALWAYS_INLINE(void setDataPointer(
WireReference* ref, SegmentBuilder* segment, Data::Reader value)) { WirePointer* ref, SegmentBuilder* segment, Data::Reader value)) {
initDataReference(ref, segment, value.size() * BYTES).copyFrom(value); initDataPointer(ref, segment, value.size() * BYTES).copyFrom(value);
} }
static CAPNPROTO_ALWAYS_INLINE(Data::Builder getWritableDataReference( static CAPNPROTO_ALWAYS_INLINE(Data::Builder getWritableDataPointer(
WireReference* ref, SegmentBuilder* segment, WirePointer* ref, SegmentBuilder* segment,
const void* defaultValue, ByteCount defaultSize)) { const void* defaultValue, ByteCount defaultSize)) {
if (ref->isNull()) { if (ref->isNull()) {
Data::Builder builder = initDataReference(ref, segment, defaultSize); Data::Builder builder = initDataPointer(ref, segment, defaultSize);
builder.copyFrom(defaultValue); builder.copyFrom(defaultValue);
return builder; return builder;
} else { } else {
word* ptr = followFars(ref, segment); word* ptr = followFars(ref, segment);
PRECOND(ref->kind() == WireReference::LIST, PRECOND(ref->kind() == WirePointer::LIST,
"Called getData{Field,Element}() but existing reference is not a list."); "Called getData{Field,Element}() but existing pointer is not a list.");
PRECOND(ref->listRef.elementSize() == FieldSize::BYTE, PRECOND(ref->listRef.elementSize() == FieldSize::BYTE,
"Called getData{Field,Element}() but existing list reference is not byte-sized."); "Called getData{Field,Element}() but existing list pointer is not byte-sized.");
return Data::Builder(reinterpret_cast<char*>(ptr), ref->listRef.elementCount() / ELEMENTS); return Data::Builder(reinterpret_cast<char*>(ptr), ref->listRef.elementCount() / ELEMENTS);
} }
} }
static CAPNPROTO_ALWAYS_INLINE(ObjectBuilder getWritableObjectReference( static CAPNPROTO_ALWAYS_INLINE(ObjectBuilder getWritableObjectPointer(
SegmentBuilder* segment, WireReference* ref, const word* defaultValue)) { SegmentBuilder* segment, WirePointer* ref, const word* defaultValue)) {
word* ptr; word* ptr;
if (ref->isNull()) { if (ref->isNull()) {
if (defaultValue == nullptr || if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) { reinterpret_cast<const WirePointer*>(defaultValue)->isNull()) {
return ObjectBuilder(); return ObjectBuilder();
} else { } else {
ptr = copyMessage(segment, ref, reinterpret_cast<const WireReference*>(defaultValue)); ptr = copyMessage(segment, ref, reinterpret_cast<const WirePointer*>(defaultValue));
} }
} else { } else {
ptr = followFars(ref, segment); ptr = followFars(ref, segment);
} }
if (ref->kind() == WireReference::LIST) { if (ref->kind() == WirePointer::LIST) {
if (ref->listRef.elementSize() == FieldSize::INLINE_COMPOSITE) { if (ref->listRef.elementSize() == FieldSize::INLINE_COMPOSITE) {
// Read the tag to get the actual element count. // Read the tag to get the actual element count.
WireReference* tag = reinterpret_cast<WireReference*>(ptr); WirePointer* tag = reinterpret_cast<WirePointer*>(ptr);
PRECOND(tag->kind() == WireReference::STRUCT, PRECOND(tag->kind() == WirePointer::STRUCT,
"INLINE_COMPOSITE list with non-STRUCT elements not supported."); "INLINE_COMPOSITE list with non-STRUCT elements not supported.");
// First list element is at tag + 1 reference. // First list element is at tag + 1 pointer.
return ObjectBuilder( return ObjectBuilder(
ListBuilder(segment, tag + 1, tag->structRef.wordSize() * BITS_PER_WORD / ELEMENTS, ListBuilder(segment, tag + 1, tag->structRef.wordSize() * BITS_PER_WORD / ELEMENTS,
tag->inlineCompositeListElementCount(), tag->inlineCompositeListElementCount(),
tag->structRef.dataSize.get() * BITS_PER_WORD, tag->structRef.dataSize.get() * BITS_PER_WORD,
tag->structRef.refCount.get())); tag->structRef.ptrCount.get()));
} else { } else {
BitCount dataSize = dataBitsPerElement(ref->listRef.elementSize()) * ELEMENTS; BitCount dataSize = dataBitsPerElement(ref->listRef.elementSize()) * ELEMENTS;
WireReferenceCount referenceCount = WirePointerCount pointerCount =
pointersPerElement(ref->listRef.elementSize()) * ELEMENTS; pointersPerElement(ref->listRef.elementSize()) * ELEMENTS;
auto step = (dataSize + referenceCount * BITS_PER_REFERENCE) / ELEMENTS; auto step = (dataSize + pointerCount * BITS_PER_POINTER) / ELEMENTS;
return ObjectBuilder(ListBuilder( return ObjectBuilder(ListBuilder(
segment, ptr, step, ref->listRef.elementCount(), dataSize, referenceCount)); segment, ptr, step, ref->listRef.elementCount(), dataSize, pointerCount));
} }
} else { } else {
return ObjectBuilder(StructBuilder( return ObjectBuilder(StructBuilder(
segment, ptr, segment, ptr,
reinterpret_cast<WireReference*>(ptr + ref->structRef.dataSize.get()), reinterpret_cast<WirePointer*>(ptr + ref->structRef.dataSize.get()),
ref->structRef.dataSize.get() * BITS_PER_WORD, ref->structRef.dataSize.get() * BITS_PER_WORD,
ref->structRef.refCount.get(), ref->structRef.ptrCount.get(),
0 * BITS)); 0 * BITS));
} }
} }
// ----------------------------------------------------------------- // -----------------------------------------------------------------
static CAPNPROTO_ALWAYS_INLINE(StructReader readStructReference( static CAPNPROTO_ALWAYS_INLINE(StructReader readStructPointer(
SegmentReader* segment, const WireReference* ref, const word* defaultValue, SegmentReader* segment, const WirePointer* ref, const word* defaultValue,
int nestingLimit)) { int nestingLimit)) {
const word* ptr; const word* ptr;
if (ref == nullptr || ref->isNull()) { if (ref == nullptr || ref->isNull()) {
useDefault: useDefault:
if (defaultValue == nullptr || if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) { reinterpret_cast<const WirePointer*>(defaultValue)->isNull()) {
return StructReader(nullptr, nullptr, nullptr, 0 * BITS, 0 * REFERENCES, 0 * BITS, return StructReader(nullptr, nullptr, nullptr, 0 * BITS, 0 * POINTERS, 0 * BITS,
std::numeric_limits<int>::max()); std::numeric_limits<int>::max());
} }
segment = nullptr; segment = nullptr;
ref = reinterpret_cast<const WireReference*>(defaultValue); ref = reinterpret_cast<const WirePointer*>(defaultValue);
ptr = ref->target(); ptr = ref->target();
} else if (segment != nullptr) { } else if (segment != nullptr) {
VALIDATE_INPUT(nestingLimit > 0, VALIDATE_INPUT(nestingLimit > 0,
...@@ -775,13 +775,13 @@ struct WireHelpers { ...@@ -775,13 +775,13 @@ struct WireHelpers {
goto useDefault; goto useDefault;
} }
VALIDATE_INPUT(ref->kind() == WireReference::STRUCT, VALIDATE_INPUT(ref->kind() == WirePointer::STRUCT,
"Message contains non-struct reference where struct reference was expected.") { "Message contains non-struct pointer where struct pointer was expected.") {
goto useDefault; goto useDefault;
} }
VALIDATE_INPUT(segment->containsInterval(ptr, ptr + ref->structRef.wordSize()), VALIDATE_INPUT(segment->containsInterval(ptr, ptr + ref->structRef.wordSize()),
"Message contained out-of-bounds struct reference.") { "Message contained out-of-bounds struct pointer.") {
goto useDefault; goto useDefault;
} }
} else { } else {
...@@ -790,24 +790,24 @@ struct WireHelpers { ...@@ -790,24 +790,24 @@ struct WireHelpers {
} }
return StructReader( return StructReader(
segment, ptr, reinterpret_cast<const WireReference*>(ptr + ref->structRef.dataSize.get()), segment, ptr, reinterpret_cast<const WirePointer*>(ptr + ref->structRef.dataSize.get()),
ref->structRef.dataSize.get() * BITS_PER_WORD, ref->structRef.dataSize.get() * BITS_PER_WORD,
ref->structRef.refCount.get(), ref->structRef.ptrCount.get(),
0 * BITS, nestingLimit - 1); 0 * BITS, nestingLimit - 1);
} }
static CAPNPROTO_ALWAYS_INLINE(ListReader readListReference( static CAPNPROTO_ALWAYS_INLINE(ListReader readListPointer(
SegmentReader* segment, const WireReference* ref, const word* defaultValue, SegmentReader* segment, const WirePointer* ref, const word* defaultValue,
FieldSize expectedElementSize, int nestingLimit)) { FieldSize expectedElementSize, int nestingLimit)) {
const word* ptr; const word* ptr;
if (ref == nullptr || ref->isNull()) { if (ref == nullptr || ref->isNull()) {
useDefault: useDefault:
if (defaultValue == nullptr || if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) { reinterpret_cast<const WirePointer*>(defaultValue)->isNull()) {
return ListReader(); return ListReader();
} }
segment = nullptr; segment = nullptr;
ref = reinterpret_cast<const WireReference*>(defaultValue); ref = reinterpret_cast<const WirePointer*>(defaultValue);
ptr = ref->target(); ptr = ref->target();
} else if (segment != nullptr) { } else if (segment != nullptr) {
VALIDATE_INPUT(nestingLimit > 0, VALIDATE_INPUT(nestingLimit > 0,
...@@ -821,8 +821,8 @@ struct WireHelpers { ...@@ -821,8 +821,8 @@ struct WireHelpers {
goto useDefault; goto useDefault;
} }
VALIDATE_INPUT(ref->kind() == WireReference::LIST, VALIDATE_INPUT(ref->kind() == WirePointer::LIST,
"Message contains non-list reference where list reference was expected.") { "Message contains non-list pointer where list pointer was expected.") {
goto useDefault; goto useDefault;
} }
} else { } else {
...@@ -836,17 +836,17 @@ struct WireHelpers { ...@@ -836,17 +836,17 @@ struct WireHelpers {
WordCount wordCount = ref->listRef.inlineCompositeWordCount(); WordCount wordCount = ref->listRef.inlineCompositeWordCount();
// An INLINE_COMPOSITE list points to a tag, which is formatted like a reference. // An INLINE_COMPOSITE list points to a tag, which is formatted like a pointer.
const WireReference* tag = reinterpret_cast<const WireReference*>(ptr); const WirePointer* tag = reinterpret_cast<const WirePointer*>(ptr);
ptr += REFERENCE_SIZE_IN_WORDS; ptr += POINTER_SIZE_IN_WORDS;
if (segment != nullptr) { if (segment != nullptr) {
VALIDATE_INPUT(segment->containsInterval(ptr - REFERENCE_SIZE_IN_WORDS, ptr + wordCount), VALIDATE_INPUT(segment->containsInterval(ptr - POINTER_SIZE_IN_WORDS, ptr + wordCount),
"Message contains out-of-bounds list reference.") { "Message contains out-of-bounds list pointer.") {
goto useDefault; goto useDefault;
} }
VALIDATE_INPUT(tag->kind() == WireReference::STRUCT, VALIDATE_INPUT(tag->kind() == WirePointer::STRUCT,
"INLINE_COMPOSITE lists of non-STRUCT type are not supported.") { "INLINE_COMPOSITE lists of non-STRUCT type are not supported.") {
goto useDefault; goto useDefault;
} }
...@@ -885,12 +885,12 @@ struct WireHelpers { ...@@ -885,12 +885,12 @@ struct WireHelpers {
} }
break; break;
case FieldSize::REFERENCE: case FieldSize::POINTER:
// We expected a list of references but got a list of structs. Assuming the first field // We expected a list of pointers but got a list of structs. Assuming the first field
// in the struct is the reference we were looking for, we want to munge the pointer to // in the struct is the pointer we were looking for, we want to munge the pointer to
// point at the first element's reference segment. // point at the first element's pointer segment.
ptr += tag->structRef.dataSize.get(); ptr += tag->structRef.dataSize.get();
VALIDATE_INPUT(tag->structRef.refCount.get() > 0 * REFERENCES, VALIDATE_INPUT(tag->structRef.ptrCount.get() > 0 * POINTERS,
"Expected a pointer list, but got a list of data-only structs.") { "Expected a pointer list, but got a list of data-only structs.") {
goto useDefault; goto useDefault;
} }
...@@ -906,7 +906,7 @@ struct WireHelpers { ...@@ -906,7 +906,7 @@ struct WireHelpers {
size = tag->inlineCompositeListElementCount(); size = tag->inlineCompositeListElementCount();
wordsPerElement = tag->structRef.wordSize() / ELEMENTS; wordsPerElement = tag->structRef.wordSize() / ELEMENTS;
if (expectedElementSize == FieldSize::REFERENCE) { if (expectedElementSize == FieldSize::POINTER) {
ptr += tag->structRef.dataSize.get(); ptr += tag->structRef.dataSize.get();
} }
} }
...@@ -914,20 +914,20 @@ struct WireHelpers { ...@@ -914,20 +914,20 @@ struct WireHelpers {
return ListReader( return ListReader(
segment, ptr, size, wordsPerElement * BITS_PER_WORD, segment, ptr, size, wordsPerElement * BITS_PER_WORD,
tag->structRef.dataSize.get() * BITS_PER_WORD, tag->structRef.dataSize.get() * BITS_PER_WORD,
tag->structRef.refCount.get(), nestingLimit - 1); tag->structRef.ptrCount.get(), nestingLimit - 1);
} else { } else {
// This is a primitive or pointer list, but all such lists can also be interpreted as struct // This is a primitive or pointer list, but all such lists can also be interpreted as struct
// lists. We need to compute the data size and reference count for such structs. // lists. We need to compute the data size and pointer count for such structs.
BitCount dataSize = dataBitsPerElement(ref->listRef.elementSize()) * ELEMENTS; BitCount dataSize = dataBitsPerElement(ref->listRef.elementSize()) * ELEMENTS;
WireReferenceCount referenceCount = WirePointerCount pointerCount =
pointersPerElement(ref->listRef.elementSize()) * ELEMENTS; pointersPerElement(ref->listRef.elementSize()) * ELEMENTS;
auto step = (dataSize + referenceCount * BITS_PER_REFERENCE) / ELEMENTS; auto step = (dataSize + pointerCount * BITS_PER_POINTER) / ELEMENTS;
if (segment != nullptr) { if (segment != nullptr) {
VALIDATE_INPUT(segment->containsInterval(ptr, ptr + VALIDATE_INPUT(segment->containsInterval(ptr, ptr +
roundUpToWords(ElementCount64(ref->listRef.elementCount()) * step)), roundUpToWords(ElementCount64(ref->listRef.elementCount()) * step)),
"Message contains out-of-bounds list reference.") { "Message contains out-of-bounds list pointer.") {
goto useDefault; goto useDefault;
} }
} }
...@@ -940,31 +940,31 @@ struct WireHelpers { ...@@ -940,31 +940,31 @@ struct WireHelpers {
BitCount expectedDataBitsPerElement = BitCount expectedDataBitsPerElement =
dataBitsPerElement(expectedElementSize) * ELEMENTS; dataBitsPerElement(expectedElementSize) * ELEMENTS;
WireReferenceCount expectedPointersPerElement = WirePointerCount expectedPointersPerElement =
pointersPerElement(expectedElementSize) * ELEMENTS; pointersPerElement(expectedElementSize) * ELEMENTS;
VALIDATE_INPUT(expectedDataBitsPerElement <= dataSize, VALIDATE_INPUT(expectedDataBitsPerElement <= dataSize,
"Message contained list with incompatible element type.") { "Message contained list with incompatible element type.") {
goto useDefault; goto useDefault;
} }
VALIDATE_INPUT(expectedPointersPerElement <= referenceCount, VALIDATE_INPUT(expectedPointersPerElement <= pointerCount,
"Message contained list with incompatible element type.") { "Message contained list with incompatible element type.") {
goto useDefault; goto useDefault;
} }
} }
return ListReader(segment, ptr, ref->listRef.elementCount(), step, return ListReader(segment, ptr, ref->listRef.elementCount(), step,
dataSize, referenceCount, nestingLimit - 1); dataSize, pointerCount, nestingLimit - 1);
} }
} }
static CAPNPROTO_ALWAYS_INLINE(Text::Reader readTextReference( static CAPNPROTO_ALWAYS_INLINE(Text::Reader readTextPointer(
SegmentReader* segment, const WireReference* ref, SegmentReader* segment, const WirePointer* ref,
const void* defaultValue, ByteCount defaultSize)) { const void* defaultValue, ByteCount defaultSize)) {
if (ref == nullptr || ref->isNull()) { if (ref == nullptr || ref->isNull()) {
useDefault: useDefault:
if (defaultValue == nullptr || if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) { reinterpret_cast<const WirePointer*>(defaultValue)->isNull()) {
defaultValue = ""; defaultValue = "";
} }
return Text::Reader(reinterpret_cast<const char*>(defaultValue), defaultSize / BYTES); return Text::Reader(reinterpret_cast<const char*>(defaultValue), defaultSize / BYTES);
...@@ -982,19 +982,19 @@ struct WireHelpers { ...@@ -982,19 +982,19 @@ struct WireHelpers {
uint size = ref->listRef.elementCount() / ELEMENTS; uint size = ref->listRef.elementCount() / ELEMENTS;
VALIDATE_INPUT(ref->kind() == WireReference::LIST, VALIDATE_INPUT(ref->kind() == WirePointer::LIST,
"Message contains non-list reference where text was expected.") { "Message contains non-list pointer where text was expected.") {
goto useDefault; goto useDefault;
} }
VALIDATE_INPUT(ref->listRef.elementSize() == FieldSize::BYTE, VALIDATE_INPUT(ref->listRef.elementSize() == FieldSize::BYTE,
"Message contains list reference of non-bytes where text was expected.") { "Message contains list pointer of non-bytes where text was expected.") {
goto useDefault; goto useDefault;
} }
VALIDATE_INPUT(segment->containsInterval(ptr, ptr + VALIDATE_INPUT(segment->containsInterval(ptr, ptr +
roundUpToWords(ref->listRef.elementCount() * (1 * BYTES / ELEMENTS))), roundUpToWords(ref->listRef.elementCount() * (1 * BYTES / ELEMENTS))),
"Message contained out-of-bounds text reference.") { "Message contained out-of-bounds text pointer.") {
goto useDefault; goto useDefault;
} }
...@@ -1013,8 +1013,8 @@ struct WireHelpers { ...@@ -1013,8 +1013,8 @@ struct WireHelpers {
} }
} }
static CAPNPROTO_ALWAYS_INLINE(Data::Reader readDataReference( static CAPNPROTO_ALWAYS_INLINE(Data::Reader readDataPointer(
SegmentReader* segment, const WireReference* ref, SegmentReader* segment, const WirePointer* ref,
const void* defaultValue, ByteCount defaultSize)) { const void* defaultValue, ByteCount defaultSize)) {
if (ref == nullptr || ref->isNull()) { if (ref == nullptr || ref->isNull()) {
useDefault: useDefault:
...@@ -1033,19 +1033,19 @@ struct WireHelpers { ...@@ -1033,19 +1033,19 @@ struct WireHelpers {
uint size = ref->listRef.elementCount() / ELEMENTS; uint size = ref->listRef.elementCount() / ELEMENTS;
VALIDATE_INPUT(ref->kind() == WireReference::LIST, VALIDATE_INPUT(ref->kind() == WirePointer::LIST,
"Message contains non-list reference where data was expected.") { "Message contains non-list pointer where data was expected.") {
goto useDefault; goto useDefault;
} }
VALIDATE_INPUT(ref->listRef.elementSize() == FieldSize::BYTE, VALIDATE_INPUT(ref->listRef.elementSize() == FieldSize::BYTE,
"Message contains list reference of non-bytes where data was expected.") { "Message contains list pointer of non-bytes where data was expected.") {
goto useDefault; goto useDefault;
} }
VALIDATE_INPUT(segment->containsInterval(ptr, ptr + VALIDATE_INPUT(segment->containsInterval(ptr, ptr +
roundUpToWords(ref->listRef.elementCount() * (1 * BYTES / ELEMENTS))), roundUpToWords(ref->listRef.elementCount() * (1 * BYTES / ELEMENTS))),
"Message contained out-of-bounds data reference.") { "Message contained out-of-bounds data pointer.") {
goto useDefault; goto useDefault;
} }
...@@ -1053,10 +1053,10 @@ struct WireHelpers { ...@@ -1053,10 +1053,10 @@ struct WireHelpers {
} }
} }
static CAPNPROTO_ALWAYS_INLINE(ObjectReader readObjectReference( static CAPNPROTO_ALWAYS_INLINE(ObjectReader readObjectPointer(
SegmentReader* segment, const WireReference* ref, SegmentReader* segment, const WirePointer* ref,
const word* defaultValue, int nestingLimit)) { const word* defaultValue, int nestingLimit)) {
// We can't really reuse readStructReference() and readListReference() because they are designed // We can't really reuse readStructPointer() and readListPointer() because they are designed
// for the case where we are expecting a specific type, and they do validation around that, // for the case where we are expecting a specific type, and they do validation around that,
// whereas this method is for the case where we accept any pointer. // whereas this method is for the case where we accept any pointer.
...@@ -1064,11 +1064,11 @@ struct WireHelpers { ...@@ -1064,11 +1064,11 @@ struct WireHelpers {
if (ref == nullptr || ref->isNull()) { if (ref == nullptr || ref->isNull()) {
useDefault: useDefault:
if (defaultValue == nullptr || if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) { reinterpret_cast<const WirePointer*>(defaultValue)->isNull()) {
return ObjectReader(); return ObjectReader();
} }
segment = nullptr; segment = nullptr;
ref = reinterpret_cast<const WireReference*>(defaultValue); ref = reinterpret_cast<const WirePointer*>(defaultValue);
ptr = ref->target(); ptr = ref->target();
} else if (segment != nullptr) { } else if (segment != nullptr) {
ptr = WireHelpers::followFars(ref, segment); ptr = WireHelpers::followFars(ref, segment);
...@@ -1081,7 +1081,7 @@ struct WireHelpers { ...@@ -1081,7 +1081,7 @@ struct WireHelpers {
} }
switch (ref->kind()) { switch (ref->kind()) {
case WireReference::STRUCT: case WirePointer::STRUCT:
if (segment != nullptr) { if (segment != nullptr) {
VALIDATE_INPUT(nestingLimit > 0, VALIDATE_INPUT(nestingLimit > 0,
"Message is too deeply-nested or contains cycles. See capnproto::ReadOptions.") { "Message is too deeply-nested or contains cycles. See capnproto::ReadOptions.") {
...@@ -1089,17 +1089,17 @@ struct WireHelpers { ...@@ -1089,17 +1089,17 @@ struct WireHelpers {
} }
VALIDATE_INPUT(segment->containsInterval(ptr, ptr + ref->structRef.wordSize()), VALIDATE_INPUT(segment->containsInterval(ptr, ptr + ref->structRef.wordSize()),
"Message contained out-of-bounds struct reference.") { "Message contained out-of-bounds struct pointer.") {
goto useDefault; goto useDefault;
} }
} }
return ObjectReader( return ObjectReader(
StructReader(segment, ptr, StructReader(segment, ptr,
reinterpret_cast<const WireReference*>(ptr + ref->structRef.dataSize.get()), reinterpret_cast<const WirePointer*>(ptr + ref->structRef.dataSize.get()),
ref->structRef.dataSize.get() * BITS_PER_WORD, ref->structRef.dataSize.get() * BITS_PER_WORD,
ref->structRef.refCount.get(), ref->structRef.ptrCount.get(),
0 * BITS, nestingLimit - 1)); 0 * BITS, nestingLimit - 1));
case WireReference::LIST: { case WirePointer::LIST: {
FieldSize elementSize = ref->listRef.elementSize(); FieldSize elementSize = ref->listRef.elementSize();
if (segment != nullptr) { if (segment != nullptr) {
...@@ -1111,17 +1111,17 @@ struct WireHelpers { ...@@ -1111,17 +1111,17 @@ struct WireHelpers {
if (elementSize == FieldSize::INLINE_COMPOSITE) { if (elementSize == FieldSize::INLINE_COMPOSITE) {
WordCount wordCount = ref->listRef.inlineCompositeWordCount(); WordCount wordCount = ref->listRef.inlineCompositeWordCount();
const WireReference* tag = reinterpret_cast<const WireReference*>(ptr); const WirePointer* tag = reinterpret_cast<const WirePointer*>(ptr);
ptr += REFERENCE_SIZE_IN_WORDS; ptr += POINTER_SIZE_IN_WORDS;
if (segment != nullptr) { if (segment != nullptr) {
VALIDATE_INPUT(segment->containsInterval(ptr - REFERENCE_SIZE_IN_WORDS, VALIDATE_INPUT(segment->containsInterval(ptr - POINTER_SIZE_IN_WORDS,
ptr + wordCount), ptr + wordCount),
"Message contains out-of-bounds list reference.") { "Message contains out-of-bounds list pointer.") {
goto useDefault; goto useDefault;
} }
VALIDATE_INPUT(tag->kind() == WireReference::STRUCT, VALIDATE_INPUT(tag->kind() == WirePointer::STRUCT,
"INLINE_COMPOSITE lists of non-STRUCT type are not supported.") { "INLINE_COMPOSITE lists of non-STRUCT type are not supported.") {
goto useDefault; goto useDefault;
} }
...@@ -1138,23 +1138,23 @@ struct WireHelpers { ...@@ -1138,23 +1138,23 @@ struct WireHelpers {
return ObjectReader( return ObjectReader(
ListReader(segment, ptr, elementCount, wordsPerElement * BITS_PER_WORD, ListReader(segment, ptr, elementCount, wordsPerElement * BITS_PER_WORD,
tag->structRef.dataSize.get() * BITS_PER_WORD, tag->structRef.dataSize.get() * BITS_PER_WORD,
tag->structRef.refCount.get(), nestingLimit - 1)); tag->structRef.ptrCount.get(), nestingLimit - 1));
} else { } else {
BitCount dataSize = dataBitsPerElement(elementSize) * ELEMENTS; BitCount dataSize = dataBitsPerElement(elementSize) * ELEMENTS;
WireReferenceCount referenceCount = pointersPerElement(elementSize) * ELEMENTS; WirePointerCount pointerCount = pointersPerElement(elementSize) * ELEMENTS;
auto step = (dataSize + referenceCount * BITS_PER_REFERENCE) / ELEMENTS; auto step = (dataSize + pointerCount * BITS_PER_POINTER) / ELEMENTS;
ElementCount elementCount = ref->listRef.elementCount(); ElementCount elementCount = ref->listRef.elementCount();
WordCount wordCount = roundUpToWords(ElementCount64(elementCount) * step); WordCount wordCount = roundUpToWords(ElementCount64(elementCount) * step);
if (segment != nullptr) { if (segment != nullptr) {
VALIDATE_INPUT(segment->containsInterval(ptr, ptr + wordCount), VALIDATE_INPUT(segment->containsInterval(ptr, ptr + wordCount),
"Message contains out-of-bounds list reference.") { "Message contains out-of-bounds list pointer.") {
goto useDefault; goto useDefault;
} }
} }
return ObjectReader( return ObjectReader(
ListReader(segment, ptr, elementCount, step, dataSize, referenceCount, ListReader(segment, ptr, elementCount, step, dataSize, pointerCount,
nestingLimit - 1)); nestingLimit - 1));
} }
} }
...@@ -1170,148 +1170,148 @@ struct WireHelpers { ...@@ -1170,148 +1170,148 @@ struct WireHelpers {
StructBuilder StructBuilder::initRoot( StructBuilder StructBuilder::initRoot(
SegmentBuilder* segment, word* location, StructSize size) { SegmentBuilder* segment, word* location, StructSize size) {
return WireHelpers::initStructReference( return WireHelpers::initStructPointer(
reinterpret_cast<WireReference*>(location), segment, size); reinterpret_cast<WirePointer*>(location), segment, size);
} }
StructBuilder StructBuilder::getRoot( StructBuilder StructBuilder::getRoot(
SegmentBuilder* segment, word* location, StructSize size) { SegmentBuilder* segment, word* location, StructSize size) {
return WireHelpers::getWritableStructReference( return WireHelpers::getWritableStructPointer(
reinterpret_cast<WireReference*>(location), segment, size, nullptr); reinterpret_cast<WirePointer*>(location), segment, size, nullptr);
} }
StructBuilder StructBuilder::initStructField( StructBuilder StructBuilder::initStructField(
WireReferenceCount refIndex, StructSize size) const { WirePointerCount ptrIndex, StructSize size) const {
return WireHelpers::initStructReference(references + refIndex, segment, size); return WireHelpers::initStructPointer(pointers + ptrIndex, segment, size);
} }
StructBuilder StructBuilder::getStructField( StructBuilder StructBuilder::getStructField(
WireReferenceCount refIndex, StructSize size, const word* defaultValue) const { WirePointerCount ptrIndex, StructSize size, const word* defaultValue) const {
return WireHelpers::getWritableStructReference( return WireHelpers::getWritableStructPointer(
references + refIndex, segment, size, defaultValue); pointers + ptrIndex, segment, size, defaultValue);
} }
ListBuilder StructBuilder::initListField( ListBuilder StructBuilder::initListField(
WireReferenceCount refIndex, FieldSize elementSize, ElementCount elementCount) const { WirePointerCount ptrIndex, FieldSize elementSize, ElementCount elementCount) const {
return WireHelpers::initListReference( return WireHelpers::initListPointer(
references + refIndex, segment, pointers + ptrIndex, segment,
elementCount, elementSize); elementCount, elementSize);
} }
ListBuilder StructBuilder::initStructListField( ListBuilder StructBuilder::initStructListField(
WireReferenceCount refIndex, ElementCount elementCount, StructSize elementSize) const { WirePointerCount ptrIndex, ElementCount elementCount, StructSize elementSize) const {
return WireHelpers::initStructListReference( return WireHelpers::initStructListPointer(
references + refIndex, segment, elementCount, elementSize); pointers + ptrIndex, segment, elementCount, elementSize);
} }
ListBuilder StructBuilder::getListField( ListBuilder StructBuilder::getListField(
WireReferenceCount refIndex, const word* defaultValue) const { WirePointerCount ptrIndex, const word* defaultValue) const {
return WireHelpers::getWritableListReference( return WireHelpers::getWritableListPointer(
references + refIndex, segment, defaultValue); pointers + ptrIndex, segment, defaultValue);
} }
template <> template <>
Text::Builder StructBuilder::initBlobField<Text>(WireReferenceCount refIndex, ByteCount size) const { Text::Builder StructBuilder::initBlobField<Text>(WirePointerCount ptrIndex, ByteCount size) const {
return WireHelpers::initTextReference(references + refIndex, segment, size); return WireHelpers::initTextPointer(pointers + ptrIndex, segment, size);
} }
template <> template <>
void StructBuilder::setBlobField<Text>(WireReferenceCount refIndex, Text::Reader value) const { void StructBuilder::setBlobField<Text>(WirePointerCount ptrIndex, Text::Reader value) const {
WireHelpers::setTextReference(references + refIndex, segment, value); WireHelpers::setTextPointer(pointers + ptrIndex, segment, value);
} }
template <> template <>
Text::Builder StructBuilder::getBlobField<Text>( Text::Builder StructBuilder::getBlobField<Text>(
WireReferenceCount refIndex, const void* defaultValue, ByteCount defaultSize) const { WirePointerCount ptrIndex, const void* defaultValue, ByteCount defaultSize) const {
return WireHelpers::getWritableTextReference( return WireHelpers::getWritableTextPointer(
references + refIndex, segment, defaultValue, defaultSize); pointers + ptrIndex, segment, defaultValue, defaultSize);
} }
template <> template <>
Data::Builder StructBuilder::initBlobField<Data>(WireReferenceCount refIndex, ByteCount size) const { Data::Builder StructBuilder::initBlobField<Data>(WirePointerCount ptrIndex, ByteCount size) const {
return WireHelpers::initDataReference(references + refIndex, segment, size); return WireHelpers::initDataPointer(pointers + ptrIndex, segment, size);
} }
template <> template <>
void StructBuilder::setBlobField<Data>(WireReferenceCount refIndex, Data::Reader value) const { void StructBuilder::setBlobField<Data>(WirePointerCount ptrIndex, Data::Reader value) const {
WireHelpers::setDataReference(references + refIndex, segment, value); WireHelpers::setDataPointer(pointers + ptrIndex, segment, value);
} }
template <> template <>
Data::Builder StructBuilder::getBlobField<Data>( Data::Builder StructBuilder::getBlobField<Data>(
WireReferenceCount refIndex, const void* defaultValue, ByteCount defaultSize) const { WirePointerCount ptrIndex, const void* defaultValue, ByteCount defaultSize) const {
return WireHelpers::getWritableDataReference( return WireHelpers::getWritableDataPointer(
references + refIndex, segment, defaultValue, defaultSize); pointers + ptrIndex, segment, defaultValue, defaultSize);
} }
ObjectBuilder StructBuilder::getObjectField( ObjectBuilder StructBuilder::getObjectField(
WireReferenceCount refIndex, const word* defaultValue) const { WirePointerCount ptrIndex, const word* defaultValue) const {
return WireHelpers::getWritableObjectReference(segment, references + refIndex, defaultValue); return WireHelpers::getWritableObjectPointer(segment, pointers + ptrIndex, defaultValue);
} }
StructReader StructBuilder::asReader() const { StructReader StructBuilder::asReader() const {
return StructReader(segment, data, references, return StructReader(segment, data, pointers,
dataSize, referenceCount, bit0Offset, std::numeric_limits<int>::max()); dataSize, pointerCount, bit0Offset, std::numeric_limits<int>::max());
} }
// ======================================================================================= // =======================================================================================
// StructReader // StructReader
StructReader StructReader::readRootTrusted(const word* location) { StructReader StructReader::readRootTrusted(const word* location) {
return WireHelpers::readStructReference(nullptr, reinterpret_cast<const WireReference*>(location), return WireHelpers::readStructPointer(nullptr, reinterpret_cast<const WirePointer*>(location),
nullptr, std::numeric_limits<int>::max()); nullptr, std::numeric_limits<int>::max());
} }
StructReader StructReader::readRoot( StructReader StructReader::readRoot(
const word* location, SegmentReader* segment, int nestingLimit) { const word* location, SegmentReader* segment, int nestingLimit) {
VALIDATE_INPUT(segment->containsInterval(location, location + REFERENCE_SIZE_IN_WORDS), VALIDATE_INPUT(segment->containsInterval(location, location + POINTER_SIZE_IN_WORDS),
"Root location out-of-bounds.") { "Root location out-of-bounds.") {
location = nullptr; location = nullptr;
} }
return WireHelpers::readStructReference(segment, reinterpret_cast<const WireReference*>(location), return WireHelpers::readStructPointer(segment, reinterpret_cast<const WirePointer*>(location),
nullptr, nestingLimit); nullptr, nestingLimit);
} }
StructReader StructReader::getStructField( StructReader StructReader::getStructField(
WireReferenceCount refIndex, const word* defaultValue) const { WirePointerCount ptrIndex, const word* defaultValue) const {
const WireReference* ref = refIndex >= referenceCount ? nullptr : references + refIndex; const WirePointer* ref = ptrIndex >= pointerCount ? nullptr : pointers + ptrIndex;
return WireHelpers::readStructReference(segment, ref, defaultValue, nestingLimit); return WireHelpers::readStructPointer(segment, ref, defaultValue, nestingLimit);
} }
ListReader StructReader::getListField( ListReader StructReader::getListField(
WireReferenceCount refIndex, FieldSize expectedElementSize, const word* defaultValue) const { WirePointerCount ptrIndex, FieldSize expectedElementSize, const word* defaultValue) const {
const WireReference* ref = refIndex >= referenceCount ? nullptr : references + refIndex; const WirePointer* ref = ptrIndex >= pointerCount ? nullptr : pointers + ptrIndex;
return WireHelpers::readListReference( return WireHelpers::readListPointer(
segment, ref, defaultValue, expectedElementSize, nestingLimit); segment, ref, defaultValue, expectedElementSize, nestingLimit);
} }
template <> template <>
Text::Reader StructReader::getBlobField<Text>( Text::Reader StructReader::getBlobField<Text>(
WireReferenceCount refIndex, const void* defaultValue, ByteCount defaultSize) const { WirePointerCount ptrIndex, const void* defaultValue, ByteCount defaultSize) const {
const WireReference* ref = refIndex >= referenceCount ? nullptr : references + refIndex; const WirePointer* ref = ptrIndex >= pointerCount ? nullptr : pointers + ptrIndex;
return WireHelpers::readTextReference(segment, ref, defaultValue, defaultSize); return WireHelpers::readTextPointer(segment, ref, defaultValue, defaultSize);
} }
template <> template <>
Data::Reader StructReader::getBlobField<Data>( Data::Reader StructReader::getBlobField<Data>(
WireReferenceCount refIndex, const void* defaultValue, ByteCount defaultSize) const { WirePointerCount ptrIndex, const void* defaultValue, ByteCount defaultSize) const {
const WireReference* ref = refIndex >= referenceCount ? nullptr : references + refIndex; const WirePointer* ref = ptrIndex >= pointerCount ? nullptr : pointers + ptrIndex;
return WireHelpers::readDataReference(segment, ref, defaultValue, defaultSize); return WireHelpers::readDataPointer(segment, ref, defaultValue, defaultSize);
} }
ObjectReader StructReader::getObjectField( ObjectReader StructReader::getObjectField(
WireReferenceCount refIndex, const word* defaultValue) const { WirePointerCount ptrIndex, const word* defaultValue) const {
return WireHelpers::readObjectReference( return WireHelpers::readObjectPointer(
segment, references + refIndex, defaultValue, nestingLimit); segment, pointers + ptrIndex, defaultValue, nestingLimit);
} }
const word* StructReader::getTrustedPointer(WireReferenceCount refIndex) const { const word* StructReader::getTrustedPointer(WirePointerCount ptrIndex) const {
PRECOND(segment == nullptr, "getTrustedPointer() only allowed on trusted messages."); PRECOND(segment == nullptr, "getTrustedPointer() only allowed on trusted messages.");
return reinterpret_cast<const word*>(references + refIndex); return reinterpret_cast<const word*>(pointers + ptrIndex);
} }
// ======================================================================================= // =======================================================================================
// ListBuilder // ListBuilder
Text::Builder ListBuilder::asText() { Text::Builder ListBuilder::asText() {
VALIDATE_INPUT(structDataSize == 8 * BITS && structReferenceCount == 0 * REFERENCES, VALIDATE_INPUT(structDataSize == 8 * BITS && structPointerCount == 0 * POINTERS,
"Expected Text, got list of non-bytes.") { "Expected Text, got list of non-bytes.") {
return Text::Builder(); return Text::Builder();
} }
...@@ -1333,7 +1333,7 @@ Text::Builder ListBuilder::asText() { ...@@ -1333,7 +1333,7 @@ Text::Builder ListBuilder::asText() {
} }
Data::Builder ListBuilder::asData() { Data::Builder ListBuilder::asData() {
VALIDATE_INPUT(structDataSize == 8 * BITS && structReferenceCount == 0 * REFERENCES, VALIDATE_INPUT(structDataSize == 8 * BITS && structPointerCount == 0 * POINTERS,
"Expected Text, got list of non-bytes.") { "Expected Text, got list of non-bytes.") {
return Data::Builder(); return Data::Builder();
} }
...@@ -1345,69 +1345,69 @@ StructBuilder ListBuilder::getStructElement(ElementCount index) const { ...@@ -1345,69 +1345,69 @@ StructBuilder ListBuilder::getStructElement(ElementCount index) const {
BitCount64 indexBit = ElementCount64(index) * step; BitCount64 indexBit = ElementCount64(index) * step;
byte* structData = ptr + indexBit / BITS_PER_BYTE; byte* structData = ptr + indexBit / BITS_PER_BYTE;
return StructBuilder(segment, structData, return StructBuilder(segment, structData,
reinterpret_cast<WireReference*>(structData + structDataSize / BITS_PER_BYTE), reinterpret_cast<WirePointer*>(structData + structDataSize / BITS_PER_BYTE),
structDataSize, structReferenceCount, indexBit % BITS_PER_BYTE); structDataSize, structPointerCount, indexBit % BITS_PER_BYTE);
} }
ListBuilder ListBuilder::initListElement( ListBuilder ListBuilder::initListElement(
ElementCount index, FieldSize elementSize, ElementCount elementCount) const { ElementCount index, FieldSize elementSize, ElementCount elementCount) const {
return WireHelpers::initListReference( return WireHelpers::initListPointer(
reinterpret_cast<WireReference*>(ptr + index * step / BITS_PER_BYTE), reinterpret_cast<WirePointer*>(ptr + index * step / BITS_PER_BYTE),
segment, elementCount, elementSize); segment, elementCount, elementSize);
} }
ListBuilder ListBuilder::initStructListElement( ListBuilder ListBuilder::initStructListElement(
ElementCount index, ElementCount elementCount, StructSize elementSize) const { ElementCount index, ElementCount elementCount, StructSize elementSize) const {
return WireHelpers::initStructListReference( return WireHelpers::initStructListPointer(
reinterpret_cast<WireReference*>(ptr + index * step / BITS_PER_BYTE), reinterpret_cast<WirePointer*>(ptr + index * step / BITS_PER_BYTE),
segment, elementCount, elementSize); segment, elementCount, elementSize);
} }
ListBuilder ListBuilder::getListElement(ElementCount index) const { ListBuilder ListBuilder::getListElement(ElementCount index) const {
return WireHelpers::getWritableListReference( return WireHelpers::getWritableListPointer(
reinterpret_cast<WireReference*>(ptr + index * step / BITS_PER_BYTE), segment, nullptr); reinterpret_cast<WirePointer*>(ptr + index * step / BITS_PER_BYTE), segment, nullptr);
} }
template <> template <>
Text::Builder ListBuilder::initBlobElement<Text>(ElementCount index, ByteCount size) const { Text::Builder ListBuilder::initBlobElement<Text>(ElementCount index, ByteCount size) const {
return WireHelpers::initTextReference( return WireHelpers::initTextPointer(
reinterpret_cast<WireReference*>(ptr + index * step / BITS_PER_BYTE), segment, size); reinterpret_cast<WirePointer*>(ptr + index * step / BITS_PER_BYTE), segment, size);
} }
template <> template <>
void ListBuilder::setBlobElement<Text>(ElementCount index, Text::Reader value) const { void ListBuilder::setBlobElement<Text>(ElementCount index, Text::Reader value) const {
WireHelpers::setTextReference( WireHelpers::setTextPointer(
reinterpret_cast<WireReference*>(ptr + index * step / BITS_PER_BYTE), segment, value); reinterpret_cast<WirePointer*>(ptr + index * step / BITS_PER_BYTE), segment, value);
} }
template <> template <>
Text::Builder ListBuilder::getBlobElement<Text>(ElementCount index) const { Text::Builder ListBuilder::getBlobElement<Text>(ElementCount index) const {
return WireHelpers::getWritableTextReference( return WireHelpers::getWritableTextPointer(
reinterpret_cast<WireReference*>(ptr + index * step / BITS_PER_BYTE), segment, "", 0 * BYTES); reinterpret_cast<WirePointer*>(ptr + index * step / BITS_PER_BYTE), segment, "", 0 * BYTES);
} }
template <> template <>
Data::Builder ListBuilder::initBlobElement<Data>(ElementCount index, ByteCount size) const { Data::Builder ListBuilder::initBlobElement<Data>(ElementCount index, ByteCount size) const {
return WireHelpers::initDataReference( return WireHelpers::initDataPointer(
reinterpret_cast<WireReference*>(ptr + index * step / BITS_PER_BYTE), segment, size); reinterpret_cast<WirePointer*>(ptr + index * step / BITS_PER_BYTE), segment, size);
} }
template <> template <>
void ListBuilder::setBlobElement<Data>(ElementCount index, Data::Reader value) const { void ListBuilder::setBlobElement<Data>(ElementCount index, Data::Reader value) const {
WireHelpers::setDataReference( WireHelpers::setDataPointer(
reinterpret_cast<WireReference*>(ptr + index * step / BITS_PER_BYTE), segment, value); reinterpret_cast<WirePointer*>(ptr + index * step / BITS_PER_BYTE), segment, value);
} }
template <> template <>
Data::Builder ListBuilder::getBlobElement<Data>(ElementCount index) const { Data::Builder ListBuilder::getBlobElement<Data>(ElementCount index) const {
return WireHelpers::getWritableDataReference( return WireHelpers::getWritableDataPointer(
reinterpret_cast<WireReference*>(ptr + index * step / BITS_PER_BYTE), segment, nullptr, reinterpret_cast<WirePointer*>(ptr + index * step / BITS_PER_BYTE), segment, nullptr,
0 * BYTES); 0 * BYTES);
} }
ObjectBuilder ListBuilder::getObjectElement(ElementCount index) const { ObjectBuilder ListBuilder::getObjectElement(ElementCount index) const {
return WireHelpers::getWritableObjectReference( return WireHelpers::getWritableObjectPointer(
segment, reinterpret_cast<WireReference*>(ptr + index * step / BITS_PER_BYTE), nullptr); segment, reinterpret_cast<WirePointer*>(ptr + index * step / BITS_PER_BYTE), nullptr);
} }
ListReader ListBuilder::asReader() const { ListReader ListBuilder::asReader() const {
return ListReader(segment, ptr, elementCount, step, structDataSize, structReferenceCount, return ListReader(segment, ptr, elementCount, step, structDataSize, structPointerCount,
std::numeric_limits<int>::max()); std::numeric_limits<int>::max());
} }
...@@ -1415,7 +1415,7 @@ ListReader ListBuilder::asReader() const { ...@@ -1415,7 +1415,7 @@ ListReader ListBuilder::asReader() const {
// ListReader // ListReader
Text::Reader ListReader::asText() { Text::Reader ListReader::asText() {
VALIDATE_INPUT(structDataSize == 8 * BITS && structReferenceCount == 0 * REFERENCES, VALIDATE_INPUT(structDataSize == 8 * BITS && structPointerCount == 0 * POINTERS,
"Expected Text, got list of non-bytes.") { "Expected Text, got list of non-bytes.") {
return Text::Reader(); return Text::Reader();
} }
...@@ -1437,7 +1437,7 @@ Text::Reader ListReader::asText() { ...@@ -1437,7 +1437,7 @@ Text::Reader ListReader::asText() {
} }
Data::Reader ListReader::asData() { Data::Reader ListReader::asData() {
VALIDATE_INPUT(structDataSize == 8 * BITS && structReferenceCount == 0 * REFERENCES, VALIDATE_INPUT(structDataSize == 8 * BITS && structPointerCount == 0 * POINTERS,
"Expected Text, got list of non-bytes.") { "Expected Text, got list of non-bytes.") {
return Data::Reader(); return Data::Reader();
} }
...@@ -1453,49 +1453,49 @@ StructReader ListReader::getStructElement(ElementCount index) const { ...@@ -1453,49 +1453,49 @@ StructReader ListReader::getStructElement(ElementCount index) const {
BitCount64 indexBit = ElementCount64(index) * step; BitCount64 indexBit = ElementCount64(index) * step;
const byte* structData = ptr + indexBit / BITS_PER_BYTE; const byte* structData = ptr + indexBit / BITS_PER_BYTE;
const WireReference* structPointers = const WirePointer* structPointers =
reinterpret_cast<const WireReference*>(structData + structDataSize / BITS_PER_BYTE); reinterpret_cast<const WirePointer*>(structData + structDataSize / BITS_PER_BYTE);
// This check should pass if there are no bugs in the list pointer validation code. // This check should pass if there are no bugs in the list pointer validation code.
DCHECK(structReferenceCount == 0 * REFERENCES || DCHECK(structPointerCount == 0 * POINTERS ||
(uintptr_t)structPointers % sizeof(WireReference) == 0, (uintptr_t)structPointers % sizeof(WirePointer) == 0,
"Pointer segment of struct list element not aligned."); "Pointer segment of struct list element not aligned.");
return StructReader( return StructReader(
segment, structData, structPointers, segment, structData, structPointers,
structDataSize, structReferenceCount, structDataSize, structPointerCount,
indexBit % BITS_PER_BYTE, nestingLimit - 1); indexBit % BITS_PER_BYTE, nestingLimit - 1);
} }
static const WireReference* checkAlignment(const void* ptr) { static const WirePointer* checkAlignment(const void* ptr) {
DCHECK((uintptr_t)ptr % sizeof(WireReference) == 0, DCHECK((uintptr_t)ptr % sizeof(WirePointer) == 0,
"Pointer segment of struct list element not aligned."); "Pointer segment of struct list element not aligned.");
return reinterpret_cast<const WireReference*>(ptr); return reinterpret_cast<const WirePointer*>(ptr);
} }
ListReader ListReader::getListElement( ListReader ListReader::getListElement(
ElementCount index, FieldSize expectedElementSize) const { ElementCount index, FieldSize expectedElementSize) const {
return WireHelpers::readListReference( return WireHelpers::readListPointer(
segment, checkAlignment(ptr + index * step / BITS_PER_BYTE), segment, checkAlignment(ptr + index * step / BITS_PER_BYTE),
nullptr, expectedElementSize, nestingLimit); nullptr, expectedElementSize, nestingLimit);
} }
template <> template <>
Text::Reader ListReader::getBlobElement<Text>(ElementCount index) const { Text::Reader ListReader::getBlobElement<Text>(ElementCount index) const {
return WireHelpers::readTextReference( return WireHelpers::readTextPointer(
segment, checkAlignment(ptr + index * step / BITS_PER_BYTE), segment, checkAlignment(ptr + index * step / BITS_PER_BYTE),
"", 0 * BYTES); "", 0 * BYTES);
} }
template <> template <>
Data::Reader ListReader::getBlobElement<Data>(ElementCount index) const { Data::Reader ListReader::getBlobElement<Data>(ElementCount index) const {
return WireHelpers::readDataReference( return WireHelpers::readDataPointer(
segment, checkAlignment(ptr + index * step / BITS_PER_BYTE), segment, checkAlignment(ptr + index * step / BITS_PER_BYTE),
nullptr, 0 * BYTES); nullptr, 0 * BYTES);
} }
ObjectReader ListReader::getObjectElement(ElementCount index) const { ObjectReader ListReader::getObjectElement(ElementCount index) const {
return WireHelpers::readObjectReference( return WireHelpers::readObjectPointer(
segment, checkAlignment(ptr + index * step / BITS_PER_BYTE), nullptr, nestingLimit); segment, checkAlignment(ptr + index * step / BITS_PER_BYTE), nullptr, nestingLimit);
} }
......
...@@ -44,7 +44,7 @@ class ListBuilder; ...@@ -44,7 +44,7 @@ class ListBuilder;
class ListReader; class ListReader;
class ObjectBuilder; class ObjectBuilder;
class ObjectReader; class ObjectReader;
struct WireReference; struct WirePointer;
struct WireHelpers; struct WireHelpers;
class SegmentReader; class SegmentReader;
class SegmentBuilder; class SegmentBuilder;
...@@ -61,23 +61,23 @@ enum class FieldSize: uint8_t { ...@@ -61,23 +61,23 @@ enum class FieldSize: uint8_t {
FOUR_BYTES = 4, FOUR_BYTES = 4,
EIGHT_BYTES = 5, EIGHT_BYTES = 5,
REFERENCE = 6, // Indicates that the field lives in the reference segment, not the data segment. POINTER = 6, // Indicates that the field lives in the pointer segment, not the data segment.
INLINE_COMPOSITE = 7 INLINE_COMPOSITE = 7
// A composite type of fixed width. This serves two purposes: // A composite type of fixed width. This serves two purposes:
// 1) For lists of composite types where all the elements would have the exact same width, // 1) For lists of composite types where all the elements would have the exact same width,
// allocating a list of references which in turn point at the elements would waste space. We // allocating a list of pointers which in turn point at the elements would waste space. We
// can avoid a layer of indirection by placing all the elements in a flat sequence, and only // can avoid a layer of indirection by placing all the elements in a flat sequence, and only
// indicating the element properties (e.g. field count for structs) once. // indicating the element properties (e.g. field count for structs) once.
// //
// Specifically, a list reference indicating INLINE_COMPOSITE element size actually points to // Specifically, a list pointer indicating INLINE_COMPOSITE element size actually points to
// a "tag" describing one element. This tag is formatted like a wire reference, but the // a "tag" describing one element. This tag is formatted like a wire pointer, but the
// "offset" instead stores the element count of the list. The flat list of elements appears // "offset" instead stores the element count of the list. The flat list of elements appears
// immediately after the tag. In the list reference itself, the element count is replaced with // immediately after the tag. In the list pointer itself, the element count is replaced with
// a word count for the whole list (excluding tag). This allows the tag and elements to be // a word count for the whole list (excluding tag). This allows the tag and elements to be
// precached in a single step rather than two sequential steps. // precached in a single step rather than two sequential steps.
// //
// It is NOT intended to be possible to substitute an INLINE_COMPOSITE list for a REFERENCE // It is NOT intended to be possible to substitute an INLINE_COMPOSITE list for a POINTER
// list or vice-versa without breaking recipients. Recipients expect one or the other // list or vice-versa without breaking recipients. Recipients expect one or the other
// depending on the message definition. // depending on the message definition.
// //
...@@ -93,7 +93,7 @@ enum class FieldSize: uint8_t { ...@@ -93,7 +93,7 @@ enum class FieldSize: uint8_t {
}; };
typedef decltype(BITS / ELEMENTS) BitsPerElement; typedef decltype(BITS / ELEMENTS) BitsPerElement;
typedef decltype(REFERENCES / ELEMENTS) PointersPerElement; typedef decltype(POINTERS / ELEMENTS) PointersPerElement;
namespace internal { namespace internal {
static constexpr BitsPerElement BITS_PER_ELEMENT_TABLE[8] = { static constexpr BitsPerElement BITS_PER_ELEMENT_TABLE[8] = {
...@@ -113,7 +113,7 @@ inline constexpr BitsPerElement dataBitsPerElement(FieldSize size) { ...@@ -113,7 +113,7 @@ inline constexpr BitsPerElement dataBitsPerElement(FieldSize size) {
} }
inline constexpr PointersPerElement pointersPerElement(FieldSize size) { inline constexpr PointersPerElement pointersPerElement(FieldSize size) {
return size == FieldSize::REFERENCE ? 1 * REFERENCES / ELEMENTS : 0 * REFERENCES / ELEMENTS; return size == FieldSize::POINTER ? 1 * POINTERS / ELEMENTS : 0 * POINTERS / ELEMENTS;
} }
} // namespace internal } // namespace internal
...@@ -169,17 +169,17 @@ union AlignedData { ...@@ -169,17 +169,17 @@ union AlignedData {
struct StructSize { struct StructSize {
WordCount16 data; WordCount16 data;
WireReferenceCount16 pointers; WirePointerCount16 pointers;
FieldSize preferredListEncoding; FieldSize preferredListEncoding;
// Preferred size to use when encoding a list of this struct. This is INLINE_COMPOSITE if and // Preferred size to use when encoding a list of this struct. This is INLINE_COMPOSITE if and
// only if the struct is larger than one word; otherwise the struct list can be encoded more // only if the struct is larger than one word; otherwise the struct list can be encoded more
// efficiently by encoding it as if it were some primitive type. // efficiently by encoding it as if it were some primitive type.
inline constexpr WordCount total() const { return data + pointers * WORDS_PER_REFERENCE; } inline constexpr WordCount total() const { return data + pointers * WORDS_PER_POINTER; }
StructSize() = default; StructSize() = default;
inline constexpr StructSize(WordCount data, WireReferenceCount pointers, inline constexpr StructSize(WordCount data, WirePointerCount pointers,
FieldSize preferredListEncoding) FieldSize preferredListEncoding)
: data(data), pointers(pointers), preferredListEncoding(preferredListEncoding) {} : data(data), pointers(pointers), preferredListEncoding(preferredListEncoding) {}
}; };
...@@ -288,13 +288,13 @@ private: ...@@ -288,13 +288,13 @@ private:
class StructBuilder { class StructBuilder {
public: public:
inline StructBuilder(): segment(nullptr), data(nullptr), references(nullptr), bit0Offset(0) {} inline StructBuilder(): segment(nullptr), data(nullptr), pointers(nullptr), bit0Offset(0) {}
static StructBuilder initRoot(SegmentBuilder* segment, word* location, StructSize size); static StructBuilder initRoot(SegmentBuilder* segment, word* location, StructSize size);
static StructBuilder getRoot(SegmentBuilder* segment, word* location, StructSize size); static StructBuilder getRoot(SegmentBuilder* segment, word* location, StructSize size);
inline BitCount getDataSectionSize() const { return dataSize; } inline BitCount getDataSectionSize() const { return dataSize; }
inline WireReferenceCount getPointerSectionSize() const { return referenceCount; } inline WirePointerCount getPointerSectionSize() const { return pointerCount; }
inline Data::Builder getDataSectionAsBlob(); inline Data::Builder getDataSectionAsBlob();
template <typename T> template <typename T>
...@@ -318,48 +318,48 @@ public: ...@@ -318,48 +318,48 @@ public:
// Like setDataField() but applies the given XOR mask before storing. Used for writing fields // Like setDataField() but applies the given XOR mask before storing. Used for writing fields
// with non-zero default values. // with non-zero default values.
StructBuilder initStructField(WireReferenceCount refIndex, StructSize size) const; StructBuilder initStructField(WirePointerCount ptrIndex, StructSize size) const;
// Initializes the struct field at the given index in the reference segment. If it is already // Initializes the struct field at the given index in the pointer segment. If it is already
// initialized, the previous value is discarded or overwritten. The struct is initialized to // initialized, the previous value is discarded or overwritten. The struct is initialized to
// the type's default state (all-zero). Use getStructField() if you want the struct to be // the type's default state (all-zero). Use getStructField() if you want the struct to be
// initialized as a copy of the field's default value (which may have non-null references). // initialized as a copy of the field's default value (which may have non-null pointers).
StructBuilder getStructField(WireReferenceCount refIndex, StructSize size, StructBuilder getStructField(WirePointerCount ptrIndex, StructSize size,
const word* defaultValue) const; const word* defaultValue) const;
// Gets the struct field at the given index in the reference segment. If the field is not already // Gets the struct field at the given index in the pointer segment. If the field is not already
// initialized, it is initialized as a deep copy of the given default value (a trusted message), // initialized, it is initialized as a deep copy of the given default value (a trusted message),
// or to the empty state if defaultValue is nullptr. // or to the empty state if defaultValue is nullptr.
ListBuilder initListField(WireReferenceCount refIndex, FieldSize elementSize, ListBuilder initListField(WirePointerCount ptrIndex, FieldSize elementSize,
ElementCount elementCount) const; ElementCount elementCount) const;
// Allocates a new list of the given size for the field at the given index in the reference // Allocates a new list of the given size for the field at the given index in the pointer
// segment, and return a pointer to it. All elements are initialized to zero. // segment, and return a pointer to it. All elements are initialized to zero.
ListBuilder initStructListField(WireReferenceCount refIndex, ElementCount elementCount, ListBuilder initStructListField(WirePointerCount ptrIndex, ElementCount elementCount,
StructSize size) const; StructSize size) const;
// Allocates a new list of the given size for the field at the given index in the reference // Allocates a new list of the given size for the field at the given index in the pointer
// segment, and return a pointer to it. Each element is initialized to its empty state. // segment, and return a pointer to it. Each element is initialized to its empty state.
ListBuilder getListField(WireReferenceCount refIndex, const word* defaultValue) const; ListBuilder getListField(WirePointerCount ptrIndex, const word* defaultValue) const;
// Gets the already-allocated list field for the given reference index. If the list is not // Gets the already-allocated list field for the given pointer index. If the list is not
// already allocated, it is allocated as a deep copy of the given default value (a trusted // already allocated, it is allocated as a deep copy of the given default value (a trusted
// message). If the default value is null, an empty list is used. // message). If the default value is null, an empty list is used.
template <typename T> template <typename T>
typename T::Builder initBlobField(WireReferenceCount refIndex, ByteCount size) const; typename T::Builder initBlobField(WirePointerCount ptrIndex, ByteCount size) const;
// Initialize a Text or Data field to the given size in bytes (not including NUL terminator for // Initialize a Text or Data field to the given size in bytes (not including NUL terminator for
// Text) and return a Text::Builder which can be used to fill in the content. // Text) and return a Text::Builder which can be used to fill in the content.
template <typename T> template <typename T>
void setBlobField(WireReferenceCount refIndex, typename T::Reader value) const; void setBlobField(WirePointerCount ptrIndex, typename T::Reader value) const;
// Set the blob field to a copy of the given blob. // Set the blob field to a copy of the given blob.
template <typename T> template <typename T>
typename T::Builder getBlobField(WireReferenceCount refIndex, typename T::Builder getBlobField(WirePointerCount ptrIndex,
const void* defaultValue, ByteCount defaultSize) const; const void* defaultValue, ByteCount defaultSize) const;
// Get the blob field. If it is not initialized, initialize it to a copy of the given default. // Get the blob field. If it is not initialized, initialize it to a copy of the given default.
ObjectBuilder getObjectField(WireReferenceCount refIndex, const word* defaultValue) const; ObjectBuilder getObjectField(WirePointerCount ptrIndex, const word* defaultValue) const;
// Read a pointer of arbitrary type. // Read a pointer of arbitrary type.
StructReader asReader() const; StructReader asReader() const;
...@@ -368,23 +368,23 @@ public: ...@@ -368,23 +368,23 @@ public:
private: private:
SegmentBuilder* segment; // Memory segment in which the struct resides. SegmentBuilder* segment; // Memory segment in which the struct resides.
void* data; // Pointer to the encoded data. void* data; // Pointer to the encoded data.
WireReference* references; // Pointer to the encoded references. WirePointer* pointers; // Pointer to the encoded pointers.
BitCount32 dataSize; BitCount32 dataSize;
// Size of data segment. We use a bit count rather than a word count to more easily handle the // Size of data segment. We use a bit count rather than a word count to more easily handle the
// case of struct lists encoded with less than a word per element. // case of struct lists encoded with less than a word per element.
WireReferenceCount16 referenceCount; // Size of the reference segment. WirePointerCount16 pointerCount; // Size of the pointer segment.
BitCount8 bit0Offset; BitCount8 bit0Offset;
// A special hack: If dataSize == 1 bit, then bit0Offset is the offset of that bit within the // A special hack: If dataSize == 1 bit, then bit0Offset is the offset of that bit within the
// byte pointed to by `data`. In all other cases, this is zero. This is needed to implement // byte pointed to by `data`. In all other cases, this is zero. This is needed to implement
// struct lists where each struct is one bit. // struct lists where each struct is one bit.
inline StructBuilder(SegmentBuilder* segment, void* data, WireReference* references, inline StructBuilder(SegmentBuilder* segment, void* data, WirePointer* pointers,
BitCount dataSize, WireReferenceCount referenceCount, BitCount8 bit0Offset) BitCount dataSize, WirePointerCount pointerCount, BitCount8 bit0Offset)
: segment(segment), data(data), references(references), : segment(segment), data(data), pointers(pointers),
dataSize(dataSize), referenceCount(referenceCount), bit0Offset(bit0Offset) {} dataSize(dataSize), pointerCount(pointerCount), bit0Offset(bit0Offset) {}
friend class ListBuilder; friend class ListBuilder;
friend struct WireHelpers; friend struct WireHelpers;
...@@ -393,14 +393,14 @@ private: ...@@ -393,14 +393,14 @@ private:
class StructReader { class StructReader {
public: public:
inline StructReader() inline StructReader()
: segment(nullptr), data(nullptr), references(nullptr), dataSize(0), : segment(nullptr), data(nullptr), pointers(nullptr), dataSize(0),
referenceCount(0), bit0Offset(0), nestingLimit(0) {} pointerCount(0), bit0Offset(0), nestingLimit(0) {}
static StructReader readRootTrusted(const word* location); static StructReader readRootTrusted(const word* location);
static StructReader readRoot(const word* location, SegmentReader* segment, int nestingLimit); static StructReader readRoot(const word* location, SegmentReader* segment, int nestingLimit);
inline BitCount getDataSectionSize() const { return dataSize; } inline BitCount getDataSectionSize() const { return dataSize; }
inline WireReferenceCount getPointerSectionSize() const { return referenceCount; } inline WirePointerCount getPointerSectionSize() const { return pointerCount; }
inline Data::Reader getDataSectionAsBlob(); inline Data::Reader getDataSectionAsBlob();
template <typename T> template <typename T>
...@@ -415,26 +415,26 @@ public: ...@@ -415,26 +415,26 @@ public:
// Like getDataField(offset), but applies the given XOR mask to the result. Used for reading // Like getDataField(offset), but applies the given XOR mask to the result. Used for reading
// fields with non-zero default values. // fields with non-zero default values.
StructReader getStructField(WireReferenceCount refIndex, const word* defaultValue) const; StructReader getStructField(WirePointerCount ptrIndex, const word* defaultValue) const;
// Get the struct field at the given index in the reference segment, or the default value if not // Get the struct field at the given index in the pointer segment, or the default value if not
// initialized. defaultValue will be interpreted as a trusted message -- it must point at a // initialized. defaultValue will be interpreted as a trusted message -- it must point at a
// struct reference, which in turn points at the struct value. The default value is allowed to // struct pointer, which in turn points at the struct value. The default value is allowed to
// be null, in which case an empty struct is used. // be null, in which case an empty struct is used.
ListReader getListField(WireReferenceCount refIndex, FieldSize expectedElementSize, ListReader getListField(WirePointerCount ptrIndex, FieldSize expectedElementSize,
const word* defaultValue) const; const word* defaultValue) const;
// Get the list field at the given index in the reference segment, or the default value if not // Get the list field at the given index in the pointer segment, or the default value if not
// initialized. The default value is allowed to be null, in which case an empty list is used. // initialized. The default value is allowed to be null, in which case an empty list is used.
template <typename T> template <typename T>
typename T::Reader getBlobField(WireReferenceCount refIndex, typename T::Reader getBlobField(WirePointerCount ptrIndex,
const void* defaultValue, ByteCount defaultSize) const; const void* defaultValue, ByteCount defaultSize) const;
// Gets the text or data field, or the given default value if not initialized. // Gets the text or data field, or the given default value if not initialized.
ObjectReader getObjectField(WireReferenceCount refIndex, const word* defaultValue) const; ObjectReader getObjectField(WirePointerCount ptrIndex, const word* defaultValue) const;
// Read a pointer of arbitrary type. // Read a pointer of arbitrary type.
const word* getTrustedPointer(WireReferenceCount refIndex) const; const word* getTrustedPointer(WirePointerCount ptrIndex) const;
// If this is a trusted message, get a word* pointing at the location of the pointer. This // If this is a trusted message, get a word* pointing at the location of the pointer. This
// word* can actually be passed to readTrusted() to read the designated sub-object later. If // word* can actually be passed to readTrusted() to read the designated sub-object later. If
// this isn't a trusted message, throws an exception. // this isn't a trusted message, throws an exception.
...@@ -443,13 +443,13 @@ private: ...@@ -443,13 +443,13 @@ private:
SegmentReader* segment; // Memory segment in which the struct resides. SegmentReader* segment; // Memory segment in which the struct resides.
const void* data; const void* data;
const WireReference* references; const WirePointer* pointers;
BitCount32 dataSize; BitCount32 dataSize;
// Size of data segment. We use a bit count rather than a word count to more easily handle the // Size of data segment. We use a bit count rather than a word count to more easily handle the
// case of struct lists encoded with less than a word per element. // case of struct lists encoded with less than a word per element.
WireReferenceCount16 referenceCount; // Size of the reference segment. WirePointerCount16 pointerCount; // Size of the pointer segment.
BitCount8 bit0Offset; BitCount8 bit0Offset;
// A special hack: If dataSize == 1 bit, then bit0Offset is the offset of that bit within the // A special hack: If dataSize == 1 bit, then bit0Offset is the offset of that bit within the
...@@ -466,11 +466,11 @@ private: ...@@ -466,11 +466,11 @@ private:
// Once this reaches zero, further pointers will be pruned. // Once this reaches zero, further pointers will be pruned.
// TODO: Limit to 8 bits for better alignment? // TODO: Limit to 8 bits for better alignment?
inline StructReader(SegmentReader* segment, const void* data, const WireReference* references, inline StructReader(SegmentReader* segment, const void* data, const WirePointer* pointers,
BitCount dataSize, WireReferenceCount referenceCount, BitCount8 bit0Offset, BitCount dataSize, WirePointerCount pointerCount, BitCount8 bit0Offset,
int nestingLimit) int nestingLimit)
: segment(segment), data(data), references(references), : segment(segment), data(data), pointers(pointers),
dataSize(dataSize), referenceCount(referenceCount), bit0Offset(bit0Offset), dataSize(dataSize), pointerCount(pointerCount), bit0Offset(bit0Offset),
nestingLimit(nestingLimit) {} nestingLimit(nestingLimit) {}
friend class ListReader; friend class ListReader;
...@@ -512,7 +512,7 @@ public: ...@@ -512,7 +512,7 @@ public:
ListBuilder initStructListElement(ElementCount index, ElementCount elementCount, ListBuilder initStructListElement(ElementCount index, ElementCount elementCount,
StructSize size) const; StructSize size) const;
// Allocates a new list of the given size for the field at the given index in the reference // Allocates a new list of the given size for the field at the given index in the pointer
// segment, and return a pointer to it. Each element is initialized to its empty state. // segment, and return a pointer to it. Each element is initialized to its empty state.
ListBuilder getListElement(ElementCount index) const; ListBuilder getListElement(ElementCount index) const;
...@@ -549,16 +549,16 @@ private: ...@@ -549,16 +549,16 @@ private:
// The distance between elements. // The distance between elements.
BitCount32 structDataSize; BitCount32 structDataSize;
WireReferenceCount16 structReferenceCount; WirePointerCount16 structPointerCount;
// The struct properties to use when interpreting the elements as structs. All lists can be // The struct properties to use when interpreting the elements as structs. All lists can be
// interpreted as struct lists, so these are always filled in. // interpreted as struct lists, so these are always filled in.
inline ListBuilder(SegmentBuilder* segment, void* ptr, inline ListBuilder(SegmentBuilder* segment, void* ptr,
decltype(BITS / ELEMENTS) step, ElementCount size, decltype(BITS / ELEMENTS) step, ElementCount size,
BitCount structDataSize, WireReferenceCount structReferenceCount) BitCount structDataSize, WirePointerCount structPointerCount)
: segment(segment), ptr(reinterpret_cast<byte*>(ptr)), : segment(segment), ptr(reinterpret_cast<byte*>(ptr)),
elementCount(size), step(step), structDataSize(structDataSize), elementCount(size), step(step), structDataSize(structDataSize),
structReferenceCount(structReferenceCount) {} structPointerCount(structPointerCount) {}
friend class StructBuilder; friend class StructBuilder;
friend struct WireHelpers; friend struct WireHelpers;
...@@ -568,7 +568,7 @@ class ListReader { ...@@ -568,7 +568,7 @@ class ListReader {
public: public:
inline ListReader() inline ListReader()
: segment(nullptr), ptr(nullptr), elementCount(0), step(0 * BITS / ELEMENTS), : segment(nullptr), ptr(nullptr), elementCount(0), step(0 * BITS / ELEMENTS),
structDataSize(0), structReferenceCount(0), nestingLimit(0) {} structDataSize(0), structPointerCount(0), nestingLimit(0) {}
inline ElementCount size() const; inline ElementCount size() const;
// The number of elements in the list. // The number of elements in the list.
...@@ -605,7 +605,7 @@ private: ...@@ -605,7 +605,7 @@ private:
// The distance between elements. // The distance between elements.
BitCount32 structDataSize; BitCount32 structDataSize;
WireReferenceCount16 structReferenceCount; WirePointerCount16 structPointerCount;
// The struct properties to use when interpreting the elements as structs. All lists can be // The struct properties to use when interpreting the elements as structs. All lists can be
// interpreted as struct lists, so these are always filled in. // interpreted as struct lists, so these are always filled in.
...@@ -615,11 +615,11 @@ private: ...@@ -615,11 +615,11 @@ private:
inline ListReader(SegmentReader* segment, const void* ptr, inline ListReader(SegmentReader* segment, const void* ptr,
ElementCount elementCount, decltype(BITS / ELEMENTS) step, ElementCount elementCount, decltype(BITS / ELEMENTS) step,
BitCount structDataSize, WireReferenceCount structReferenceCount, BitCount structDataSize, WirePointerCount structPointerCount,
int nestingLimit) int nestingLimit)
: segment(segment), ptr(reinterpret_cast<const byte*>(ptr)), elementCount(elementCount), : segment(segment), ptr(reinterpret_cast<const byte*>(ptr)), elementCount(elementCount),
step(step), structDataSize(structDataSize), step(step), structDataSize(structDataSize),
structReferenceCount(structReferenceCount), nestingLimit(nestingLimit) {} structPointerCount(structPointerCount), nestingLimit(nestingLimit) {}
friend class StructReader; friend class StructReader;
friend class ListBuilder; friend class ListBuilder;
...@@ -835,19 +835,19 @@ inline Void ListReader::getDataElement<Void>(ElementCount index) const { ...@@ -835,19 +835,19 @@ inline Void ListReader::getDataElement<Void>(ElementCount index) const {
} }
// These are defined in the source file. // These are defined in the source file.
template <> typename Text::Builder StructBuilder::initBlobField<Text>(WireReferenceCount refIndex, ByteCount size) const; template <> typename Text::Builder StructBuilder::initBlobField<Text>(WirePointerCount ptrIndex, ByteCount size) const;
template <> void StructBuilder::setBlobField<Text>(WireReferenceCount refIndex, typename Text::Reader value) const; template <> void StructBuilder::setBlobField<Text>(WirePointerCount ptrIndex, typename Text::Reader value) const;
template <> typename Text::Builder StructBuilder::getBlobField<Text>(WireReferenceCount refIndex, const void* defaultValue, ByteCount defaultSize) const; template <> typename Text::Builder StructBuilder::getBlobField<Text>(WirePointerCount ptrIndex, const void* defaultValue, ByteCount defaultSize) const;
template <> typename Text::Reader StructReader::getBlobField<Text>(WireReferenceCount refIndex, const void* defaultValue, ByteCount defaultSize) const; template <> typename Text::Reader StructReader::getBlobField<Text>(WirePointerCount ptrIndex, const void* defaultValue, ByteCount defaultSize) const;
template <> typename Text::Builder ListBuilder::initBlobElement<Text>(ElementCount index, ByteCount size) const; template <> typename Text::Builder ListBuilder::initBlobElement<Text>(ElementCount index, ByteCount size) const;
template <> void ListBuilder::setBlobElement<Text>(ElementCount index, typename Text::Reader value) const; template <> void ListBuilder::setBlobElement<Text>(ElementCount index, typename Text::Reader value) const;
template <> typename Text::Builder ListBuilder::getBlobElement<Text>(ElementCount index) const; template <> typename Text::Builder ListBuilder::getBlobElement<Text>(ElementCount index) const;
template <> typename Text::Reader ListReader::getBlobElement<Text>(ElementCount index) const; template <> typename Text::Reader ListReader::getBlobElement<Text>(ElementCount index) const;
template <> typename Data::Builder StructBuilder::initBlobField<Data>(WireReferenceCount refIndex, ByteCount size) const; template <> typename Data::Builder StructBuilder::initBlobField<Data>(WirePointerCount ptrIndex, ByteCount size) const;
template <> void StructBuilder::setBlobField<Data>(WireReferenceCount refIndex, typename Data::Reader value) const; template <> void StructBuilder::setBlobField<Data>(WirePointerCount ptrIndex, typename Data::Reader value) const;
template <> typename Data::Builder StructBuilder::getBlobField<Data>(WireReferenceCount refIndex, const void* defaultValue, ByteCount defaultSize) const; template <> typename Data::Builder StructBuilder::getBlobField<Data>(WirePointerCount ptrIndex, const void* defaultValue, ByteCount defaultSize) const;
template <> typename Data::Reader StructReader::getBlobField<Data>(WireReferenceCount refIndex, const void* defaultValue, ByteCount defaultSize) const; template <> typename Data::Reader StructReader::getBlobField<Data>(WirePointerCount ptrIndex, const void* defaultValue, ByteCount defaultSize) const;
template <> typename Data::Builder ListBuilder::initBlobElement<Data>(ElementCount index, ByteCount size) const; template <> typename Data::Builder ListBuilder::initBlobElement<Data>(ElementCount index, ByteCount size) const;
template <> void ListBuilder::setBlobElement<Data>(ElementCount index, typename Data::Reader value) const; template <> void ListBuilder::setBlobElement<Data>(ElementCount index, typename Data::Reader value) const;
template <> typename Data::Builder ListBuilder::getBlobElement<Data>(ElementCount index) const; template <> typename Data::Builder ListBuilder::getBlobElement<Data>(ElementCount index) const;
......
...@@ -94,22 +94,22 @@ template <typename T> struct FieldSizeForType { ...@@ -94,22 +94,22 @@ template <typename T> struct FieldSizeForType {
kind<T>() == Kind::STRUCT ? FieldSize::INLINE_COMPOSITE : kind<T>() == Kind::STRUCT ? FieldSize::INLINE_COMPOSITE :
// Everything else is a pointer. // Everything else is a pointer.
FieldSize::REFERENCE; FieldSize::POINTER;
}; };
// Void and bool are special. // Void and bool are special.
template <> struct FieldSizeForType<Void> { static constexpr FieldSize value = FieldSize::VOID; }; template <> struct FieldSizeForType<Void> { static constexpr FieldSize value = FieldSize::VOID; };
template <> struct FieldSizeForType<bool> { static constexpr FieldSize value = FieldSize::BIT; }; template <> struct FieldSizeForType<bool> { static constexpr FieldSize value = FieldSize::BIT; };
// Lists and blobs are references, not structs. // Lists and blobs are pointers, not structs.
template <typename T, bool b> struct FieldSizeForType<List<T, b>> { template <typename T, bool b> struct FieldSizeForType<List<T, b>> {
static constexpr FieldSize value = FieldSize::REFERENCE; static constexpr FieldSize value = FieldSize::POINTER;
}; };
template <> struct FieldSizeForType<Text> { template <> struct FieldSizeForType<Text> {
static constexpr FieldSize value = FieldSize::REFERENCE; static constexpr FieldSize value = FieldSize::POINTER;
}; };
template <> struct FieldSizeForType<Data> { template <> struct FieldSizeForType<Data> {
static constexpr FieldSize value = FieldSize::REFERENCE; static constexpr FieldSize value = FieldSize::POINTER;
}; };
template <typename T> template <typename T>
...@@ -265,15 +265,15 @@ private: ...@@ -265,15 +265,15 @@ private:
} }
inline static internal::ListBuilder initAsFieldOf( inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) { internal::StructBuilder& builder, WirePointerCount index, uint size) {
return builder.initListField(index, internal::FieldSizeForType<T>::value, size * ELEMENTS); return builder.initListField(index, internal::FieldSizeForType<T>::value, size * ELEMENTS);
} }
inline static internal::ListBuilder getAsFieldOf( inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, const word* defaultValue) { internal::StructBuilder& builder, WirePointerCount index, const word* defaultValue) {
return builder.getListField(index, defaultValue); return builder.getListField(index, defaultValue);
} }
inline static internal::ListReader getAsFieldOf( inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index, const word* defaultValue) { internal::StructReader& reader, WirePointerCount index, const word* defaultValue) {
return reader.getListField(index, internal::FieldSizeForType<T>::value, defaultValue); return reader.getListField(index, internal::FieldSizeForType<T>::value, defaultValue);
} }
...@@ -351,15 +351,15 @@ private: ...@@ -351,15 +351,15 @@ private:
} }
inline static internal::ListBuilder initAsFieldOf( inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) { internal::StructBuilder& builder, WirePointerCount index, uint size) {
return builder.initStructListField(index, size * ELEMENTS, internal::structSize<T>()); return builder.initStructListField(index, size * ELEMENTS, internal::structSize<T>());
} }
inline static internal::ListBuilder getAsFieldOf( inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, const word* defaultValue) { internal::StructBuilder& builder, WirePointerCount index, const word* defaultValue) {
return builder.getListField(index, defaultValue); return builder.getListField(index, defaultValue);
} }
inline static internal::ListReader getAsFieldOf( inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index, const word* defaultValue) { internal::StructReader& reader, WirePointerCount index, const word* defaultValue) {
return reader.getListField(index, internal::FieldSize::INLINE_COMPOSITE, defaultValue); return reader.getListField(index, internal::FieldSize::INLINE_COMPOSITE, defaultValue);
} }
...@@ -425,7 +425,7 @@ private: ...@@ -425,7 +425,7 @@ private:
inline static internal::ListBuilder initAsElementOf( inline static internal::ListBuilder initAsElementOf(
const internal::ListBuilder& builder, uint index, uint size) { const internal::ListBuilder& builder, uint index, uint size) {
return builder.initListElement( return builder.initListElement(
index * ELEMENTS, internal::FieldSize::REFERENCE, size * ELEMENTS); index * ELEMENTS, internal::FieldSize::POINTER, size * ELEMENTS);
} }
inline static internal::ListBuilder getAsElementOf( inline static internal::ListBuilder getAsElementOf(
const internal::ListBuilder& builder, uint index) { const internal::ListBuilder& builder, uint index) {
...@@ -433,20 +433,20 @@ private: ...@@ -433,20 +433,20 @@ private:
} }
inline static internal::ListReader getAsElementOf( inline static internal::ListReader getAsElementOf(
const internal::ListReader& reader, uint index) { const internal::ListReader& reader, uint index) {
return reader.getListElement(index * ELEMENTS, internal::FieldSize::REFERENCE); return reader.getListElement(index * ELEMENTS, internal::FieldSize::POINTER);
} }
inline static internal::ListBuilder initAsFieldOf( inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) { internal::StructBuilder& builder, WirePointerCount index, uint size) {
return builder.initListField(index, internal::FieldSize::REFERENCE, size * ELEMENTS); return builder.initListField(index, internal::FieldSize::POINTER, size * ELEMENTS);
} }
inline static internal::ListBuilder getAsFieldOf( inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, const word* defaultValue) { internal::StructBuilder& builder, WirePointerCount index, const word* defaultValue) {
return builder.getListField(index, defaultValue); return builder.getListField(index, defaultValue);
} }
inline static internal::ListReader getAsFieldOf( inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index, const word* defaultValue) { internal::StructReader& reader, WirePointerCount index, const word* defaultValue) {
return reader.getListField(index, internal::FieldSize::REFERENCE, defaultValue); return reader.getListField(index, internal::FieldSize::POINTER, defaultValue);
} }
template <typename U, Kind k> template <typename U, Kind k>
...@@ -526,7 +526,7 @@ private: ...@@ -526,7 +526,7 @@ private:
inline static internal::ListBuilder initAsElementOf( inline static internal::ListBuilder initAsElementOf(
const internal::ListBuilder& builder, uint index, uint size) { const internal::ListBuilder& builder, uint index, uint size) {
return builder.initListElement( return builder.initListElement(
index * ELEMENTS, internal::FieldSize::REFERENCE, size * ELEMENTS); index * ELEMENTS, internal::FieldSize::POINTER, size * ELEMENTS);
} }
inline static internal::ListBuilder getAsElementOf( inline static internal::ListBuilder getAsElementOf(
const internal::ListBuilder& builder, uint index) { const internal::ListBuilder& builder, uint index) {
...@@ -534,20 +534,20 @@ private: ...@@ -534,20 +534,20 @@ private:
} }
inline static internal::ListReader getAsElementOf( inline static internal::ListReader getAsElementOf(
const internal::ListReader& reader, uint index) { const internal::ListReader& reader, uint index) {
return reader.getListElement(index * ELEMENTS, internal::FieldSize::REFERENCE); return reader.getListElement(index * ELEMENTS, internal::FieldSize::POINTER);
} }
inline static internal::ListBuilder initAsFieldOf( inline static internal::ListBuilder initAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, uint size) { internal::StructBuilder& builder, WirePointerCount index, uint size) {
return builder.initListField(index, internal::FieldSize::REFERENCE, size * ELEMENTS); return builder.initListField(index, internal::FieldSize::POINTER, size * ELEMENTS);
} }
inline static internal::ListBuilder getAsFieldOf( inline static internal::ListBuilder getAsFieldOf(
internal::StructBuilder& builder, WireReferenceCount index, const word* defaultValue) { internal::StructBuilder& builder, WirePointerCount index, const word* defaultValue) {
return builder.getListField(index, defaultValue); return builder.getListField(index, defaultValue);
} }
inline static internal::ListReader getAsFieldOf( inline static internal::ListReader getAsFieldOf(
internal::StructReader& reader, WireReferenceCount index, const word* defaultValue) { internal::StructReader& reader, WirePointerCount index, const word* defaultValue) {
return reader.getListField(index, internal::FieldSize::REFERENCE, defaultValue); return reader.getListField(index, internal::FieldSize::POINTER, defaultValue);
} }
template <typename U, Kind k> template <typename U, Kind k>
......
...@@ -78,11 +78,11 @@ internal::SegmentBuilder* MessageBuilder::getRootSegment() { ...@@ -78,11 +78,11 @@ internal::SegmentBuilder* MessageBuilder::getRootSegment() {
new(arena()) internal::BuilderArena(this); new(arena()) internal::BuilderArena(this);
allocatedArena = true; allocatedArena = true;
WordCount refSize = 1 * REFERENCES * WORDS_PER_REFERENCE; WordCount ptrSize = 1 * POINTERS * WORDS_PER_POINTER;
internal::SegmentBuilder* segment = arena()->getSegmentWithAvailable(refSize); internal::SegmentBuilder* segment = arena()->getSegmentWithAvailable(ptrSize);
CHECK(segment->getSegmentId() == internal::SegmentId(0), CHECK(segment->getSegmentId() == internal::SegmentId(0),
"First allocated word of new arena was not in segment ID 0."); "First allocated word of new arena was not in segment ID 0.");
word* location = segment->allocate(refSize); word* location = segment->allocate(ptrSize);
CHECK(location == segment->getPtrUnchecked(0 * WORDS), CHECK(location == segment->getPtrUnchecked(0 * WORDS),
"First allocated word of new arena was not the first word in its segment."); "First allocated word of new arena was not the first word in its segment.");
return segment; return segment;
......
...@@ -391,7 +391,7 @@ TEST(Packed, RoundTripAllZero) { ...@@ -391,7 +391,7 @@ TEST(Packed, RoundTripAllZero) {
checkTestMessageAllZero(reader.getRoot<TestAllTypes>()); checkTestMessageAllZero(reader.getRoot<TestAllTypes>());
// Segment table packs to 2 bytes. // Segment table packs to 2 bytes.
// Root reference packs to 3 bytes. // Root pointer packs to 3 bytes.
// Content packs to 2 bytes (zero span). // Content packs to 2 bytes (zero span).
EXPECT_LE(pipe.getData().size(), 7u); EXPECT_LE(pipe.getData().size(), 7u);
} }
......
...@@ -787,7 +787,7 @@ class word { uint64_t content; CAPNPROTO_DISALLOW_COPY(word); public: word() = d ...@@ -787,7 +787,7 @@ class word { uint64_t content; CAPNPROTO_DISALLOW_COPY(word); public: word() = d
static_assert(sizeof(byte) == 1, "uint8_t is not one byte?"); static_assert(sizeof(byte) == 1, "uint8_t is not one byte?");
static_assert(sizeof(word) == 8, "uint64_t is not 8 bytes?"); static_assert(sizeof(word) == 8, "uint64_t is not 8 bytes?");
namespace internal { class BitLabel; class ElementLabel; class WireReference; } namespace internal { class BitLabel; class ElementLabel; class WirePointer; }
#ifndef CAPNPROTO_DEBUG_TYPES #ifndef CAPNPROTO_DEBUG_TYPES
#define CAPNPROTO_DEBUG_TYPES 1 #define CAPNPROTO_DEBUG_TYPES 1
...@@ -828,11 +828,11 @@ typedef Quantity<uint16_t, internal::ElementLabel> ElementCount16; ...@@ -828,11 +828,11 @@ typedef Quantity<uint16_t, internal::ElementLabel> ElementCount16;
typedef Quantity<uint32_t, internal::ElementLabel> ElementCount32; typedef Quantity<uint32_t, internal::ElementLabel> ElementCount32;
typedef Quantity<uint64_t, internal::ElementLabel> ElementCount64; typedef Quantity<uint64_t, internal::ElementLabel> ElementCount64;
typedef Quantity<uint, internal::WireReference> WireReferenceCount; typedef Quantity<uint, internal::WirePointer> WirePointerCount;
typedef Quantity<uint8_t, internal::WireReference> WireReferenceCount8; typedef Quantity<uint8_t, internal::WirePointer> WirePointerCount8;
typedef Quantity<uint16_t, internal::WireReference> WireReferenceCount16; typedef Quantity<uint16_t, internal::WirePointer> WirePointerCount16;
typedef Quantity<uint32_t, internal::WireReference> WireReferenceCount32; typedef Quantity<uint32_t, internal::WirePointer> WirePointerCount32;
typedef Quantity<uint64_t, internal::WireReference> WireReferenceCount64; typedef Quantity<uint64_t, internal::WirePointer> WirePointerCount64;
#else #else
...@@ -860,11 +860,11 @@ typedef uint16_t ElementCount16; ...@@ -860,11 +860,11 @@ typedef uint16_t ElementCount16;
typedef uint32_t ElementCount32; typedef uint32_t ElementCount32;
typedef uint64_t ElementCount64; typedef uint64_t ElementCount64;
typedef uint WireReferenceCount; typedef uint WirePointerCount;
typedef uint8_t WireReferenceCount8; typedef uint8_t WirePointerCount8;
typedef uint16_t WireReferenceCount16; typedef uint16_t WirePointerCount16;
typedef uint32_t WireReferenceCount32; typedef uint32_t WirePointerCount32;
typedef uint64_t WireReferenceCount64; typedef uint64_t WirePointerCount64;
#endif #endif
...@@ -872,17 +872,17 @@ constexpr BitCount BITS = unit<BitCount>(); ...@@ -872,17 +872,17 @@ constexpr BitCount BITS = unit<BitCount>();
constexpr ByteCount BYTES = unit<ByteCount>(); constexpr ByteCount BYTES = unit<ByteCount>();
constexpr WordCount WORDS = unit<WordCount>(); constexpr WordCount WORDS = unit<WordCount>();
constexpr ElementCount ELEMENTS = unit<ElementCount>(); constexpr ElementCount ELEMENTS = unit<ElementCount>();
constexpr WireReferenceCount REFERENCES = unit<WireReferenceCount>(); constexpr WirePointerCount POINTERS = unit<WirePointerCount>();
constexpr auto BITS_PER_BYTE = 8 * BITS / BYTES; constexpr auto BITS_PER_BYTE = 8 * BITS / BYTES;
constexpr auto BITS_PER_WORD = 64 * BITS / WORDS; constexpr auto BITS_PER_WORD = 64 * BITS / WORDS;
constexpr auto BYTES_PER_WORD = 8 * BYTES / WORDS; constexpr auto BYTES_PER_WORD = 8 * BYTES / WORDS;
constexpr auto BITS_PER_REFERENCE = 64 * BITS / REFERENCES; constexpr auto BITS_PER_POINTER = 64 * BITS / POINTERS;
constexpr auto BYTES_PER_REFERENCE = 8 * BYTES / REFERENCES; constexpr auto BYTES_PER_POINTER = 8 * BYTES / POINTERS;
constexpr auto WORDS_PER_REFERENCE = 1 * WORDS / REFERENCES; constexpr auto WORDS_PER_POINTER = 1 * WORDS / POINTERS;
constexpr WordCount REFERENCE_SIZE_IN_WORDS = 1 * REFERENCES * WORDS_PER_REFERENCE; constexpr WordCount POINTER_SIZE_IN_WORDS = 1 * POINTERS * WORDS_PER_POINTER;
template <typename T> template <typename T>
inline constexpr decltype(BYTES / ELEMENTS) bytesPerElement() { inline constexpr decltype(BYTES / ELEMENTS) bytesPerElement() {
......
...@@ -481,26 +481,26 @@ extractFieldNumbers decls = concat ...@@ -481,26 +481,26 @@ extractFieldNumbers decls = concat
data PackingState = PackingState data PackingState = PackingState
{ packingHoles :: Map.Map DataSize Integer { packingHoles :: Map.Map DataSize Integer
, packingDataSize :: Integer , packingDataSize :: Integer
, packingReferenceCount :: Integer , packingPointerCount :: Integer
} }
initialPackingState = PackingState Map.empty 0 0 initialPackingState = PackingState Map.empty 0 0
packValue :: FieldSize -> PackingState -> (FieldOffset, PackingState) packValue :: FieldSize -> PackingState -> (FieldOffset, PackingState)
packValue SizeVoid s = (VoidOffset, s) packValue SizeVoid s = (VoidOffset, s)
packValue SizeReference s@(PackingState { packingReferenceCount = rc }) = packValue SizePointer s@(PackingState { packingPointerCount = rc }) =
(PointerOffset rc, s { packingReferenceCount = rc + 1 }) (PointerOffset rc, s { packingPointerCount = rc + 1 })
packValue (SizeInlineComposite (DataSectionWords inlineDs) inlineRc) packValue (SizeInlineComposite (DataSectionWords inlineDs) inlineRc)
s@(PackingState { packingDataSize = ds, packingReferenceCount = rc }) = s@(PackingState { packingDataSize = ds, packingPointerCount = rc }) =
(InlineCompositeOffset ds rc (DataSectionWords inlineDs) inlineRc, (InlineCompositeOffset ds rc (DataSectionWords inlineDs) inlineRc,
s { packingDataSize = ds + inlineDs s { packingDataSize = ds + inlineDs
, packingReferenceCount = rc + inlineRc }) , packingPointerCount = rc + inlineRc })
packValue (SizeInlineComposite inlineDs inlineRc) packValue (SizeInlineComposite inlineDs inlineRc)
s@(PackingState { packingReferenceCount = rc }) = let s@(PackingState { packingPointerCount = rc }) = let
size = (dataSectionAlignment inlineDs) size = (dataSectionAlignment inlineDs)
(offset, s2) = packData size s (offset, s2) = packData size s
in (InlineCompositeOffset offset rc inlineDs inlineRc, in (InlineCompositeOffset offset rc inlineDs inlineRc,
s2 { packingReferenceCount = rc + inlineRc }) s2 { packingPointerCount = rc + inlineRc })
packValue (SizeData size) s = let (o, s2) = packData size s in (DataOffset size o, s2) packValue (SizeData size) s = let (o, s2) = packData size s in (DataOffset size o, s2)
packData :: DataSize -> PackingState -> (Integer, PackingState) packData :: DataSize -> PackingState -> (Integer, PackingState)
...@@ -569,14 +569,14 @@ packUnionizedValue (SizeData size) (UnionPackingState (UnionSlot slotSize slotOf ...@@ -569,14 +569,14 @@ packUnionizedValue (SizeData size) (UnionPackingState (UnionSlot slotSize slotOf
Nothing -> packUnionizedValue (SizeData size) Nothing -> packUnionizedValue (SizeData size)
(UnionPackingState (UnionSlot (DataSectionWords 0) 0) p) s (UnionPackingState (UnionSlot (DataSectionWords 0) 0) p) s
-- Pack reference when we don't have a reference slot. -- Pack pointer when we don't have a pointer slot.
packUnionizedValue SizeReference u@(UnionPackingState _ (UnionSlot 0 _)) s = let packUnionizedValue SizePointer u@(UnionPackingState _ (UnionSlot 0 _)) s = let
(PointerOffset offset, s2) = packValue SizeReference s (PointerOffset offset, s2) = packValue SizePointer s
u2 = u { unionPointerSlot = UnionSlot 1 offset } u2 = u { unionPointerSlot = UnionSlot 1 offset }
in (PointerOffset offset, u2, s2) in (PointerOffset offset, u2, s2)
-- Pack reference when we already have a reference slot allocated. -- Pack pointer when we already have a pointer slot allocated.
packUnionizedValue SizeReference u@(UnionPackingState _ (UnionSlot _ offset)) s = packUnionizedValue SizePointer u@(UnionPackingState _ (UnionSlot _ offset)) s =
(PointerOffset offset, u, s) (PointerOffset offset, u, s)
-- Pack inline composite. -- Pack inline composite.
...@@ -621,14 +621,14 @@ packUnionizedValue (SizeInlineComposite dataSize pointerCount) ...@@ -621,14 +621,14 @@ packUnionizedValue (SizeInlineComposite dataSize pointerCount)
-- Pack the pointer section. -- Pack the pointer section.
(pointerOffset, u3, s3) (pointerOffset, u3, s3)
| pointerCount <= pointerSlotSize = (pointerSlotOffset, u2, s2) | pointerCount <= pointerSlotSize = (pointerSlotOffset, u2, s2)
| pointerSlotOffset + pointerSlotSize == packingReferenceCount s2 = | pointerSlotOffset + pointerSlotSize == packingPointerCount s2 =
(pointerSlotOffset, (pointerSlotOffset,
u2 { unionPointerSlot = UnionSlot pointerCount pointerSlotOffset }, u2 { unionPointerSlot = UnionSlot pointerCount pointerSlotOffset },
s2 { packingReferenceCount = pointerSlotOffset + pointerCount }) s2 { packingPointerCount = pointerSlotOffset + pointerCount })
| otherwise = | otherwise =
(packingReferenceCount s2, (packingPointerCount s2,
u2 { unionPointerSlot = UnionSlot pointerCount (packingReferenceCount s2) }, u2 { unionPointerSlot = UnionSlot pointerCount (packingPointerCount s2) },
s2 { packingReferenceCount = packingReferenceCount s2 + pointerCount }) s2 { packingPointerCount = packingPointerCount s2 + pointerCount })
combinedOffset = InlineCompositeOffset combinedOffset = InlineCompositeOffset
{ inlineCompositeDataOffset = dataOffset { inlineCompositeDataOffset = dataOffset
...@@ -738,7 +738,7 @@ packFields fields unions = let ...@@ -738,7 +738,7 @@ packFields fields unions = let
then dataSizeToSectionSize $ stripHolesFromFirstWord Size64 $ packingHoles finalState then dataSizeToSectionSize $ stripHolesFromFirstWord Size64 $ packingHoles finalState
else DataSectionWords $ packingDataSize finalState else DataSectionWords $ packingDataSize finalState
in (dataSectionSize, packingReferenceCount finalState, Map.fromList packedItems) in (dataSectionSize, packingPointerCount finalState, Map.fromList packedItems)
enforceFixed Nothing sizes = return sizes enforceFixed Nothing sizes = return sizes
enforceFixed (Just (Located pos (requestedDataSize, requestedPointerCount))) enforceFixed (Just (Located pos (requestedDataSize, requestedPointerCount)))
......
...@@ -195,7 +195,7 @@ cxxFieldSizeString (SizeData Size8) = "BYTE"; ...@@ -195,7 +195,7 @@ cxxFieldSizeString (SizeData Size8) = "BYTE";
cxxFieldSizeString (SizeData Size16) = "TWO_BYTES"; cxxFieldSizeString (SizeData Size16) = "TWO_BYTES";
cxxFieldSizeString (SizeData Size32) = "FOUR_BYTES"; cxxFieldSizeString (SizeData Size32) = "FOUR_BYTES";
cxxFieldSizeString (SizeData Size64) = "EIGHT_BYTES"; cxxFieldSizeString (SizeData Size64) = "EIGHT_BYTES";
cxxFieldSizeString SizeReference = "REFERENCE"; cxxFieldSizeString SizePointer = "POINTER";
cxxFieldSizeString (SizeInlineComposite _ _) = "INLINE_COMPOSITE"; cxxFieldSizeString (SizeInlineComposite _ _) = "INLINE_COMPOSITE";
fieldOffsetInteger VoidOffset = "0" fieldOffsetInteger VoidOffset = "0"
...@@ -207,7 +207,7 @@ fieldOffsetInteger (InlineCompositeOffset d p ds ps) = let ...@@ -207,7 +207,7 @@ fieldOffsetInteger (InlineCompositeOffset d p ds ps) = let
DataSectionWords _ -> d * 8 DataSectionWords _ -> d * 8
_ -> d * byteSize _ -> d * byteSize
in printf "%d * ::capnproto::BYTES, %d * ::capnproto::BYTES, \ in printf "%d * ::capnproto::BYTES, %d * ::capnproto::BYTES, \
\%d * ::capnproto::REFERENCES, %d * ::capnproto::REFERENCES" byteOffset byteSize p ps \%d * ::capnproto::POINTERS, %d * ::capnproto::POINTERS" byteOffset byteSize p ps
isDefaultZero VoidDesc = True isDefaultZero VoidDesc = True
isDefaultZero (BoolDesc b) = not b isDefaultZero (BoolDesc b) = not b
...@@ -473,7 +473,7 @@ outerFileContext schemaNodes = fileContext where ...@@ -473,7 +473,7 @@ outerFileContext schemaNodes = fileContext where
context "structFields" = MuList $ map (fieldContext context) $ structFields desc context "structFields" = MuList $ map (fieldContext context) $ structFields desc
context "structUnions" = MuList $ map (unionContext context) $ structUnions desc context "structUnions" = MuList $ map (unionContext context) $ structUnions desc
context "structDataSize" = MuVariable $ dataSectionWordSize $ structDataSize desc context "structDataSize" = MuVariable $ dataSectionWordSize $ structDataSize desc
context "structReferenceCount" = MuVariable $ structPointerCount desc context "structPointerCount" = MuVariable $ structPointerCount desc
context "structPreferredListEncoding" = case (structDataSize desc, structPointerCount desc) of context "structPreferredListEncoding" = case (structDataSize desc, structPointerCount desc) of
(DataSectionWords 0, 0) -> MuVariable "VOID" (DataSectionWords 0, 0) -> MuVariable "VOID"
(DataSection1, 0) -> MuVariable "BIT" (DataSection1, 0) -> MuVariable "BIT"
...@@ -481,7 +481,7 @@ outerFileContext schemaNodes = fileContext where ...@@ -481,7 +481,7 @@ outerFileContext schemaNodes = fileContext where
(DataSection16, 0) -> MuVariable "TWO_BYTES" (DataSection16, 0) -> MuVariable "TWO_BYTES"
(DataSection32, 0) -> MuVariable "FOUR_BYTES" (DataSection32, 0) -> MuVariable "FOUR_BYTES"
(DataSectionWords 1, 0) -> MuVariable "EIGHT_BYTES" (DataSectionWords 1, 0) -> MuVariable "EIGHT_BYTES"
(DataSectionWords 0, 1) -> MuVariable "REFERENCE" (DataSectionWords 0, 1) -> MuVariable "POINTER"
_ -> MuVariable "INLINE_COMPOSITE" _ -> MuVariable "INLINE_COMPOSITE"
context "structNestedEnums" = context "structNestedEnums" =
MuList $ map (enumContext context) [m | DescEnum m <- structMembers desc] MuList $ map (enumContext context) [m | DescEnum m <- structMembers desc]
......
...@@ -272,12 +272,12 @@ dataSizeInBits Size64 = 64 ...@@ -272,12 +272,12 @@ dataSizeInBits Size64 = 64
data FieldSize = SizeVoid data FieldSize = SizeVoid
| SizeData DataSize | SizeData DataSize
| SizeReference | SizePointer
| SizeInlineComposite DataSectionSize Integer | SizeInlineComposite DataSectionSize Integer
fieldSizeInBits SizeVoid = 0 fieldSizeInBits SizeVoid = 0
fieldSizeInBits (SizeData d) = dataSizeInBits d fieldSizeInBits (SizeData d) = dataSizeInBits d
fieldSizeInBits SizeReference = 64 fieldSizeInBits SizePointer = 64
fieldSizeInBits (SizeInlineComposite ds pc) = dataSectionBits ds + pc * 64 fieldSizeInBits (SizeInlineComposite ds pc) = dataSectionBits ds + pc * 64
data FieldOffset = VoidOffset data FieldOffset = VoidOffset
...@@ -293,7 +293,7 @@ data FieldOffset = VoidOffset ...@@ -293,7 +293,7 @@ data FieldOffset = VoidOffset
offsetToSize :: FieldOffset -> FieldSize offsetToSize :: FieldOffset -> FieldSize
offsetToSize VoidOffset = SizeVoid offsetToSize VoidOffset = SizeVoid
offsetToSize (DataOffset s _) = SizeData s offsetToSize (DataOffset s _) = SizeData s
offsetToSize (PointerOffset _) = SizeReference offsetToSize (PointerOffset _) = SizePointer
offsetToSize (InlineCompositeOffset _ _ d p) = SizeInlineComposite d p offsetToSize (InlineCompositeOffset _ _ d p) = SizeInlineComposite d p
fieldSize (BuiltinType BuiltinVoid) = SizeVoid fieldSize (BuiltinType BuiltinVoid) = SizeVoid
...@@ -308,15 +308,15 @@ fieldSize (BuiltinType BuiltinUInt32) = SizeData Size32 ...@@ -308,15 +308,15 @@ fieldSize (BuiltinType BuiltinUInt32) = SizeData Size32
fieldSize (BuiltinType BuiltinUInt64) = SizeData Size64 fieldSize (BuiltinType BuiltinUInt64) = SizeData Size64
fieldSize (BuiltinType BuiltinFloat32) = SizeData Size32 fieldSize (BuiltinType BuiltinFloat32) = SizeData Size32
fieldSize (BuiltinType BuiltinFloat64) = SizeData Size64 fieldSize (BuiltinType BuiltinFloat64) = SizeData Size64
fieldSize (BuiltinType BuiltinText) = SizeReference fieldSize (BuiltinType BuiltinText) = SizePointer
fieldSize (BuiltinType BuiltinData) = SizeReference fieldSize (BuiltinType BuiltinData) = SizePointer
fieldSize (BuiltinType BuiltinObject) = SizeReference fieldSize (BuiltinType BuiltinObject) = SizePointer
fieldSize (EnumType _) = SizeData Size16 fieldSize (EnumType _) = SizeData Size16
fieldSize (StructType _) = SizeReference fieldSize (StructType _) = SizePointer
fieldSize (InlineStructType StructDesc { structDataSize = ds, structPointerCount = ps }) = fieldSize (InlineStructType StructDesc { structDataSize = ds, structPointerCount = ps }) =
SizeInlineComposite ds ps SizeInlineComposite ds ps
fieldSize (InterfaceType _) = SizeReference fieldSize (InterfaceType _) = SizePointer
fieldSize (ListType _) = SizeReference fieldSize (ListType _) = SizePointer
fieldSize (InlineListType element size) = let fieldSize (InlineListType element size) = let
minDataSectionForBits bits minDataSectionForBits bits
| bits <= 0 = DataSectionWords 0 | bits <= 0 = DataSectionWords 0
...@@ -328,12 +328,12 @@ fieldSize (InlineListType element size) = let ...@@ -328,12 +328,12 @@ fieldSize (InlineListType element size) = let
dataSection = case fieldSize element of dataSection = case fieldSize element of
SizeVoid -> DataSectionWords 0 SizeVoid -> DataSectionWords 0
SizeData s -> minDataSectionForBits $ dataSizeInBits s * size SizeData s -> minDataSectionForBits $ dataSizeInBits s * size
SizeReference -> DataSectionWords 0 SizePointer -> DataSectionWords 0
SizeInlineComposite ds _ -> minDataSectionForBits $ dataSectionBits ds * size SizeInlineComposite ds _ -> minDataSectionForBits $ dataSectionBits ds * size
pointerCount = case fieldSize element of pointerCount = case fieldSize element of
SizeVoid -> 0 SizeVoid -> 0
SizeData _ -> 0 SizeData _ -> 0
SizeReference -> size SizePointer -> size
SizeInlineComposite _ pc -> pc * size SizeInlineComposite _ pc -> pc * size
in SizeInlineComposite dataSection pointerCount in SizeInlineComposite dataSection pointerCount
fieldSize (InlineDataType size) fieldSize (InlineDataType size)
......
...@@ -77,13 +77,13 @@ encodeMaskedDataValue t v (Just d) = xorData (encodeDataValue t v) (encodeDataVa ...@@ -77,13 +77,13 @@ encodeMaskedDataValue t v (Just d) = xorData (encodeDataValue t v) (encodeDataVa
encodePointerValue :: TypeDesc -> ValueDesc -> (Integer -> [Word8], [Word8]) encodePointerValue :: TypeDesc -> ValueDesc -> (Integer -> [Word8], [Word8])
encodePointerValue _ (TextDesc text) = let encodePointerValue _ (TextDesc text) = let
encoded = UTF8.encode text ++ [0] encoded = UTF8.encode text ++ [0]
in (encodeListReference (SizeData Size8) (genericLength encoded), padToWord encoded) in (encodeListPointer (SizeData Size8) (genericLength encoded), padToWord encoded)
encodePointerValue _ (DataDesc d) = encodePointerValue _ (DataDesc d) =
(encodeListReference (SizeData Size8) (genericLength d), padToWord d) (encodeListPointer (SizeData Size8) (genericLength d), padToWord d)
encodePointerValue (StructType desc) (StructValueDesc assignments) = let encodePointerValue (StructType desc) (StructValueDesc assignments) = let
(dataBytes, refBytes, childBytes) = encodeStruct desc assignments 0 (dataBytes, ptrBytes, childBytes) = encodeStruct desc assignments 0
in (encodeStructReference (structDataSize desc, structPointerCount desc), in (encodeStructPointer (structDataSize desc, structPointerCount desc),
concat [dataBytes, refBytes, childBytes]) concat [dataBytes, ptrBytes, childBytes])
encodePointerValue (InlineStructType _) _ = encodePointerValue (InlineStructType _) _ =
error "Tried to encode inline struct as a pointer." error "Tried to encode inline struct as a pointer."
encodePointerValue (ListType elementType) (ListDesc items) = encodeList elementType items encodePointerValue (ListType elementType) (ListDesc items) = encodeList elementType items
...@@ -132,15 +132,15 @@ packPointers size items o = loop 0 items (o + size - 1) where ...@@ -132,15 +132,15 @@ packPointers size items o = loop 0 items (o + size - 1) where
in (genericReplicate (padCount * 8) 0 ++ restPtrs, restChildren) in (genericReplicate (padCount * 8) 0 ++ restPtrs, restChildren)
loop idx [] _ = (genericReplicate ((size - idx) * 8) 0, []) loop idx [] _ = (genericReplicate ((size - idx) * 8) 0, [])
encodeStructReference (dataSize, pointerCount) offset = encodeStructPointer (dataSize, pointerCount) offset =
intToBytes (offset * 4 + structTag) 4 ++ intToBytes (offset * 4 + structTag) 4 ++
intToBytes (dataSectionWordSize dataSize) 2 ++ intToBytes (dataSectionWordSize dataSize) 2 ++
intToBytes pointerCount 2 intToBytes pointerCount 2
encodeListReference elemSize@(SizeInlineComposite ds rc) elementCount offset = encodeListPointer elemSize@(SizeInlineComposite ds rc) elementCount offset =
intToBytes (offset * 4 + listTag) 4 ++ intToBytes (offset * 4 + listTag) 4 ++
intToBytes (fieldSizeEnum elemSize + shiftL (elementCount * (dataSectionWordSize ds + rc)) 3) 4 intToBytes (fieldSizeEnum elemSize + shiftL (elementCount * (dataSectionWordSize ds + rc)) 3) 4
encodeListReference elemSize elementCount offset = encodeListPointer elemSize elementCount offset =
intToBytes (offset * 4 + listTag) 4 ++ intToBytes (offset * 4 + listTag) 4 ++
intToBytes (fieldSizeEnum elemSize + shiftL elementCount 3) 4 intToBytes (fieldSizeEnum elemSize + shiftL elementCount 3) 4
...@@ -150,13 +150,13 @@ fieldSizeEnum (SizeData Size8) = 2 ...@@ -150,13 +150,13 @@ fieldSizeEnum (SizeData Size8) = 2
fieldSizeEnum (SizeData Size16) = 3 fieldSizeEnum (SizeData Size16) = 3
fieldSizeEnum (SizeData Size32) = 4 fieldSizeEnum (SizeData Size32) = 4
fieldSizeEnum (SizeData Size64) = 5 fieldSizeEnum (SizeData Size64) = 5
fieldSizeEnum SizeReference = 6 fieldSizeEnum SizePointer = 6
fieldSizeEnum (SizeInlineComposite _ _) = 7 fieldSizeEnum (SizeInlineComposite _ _) = 7
structTag = 0 structTag = 0
listTag = 1 listTag = 1
-- childOffset = number of words between the last reference and the location where children will -- childOffset = number of words between the last pointer and the location where children will
-- be allocated. -- be allocated.
encodeStruct desc assignments childOffset = let encodeStruct desc assignments childOffset = let
dataSize = dataSectionBits $ structDataSize desc dataSize = dataSectionBits $ structDataSize desc
...@@ -224,38 +224,38 @@ encodeList :: TypeDesc -- Type of each element. ...@@ -224,38 +224,38 @@ encodeList :: TypeDesc -- Type of each element.
-- Encode a list of empty structs as void. -- Encode a list of empty structs as void.
encodeList (StructType StructDesc { encodeList (StructType StructDesc {
structDataSize = DataSectionWords 0, structPointerCount = 0 }) elements = structDataSize = DataSectionWords 0, structPointerCount = 0 }) elements =
(encodeListReference SizeVoid (genericLength elements), []) (encodeListPointer SizeVoid (genericLength elements), [])
-- Encode a list of sub-word data-only structs as a list of primitives. -- Encode a list of sub-word data-only structs as a list of primitives.
encodeList (StructType desc@StructDesc { structDataSize = ds, structPointerCount = 0 }) elements encodeList (StructType desc@StructDesc { structDataSize = ds, structPointerCount = 0 }) elements
| dataSectionBits ds <= 64 = let | dataSectionBits ds <= 64 = let
in (encodeListReference (SizeData $ dataSectionAlignment ds) (genericLength elements), in (encodeListPointer (SizeData $ dataSectionAlignment ds) (genericLength elements),
inlineStructListDataSection desc elements) inlineStructListDataSection desc elements)
-- Encode a list of single-pointer structs as a list of pointers. -- Encode a list of single-pointer structs as a list of pointers.
encodeList (StructType desc@StructDesc { encodeList (StructType desc@StructDesc {
structDataSize = DataSectionWords 0, structPointerCount = 1 }) elements = let structDataSize = DataSectionWords 0, structPointerCount = 1 }) elements = let
(refBytes, childBytes) = inlineStructListPointerSection desc elements (ptrBytes, childBytes) = inlineStructListPointerSection desc elements
in (encodeListReference SizeReference (genericLength elements), refBytes ++ childBytes) in (encodeListPointer SizePointer (genericLength elements), ptrBytes ++ childBytes)
-- Encode a list of any other sort of struct. -- Encode a list of any other sort of struct.
encodeList (StructType desc) elements = let encodeList (StructType desc) elements = let
count = genericLength elements count = genericLength elements
tag = encodeStructReference (structDataSize desc, structPointerCount desc) count tag = encodeStructPointer (structDataSize desc, structPointerCount desc) count
eSize = dataSectionWordSize (structDataSize desc) + structPointerCount desc eSize = dataSectionWordSize (structDataSize desc) + structPointerCount desc
structElems = [v | StructValueDesc v <- elements] structElems = [v | StructValueDesc v <- elements]
(elemBytes, childBytes) = loop (eSize * genericLength structElems) structElems (elemBytes, childBytes) = loop (eSize * genericLength structElems) structElems
loop _ [] = ([], []) loop _ [] = ([], [])
loop offset (element:rest) = let loop offset (element:rest) = let
offsetFromElementEnd = offset - eSize offsetFromElementEnd = offset - eSize
(dataBytes, refBytes, childBytes2) = encodeStruct desc element offsetFromElementEnd (dataBytes, ptrBytes, childBytes2) = encodeStruct desc element offsetFromElementEnd
childLen = genericLength childBytes2 childLen = genericLength childBytes2
childWordLen = if mod childLen 8 == 0 childWordLen = if mod childLen 8 == 0
then div childLen 8 then div childLen 8
else error "Child not word-aligned." else error "Child not word-aligned."
(restBytes, restChildren) = loop (offsetFromElementEnd + childWordLen) rest (restBytes, restChildren) = loop (offsetFromElementEnd + childWordLen) rest
in (dataBytes ++ refBytes ++ restBytes, childBytes2 ++ restChildren) in (dataBytes ++ ptrBytes ++ restBytes, childBytes2 ++ restChildren)
in (encodeListReference (SizeInlineComposite (structDataSize desc) (structPointerCount desc)) in (encodeListPointer (SizeInlineComposite (structDataSize desc) (structPointerCount desc))
(genericLength elements), (genericLength elements),
concat [tag, elemBytes, childBytes]) concat [tag, elemBytes, childBytes])
...@@ -280,14 +280,14 @@ encodeList elementType elements = let ...@@ -280,14 +280,14 @@ encodeList elementType elements = let
dataBytes = case eSize of dataBytes = case eSize of
SizeVoid -> [] SizeVoid -> []
SizeInlineComposite _ _ -> error "All inline composites should have been handled above." SizeInlineComposite _ _ -> error "All inline composites should have been handled above."
SizeReference -> refBytes ++ childBytes where SizePointer -> ptrBytes ++ childBytes where
encodedElements = zip [0..] $ map (encodePointerValue elementType) elements encodedElements = zip [0..] $ map (encodePointerValue elementType) elements
(refBytes, childBytes) = packPointers (genericLength elements) encodedElements 0 (ptrBytes, childBytes) = packPointers (genericLength elements) encodedElements 0
SizeData size -> let SizeData size -> let
bits = dataSizeInBits size bits = dataSizeInBits size
encodedElements = zip [0,bits..] $ map (encodeDataValue elementType) elements encodedElements = zip [0,bits..] $ map (encodeDataValue elementType) elements
in packBytes (genericLength elements * bits) encodedElements in packBytes (genericLength elements * bits) encodedElements
in (encodeListReference eSize (genericLength elements), dataBytes) in (encodeListPointer eSize (genericLength elements), dataBytes)
--------------------------------------------- ---------------------------------------------
...@@ -298,7 +298,7 @@ inlineListDataSectionValues elementType elements = case fieldSize elementType of ...@@ -298,7 +298,7 @@ inlineListDataSectionValues elementType elements = case fieldSize elementType of
InlineListType t _ -> inlineListDataSectionValues t (concat [l | ListDesc l <- elements]) InlineListType t _ -> inlineListDataSectionValues t (concat [l | ListDesc l <- elements])
InlineDataType _ -> [(0, EncodedBytes $ concat [l | DataDesc l <- elements])] InlineDataType _ -> [(0, EncodedBytes $ concat [l | DataDesc l <- elements])]
_ -> error "Unknown inline composite type." _ -> error "Unknown inline composite type."
SizeReference -> [] SizePointer -> []
SizeData size -> let SizeData size -> let
bits = dataSizeInBits size bits = dataSizeInBits size
in zip [0,bits..] $ map (encodeDataValue elementType) elements in zip [0,bits..] $ map (encodeDataValue elementType) elements
...@@ -310,7 +310,7 @@ inlineListPointerSectionValues elementType elements = case fieldSize elementType ...@@ -310,7 +310,7 @@ inlineListPointerSectionValues elementType elements = case fieldSize elementType
InlineListType t _ -> inlineListPointerSectionValues t (concat [l | ListDesc l <- elements]) InlineListType t _ -> inlineListPointerSectionValues t (concat [l | ListDesc l <- elements])
InlineDataType _ -> [] InlineDataType _ -> []
_ -> error "Unknown inline composite type." _ -> error "Unknown inline composite type."
SizeReference -> zip [0..] $ map (encodePointerValue elementType) elements SizePointer -> zip [0..] $ map (encodePointerValue elementType) elements
SizeData _ -> [] SizeData _ -> []
inlineStructListDataSection elementDesc elements = inlineStructListDataSection elementDesc elements =
...@@ -338,9 +338,9 @@ inlineStructListPointerSectionValues elementDesc elements = do ...@@ -338,9 +338,9 @@ inlineStructListPointerSectionValues elementDesc elements = do
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
encodeMessage (StructType desc) (StructValueDesc assignments) = let encodeMessage (StructType desc) (StructValueDesc assignments) = let
(dataBytes, refBytes, childBytes) = encodeStruct desc assignments 0 (dataBytes, ptrBytes, childBytes) = encodeStruct desc assignments 0
in concat [encodeStructReference (structDataSize desc, structPointerCount desc) (0::Integer), in concat [encodeStructPointer (structDataSize desc, structPointerCount desc) (0::Integer),
dataBytes, refBytes, childBytes] dataBytes, ptrBytes, childBytes]
encodeMessage (ListType elementType) (ListDesc elements) = let encodeMessage (ListType elementType) (ListDesc elements) = let
(ptr, listBytes) = encodeList elementType elements (ptr, listBytes) = encodeList elementType elements
in ptr (0::Integer) ++ listBytes in ptr (0::Integer) ++ listBytes
...@@ -368,20 +368,20 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where ...@@ -368,20 +368,20 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where
elemBits = dataSizeInBits elementSize elemBits = dataSizeInBits elementSize
bytes = packBytes (elemBits * genericLength elements) bytes = packBytes (elemBits * genericLength elements)
$ zip [0,elemBits..] elements $ zip [0,elemBits..] elements
in (encodeListReference (SizeData elementSize) (genericLength elements), bytes) in (encodeListPointer (SizeData elementSize) (genericLength elements), bytes)
-- Not used, but maybe useful in the future. -- Not used, but maybe useful in the future.
--encPtrList :: [EncodedPtr] -> EncodedPtr --encPtrList :: [EncodedPtr] -> EncodedPtr
--encPtrList elements = let --encPtrList elements = let
-- (ptrBytes, childBytes) = packPointers (genericLength elements) (zip [0..] elements) 0 -- (ptrBytes, childBytes) = packPointers (genericLength elements) (zip [0..] elements) 0
-- in (encodeListReference SizeReference (genericLength elements), ptrBytes ++ childBytes) -- in (encodeListPointer SizePointer (genericLength elements), ptrBytes ++ childBytes)
encStructList :: (DataSectionSize, Integer) encStructList :: (DataSectionSize, Integer)
-> [([(Integer, EncodedData)], [(Integer, EncodedPtr)])] -> [([(Integer, EncodedData)], [(Integer, EncodedPtr)])]
-> EncodedPtr -> EncodedPtr
encStructList elementSize@(dataSize, pointerCount) elements = let encStructList elementSize@(dataSize, pointerCount) elements = let
count = genericLength elements count = genericLength elements
tag = encodeStructReference elementSize count tag = encodeStructPointer elementSize count
eSize = dataSectionWordSize dataSize + pointerCount eSize = dataSectionWordSize dataSize + pointerCount
(elemBytes, childBytes) = loop (eSize * genericLength elements) elements (elemBytes, childBytes) = loop (eSize * genericLength elements) elements
loop _ [] = ([], []) loop _ [] = ([], [])
...@@ -395,7 +395,7 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where ...@@ -395,7 +395,7 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where
else error "Child not word-aligned." else error "Child not word-aligned."
(restBytes, restChildren) = loop (offsetFromElementEnd + childWordLen) rest (restBytes, restChildren) = loop (offsetFromElementEnd + childWordLen) rest
in (concat [dataBytes, ptrBytes, restBytes], childBytes2 ++ restChildren) in (concat [dataBytes, ptrBytes, restBytes], childBytes2 ++ restChildren)
in (encodeListReference (SizeInlineComposite dataSize pointerCount) (genericLength elements), in (encodeListPointer (SizeInlineComposite dataSize pointerCount) (genericLength elements),
concat [tag, elemBytes, childBytes]) concat [tag, elemBytes, childBytes])
encStructBody :: (DataSectionSize, Integer) encStructBody :: (DataSectionSize, Integer)
...@@ -413,7 +413,7 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where ...@@ -413,7 +413,7 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where
-> EncodedPtr -> EncodedPtr
encStruct size (dataValues, ptrValues) = let encStruct size (dataValues, ptrValues) = let
(dataBytes, ptrBytes, childBytes) = encStructBody size dataValues ptrValues 0 (dataBytes, ptrBytes, childBytes) = encStructBody size dataValues ptrValues 0
in (encodeStructReference size, concat [dataBytes, ptrBytes, childBytes]) in (encodeStructPointer size, concat [dataBytes, ptrBytes, childBytes])
--------------------------------------------- ---------------------------------------------
...@@ -497,14 +497,14 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where ...@@ -497,14 +497,14 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where
(Nothing, _) -> [] (Nothing, _) -> []
(_, SizeVoid) -> [] (_, SizeVoid) -> []
(Just value, SizeData _) -> [ (64, encodeDataValue t value) ] (Just value, SizeData _) -> [ (64, encodeDataValue t value) ]
(_, SizeReference) -> [] (_, SizePointer) -> []
(_, SizeInlineComposite _ _) -> (_, SizeInlineComposite _ _) ->
error "Inline types not currently supported by codegen plugins.") error "Inline types not currently supported by codegen plugins.")
ptrValues = case (maybeValue, fieldSize t) of ptrValues = case (maybeValue, fieldSize t) of
(Nothing, _) -> [] (Nothing, _) -> []
(_, SizeVoid) -> [] (_, SizeVoid) -> []
(_, SizeData _) -> [] (_, SizeData _) -> []
(Just value, SizeReference) -> [ (0, encodePointerValue t value) ] (Just value, SizePointer) -> [ (0, encodePointerValue t value) ]
(_, SizeInlineComposite _ _) -> (_, SizeInlineComposite _ _) ->
error "Inline types not currently supported by codegen plugins." error "Inline types not currently supported by codegen plugins."
...@@ -596,7 +596,7 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where ...@@ -596,7 +596,7 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where
preferredListEncoding = case (structDataSize desc, structPointerCount desc) of preferredListEncoding = case (structDataSize desc, structPointerCount desc) of
(DataSectionWords 0, 0) -> SizeVoid (DataSectionWords 0, 0) -> SizeVoid
(DataSectionWords 0, 1) -> SizeReference (DataSectionWords 0, 1) -> SizePointer
(DataSection1, 0) -> SizeData Size1 (DataSection1, 0) -> SizeData Size1
(DataSection8, 0) -> SizeData Size8 (DataSection8, 0) -> SizeData Size8
(DataSection16, 0) -> SizeData Size16 (DataSection16, 0) -> SizeData Size16
......
...@@ -113,7 +113,7 @@ namespace internal { ...@@ -113,7 +113,7 @@ namespace internal {
{{#typeStruct}} {{#typeStruct}}
CAPNPROTO_DECLARE_STRUCT( CAPNPROTO_DECLARE_STRUCT(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}, {{structId}}, ::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}, {{structId}},
{{structDataSize}}, {{structReferenceCount}}, {{structPreferredListEncoding}}); {{structDataSize}}, {{structPointerCount}}, {{structPreferredListEncoding}});
{{#structNestedEnums}} {{#structNestedEnums}}
CAPNPROTO_DECLARE_ENUM( CAPNPROTO_DECLARE_ENUM(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}::{{enumName}}, {{enumId}}); ::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}::{{enumName}}, {{enumId}});
...@@ -302,7 +302,7 @@ inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() { ...@@ -302,7 +302,7 @@ inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<{{fieldType}}>::get( return ::capnproto::internal::PointerHelpers<{{fieldType}}>::get(
_reader, {{fieldOffset}} * ::capnproto::REFERENCES{{#fieldDefaultBytes}}, _reader, {{fieldOffset}} * ::capnproto::POINTERS{{#fieldDefaultBytes}},
DEFAULT_{{fieldUpperCase}}.words{{#fieldIsBlob}}, {{defaultBlobSize}}{{/fieldIsBlob}}{{/fieldDefaultBytes}}); DEFAULT_{{fieldUpperCase}}.words{{#fieldIsBlob}}, {{defaultBlobSize}}{{/fieldIsBlob}}{{/fieldDefaultBytes}});
} }
...@@ -312,7 +312,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() ...@@ -312,7 +312,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}()
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<{{fieldType}}>::get( return ::capnproto::internal::PointerHelpers<{{fieldType}}>::get(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES{{#fieldDefaultBytes}}, _builder, {{fieldOffset}} * ::capnproto::POINTERS{{#fieldDefaultBytes}},
DEFAULT_{{fieldUpperCase}}.words{{#fieldIsBlob}}, {{defaultBlobSize}}{{/fieldIsBlob}}{{/fieldDefaultBytes}}); DEFAULT_{{fieldUpperCase}}.words{{#fieldIsBlob}}, {{defaultBlobSize}}{{/fieldIsBlob}}{{/fieldDefaultBytes}});
} }
...@@ -322,7 +322,7 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}({{fieldType}}::Read ...@@ -322,7 +322,7 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}({{fieldType}}::Read
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}}); {{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}} {{/fieldUnion}}
::capnproto::internal::PointerHelpers<{{fieldType}}>::set( ::capnproto::internal::PointerHelpers<{{fieldType}}>::set(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, value); _builder, {{fieldOffset}} * ::capnproto::POINTERS, value);
} }
{{#fieldIsList}} {{#fieldIsList}}
...@@ -333,7 +333,7 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}( ...@@ -333,7 +333,7 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}}); {{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}} {{/fieldUnion}}
::capnproto::internal::PointerHelpers<{{fieldType}}>::set( ::capnproto::internal::PointerHelpers<{{fieldType}}>::set(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, value); _builder, {{fieldOffset}} * ::capnproto::POINTERS, value);
} }
{{/fieldIsList}} {{/fieldIsList}}
...@@ -344,7 +344,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}( ...@@ -344,7 +344,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}}); {{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<{{fieldType}}>::init( return ::capnproto::internal::PointerHelpers<{{fieldType}}>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, size); _builder, {{fieldOffset}} * ::capnproto::POINTERS, size);
} }
{{/fieldIsListOrBlob}} {{/fieldIsListOrBlob}}
...@@ -355,7 +355,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}( ...@@ -355,7 +355,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}}); {{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<{{fieldType}}>::init( return ::capnproto::internal::PointerHelpers<{{fieldType}}>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES); _builder, {{fieldOffset}} * ::capnproto::POINTERS);
} }
{{/fieldIsStruct}} {{/fieldIsStruct}}
...@@ -370,7 +370,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() { ...@@ -370,7 +370,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::get( return ::capnproto::internal::PointerHelpers<T>::get(
_reader, {{fieldOffset}} * ::capnproto::REFERENCES); _reader, {{fieldOffset}} * ::capnproto::POINTERS);
} }
template <typename T> template <typename T>
...@@ -380,7 +380,7 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() { ...@@ -380,7 +380,7 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() {
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::get( return ::capnproto::internal::PointerHelpers<T>::get(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES); _builder, {{fieldOffset}} * ::capnproto::POINTERS);
} }
template <typename T, typename Param> template <typename T, typename Param>
...@@ -390,7 +390,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(Param& ...@@ -390,7 +390,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(Param&
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::getDynamic( return ::capnproto::internal::PointerHelpers<T>::getDynamic(
_reader, {{fieldOffset}} * ::capnproto::REFERENCES, ::capnproto::forward<Param>(param)); _reader, {{fieldOffset}} * ::capnproto::POINTERS, ::capnproto::forward<Param>(param));
} }
template <typename T, typename Param> template <typename T, typename Param>
...@@ -400,7 +400,7 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}(Para ...@@ -400,7 +400,7 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}(Para
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::getDynamic( return ::capnproto::internal::PointerHelpers<T>::getDynamic(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, ::capnproto::forward<Param>(param)); _builder, {{fieldOffset}} * ::capnproto::POINTERS, ::capnproto::forward<Param>(param));
} }
template <typename T> template <typename T>
...@@ -410,7 +410,7 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(typename T::Reader ...@@ -410,7 +410,7 @@ inline void {{typeFullName}}::Builder::set{{fieldTitleCase}}(typename T::Reader
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}}); {{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}} {{/fieldUnion}}
::capnproto::internal::PointerHelpers<T>::set( ::capnproto::internal::PointerHelpers<T>::set(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, value); _builder, {{fieldOffset}} * ::capnproto::POINTERS, value);
} }
template <typename T, typename... Params> template <typename T, typename... Params>
...@@ -420,7 +420,7 @@ inline typename T::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(Par ...@@ -420,7 +420,7 @@ inline typename T::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(Par
{{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}}); {{unionTagOffset}} * ::capnproto::ELEMENTS, {{unionTitleCase}}::{{fieldUpperCase}});
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::init( return ::capnproto::internal::PointerHelpers<T>::init(
_builder, {{fieldOffset}} * ::capnproto::REFERENCES, ::capnproto::forward<Params>(params)...); _builder, {{fieldOffset}} * ::capnproto::POINTERS, ::capnproto::forward<Params>(params)...);
} }
{{/fieldIsGenericObject}} {{/fieldIsGenericObject}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment