bring up to date
This commit is contained in:
parent
7adaa91435
commit
25a537c323
12 changed files with 207 additions and 192 deletions
|
@ -620,7 +620,7 @@ private:
|
||||||
" assert which() == ", scope, "Which.", upperCase, ":\n",
|
" assert which() == ", scope, "Which.", upperCase, ":\n",
|
||||||
spaces(indent), " \"Must check which() before get()ing a union member.\";\n"),
|
spaces(indent), " \"Must check which() before get()ing a union member.\";\n"),
|
||||||
kj::str(
|
kj::str(
|
||||||
spaces(indent), " _builder.setShortField(", discrimOffset, ", (short)",
|
spaces(indent), " _setShortField(", discrimOffset, ", (short)",
|
||||||
scope, "Which.", upperCase, ".ordinal());\n"),
|
scope, "Which.", upperCase, ".ordinal());\n"),
|
||||||
kj::strTree(spaces(indent), "public final boolean is", titleCase, "() {\n",
|
kj::strTree(spaces(indent), "public final boolean is", titleCase, "() {\n",
|
||||||
spaces(indent), " return which() == ", scope, "Which.", upperCase,";\n",
|
spaces(indent), " return which() == ", scope, "Which.", upperCase,";\n",
|
||||||
|
@ -657,7 +657,7 @@ private:
|
||||||
kj::StringTree makeEnumGetter(EnumSchema schema, kj::String member, uint offset, kj::String defaultMaskParam, int indent) {
|
kj::StringTree makeEnumGetter(EnumSchema schema, kj::String member, uint offset, kj::String defaultMaskParam, int indent) {
|
||||||
auto enumerants = schema.getEnumerants();
|
auto enumerants = schema.getEnumerants();
|
||||||
return kj::strTree(
|
return kj::strTree(
|
||||||
spaces(indent), "switch(", member, ".getShortField(", offset, defaultMaskParam, ")) {\n",
|
spaces(indent), "switch(_getShortField(", offset, defaultMaskParam, ")) {\n",
|
||||||
KJ_MAP(e, enumerants) {
|
KJ_MAP(e, enumerants) {
|
||||||
return kj::strTree(spaces(indent+1), "case ", e.getOrdinal(), " : return ",
|
return kj::strTree(spaces(indent+1), "case ", e.getOrdinal(), " : return ",
|
||||||
javaFullName(schema), ".",
|
javaFullName(schema), ".",
|
||||||
|
@ -738,14 +738,16 @@ private:
|
||||||
kj::strTree(
|
kj::strTree(
|
||||||
kj::mv(unionDiscrim.readerIsDecl),
|
kj::mv(unionDiscrim.readerIsDecl),
|
||||||
spaces(indent), " public ", titleCase, ".Reader get", titleCase, "() {\n",
|
spaces(indent), " public ", titleCase, ".Reader get", titleCase, "() {\n",
|
||||||
spaces(indent), " return new ", scope, titleCase, ".Reader(_reader);\n",
|
spaces(indent), " return new ", scope, titleCase,
|
||||||
|
".Reader(segment, data, pointers, dataSize, pointerCount, bit0Offset, nestingLimit);\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
"\n"),
|
"\n"),
|
||||||
|
|
||||||
kj::strTree(
|
kj::strTree(
|
||||||
kj::mv(unionDiscrim.builderIsDecl),
|
kj::mv(unionDiscrim.builderIsDecl),
|
||||||
spaces(indent), " public final ", titleCase, ".Builder get", titleCase, "() {\n",
|
spaces(indent), " public final ", titleCase, ".Builder get", titleCase, "() {\n",
|
||||||
spaces(indent), " return new ", scope, titleCase, ".Builder(_builder);\n",
|
spaces(indent), " return new ", scope, titleCase,
|
||||||
|
".Builder(segment, data, pointers, dataSize, pointerCount, bit0Offset);\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final ", titleCase, ".Builder init", titleCase, "() {\n",
|
spaces(indent), " public final ", titleCase, ".Builder init", titleCase, "() {\n",
|
||||||
unionDiscrim.set,
|
unionDiscrim.set,
|
||||||
|
@ -756,16 +758,17 @@ private:
|
||||||
case Section::DATA:
|
case Section::DATA:
|
||||||
return kj::strTree(
|
return kj::strTree(
|
||||||
spaces(indent),
|
spaces(indent),
|
||||||
" _builder.set", toTitleCase(maskType(slot.whichType)),
|
" _set", toTitleCase(maskType(slot.whichType)),
|
||||||
"Field(", slot.offset, ",", maskZeroLiteral(slot.whichType),
|
"Field(", slot.offset, ",", maskZeroLiteral(slot.whichType),
|
||||||
");\n");
|
");\n");
|
||||||
case Section::POINTERS:
|
case Section::POINTERS:
|
||||||
return kj::strTree(
|
return kj::strTree(
|
||||||
spaces(indent), " _builder.getPointerField(", slot.offset, ").clear();\n");
|
spaces(indent), " _getPointerField(", slot.offset, ").clear();\n");
|
||||||
}
|
}
|
||||||
KJ_UNREACHABLE;
|
KJ_UNREACHABLE;
|
||||||
},
|
},
|
||||||
" return new ", scope, titleCase, ".Builder(_builder);\n",
|
" return new ", scope, titleCase,
|
||||||
|
".Builder(segment, data, pointers, dataSize, pointerCount, bit0Offset);\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
"\n")
|
"\n")
|
||||||
};
|
};
|
||||||
|
@ -896,7 +899,7 @@ private:
|
||||||
kj::str("_reader"), offset, kj::str(defaultMaskParam), indent + 2) :
|
kj::str("_reader"), offset, kj::str(defaultMaskParam), indent + 2) :
|
||||||
(typeBody.which() == schema::Type::VOID ?
|
(typeBody.which() == schema::Type::VOID ?
|
||||||
kj::strTree(spaces(indent), " return org.capnproto.Void.VOID;\n") :
|
kj::strTree(spaces(indent), " return org.capnproto.Void.VOID;\n") :
|
||||||
kj::strTree(spaces(indent), " return _reader.get",toTitleCase(type),"Field(", offset, defaultMaskParam, ");\n"))),
|
kj::strTree(spaces(indent), " return _get",toTitleCase(type),"Field(", offset, defaultMaskParam, ");\n"))),
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
"\n"),
|
"\n"),
|
||||||
|
|
||||||
|
@ -909,16 +912,16 @@ private:
|
||||||
kj::str("_builder"), offset, kj::str(defaultMaskParam), indent + 2) :
|
kj::str("_builder"), offset, kj::str(defaultMaskParam), indent + 2) :
|
||||||
(typeBody.which() == schema::Type::VOID ?
|
(typeBody.which() == schema::Type::VOID ?
|
||||||
kj::strTree(spaces(indent), " return org.capnproto.Void.VOID;\n") :
|
kj::strTree(spaces(indent), " return org.capnproto.Void.VOID;\n") :
|
||||||
kj::strTree(spaces(indent), " return _builder.get",toTitleCase(type),"Field(", offset, defaultMaskParam, ");\n"))),
|
kj::strTree(spaces(indent), " return _get",toTitleCase(type),"Field(", offset, defaultMaskParam, ");\n"))),
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public final void set", titleCase, "(", type, " value) {\n",
|
spaces(indent), " public final void set", titleCase, "(", type, " value) {\n",
|
||||||
unionDiscrim.set,
|
unionDiscrim.set,
|
||||||
(typeBody.which() == schema::Type::ENUM ?
|
(typeBody.which() == schema::Type::ENUM ?
|
||||||
kj::strTree(spaces(indent), " _builder.setShortField(", offset, ", (short)value.ordinal());\n") :
|
kj::strTree(spaces(indent), " _setShortField(", offset, ", (short)value.ordinal());\n") :
|
||||||
(typeBody.which() == schema::Type::VOID ?
|
(typeBody.which() == schema::Type::VOID ?
|
||||||
kj::strTree() :
|
kj::strTree() :
|
||||||
kj::strTree(spaces(indent), " _builder.set",
|
kj::strTree(spaces(indent), " _set",
|
||||||
toTitleCase(type), "Field(", offset, ", value", defaultMaskParam, ");\n"))),
|
toTitleCase(type), "Field(", offset, ", value", defaultMaskParam, ");\n"))),
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
"\n")
|
"\n")
|
||||||
|
@ -932,31 +935,31 @@ private:
|
||||||
kj::mv(unionDiscrim.readerIsDecl),
|
kj::mv(unionDiscrim.readerIsDecl),
|
||||||
spaces(indent), " public boolean has", titleCase, "() {\n",
|
spaces(indent), " public boolean has", titleCase, "() {\n",
|
||||||
unionDiscrim.has,
|
unionDiscrim.has,
|
||||||
spaces(indent), " return !_reader.getPointerField(", offset, ").isNull();\n",
|
spaces(indent), " return !_getPointerField(", offset, ").isNull();\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public org.capnproto.AnyPointer.Reader get", titleCase, "() {\n",
|
spaces(indent), " public org.capnproto.AnyPointer.Reader get", titleCase, "() {\n",
|
||||||
unionDiscrim.check,
|
unionDiscrim.check,
|
||||||
spaces(indent), " return new org.capnproto.AnyPointer.Reader(_reader.getPointerField(",
|
spaces(indent), " return new org.capnproto.AnyPointer.Reader(_getPointerField(",
|
||||||
offset,"));\n",
|
offset,"));\n",
|
||||||
spaces(indent), " }\n"),
|
spaces(indent), " }\n"),
|
||||||
|
|
||||||
kj::strTree(
|
kj::strTree(
|
||||||
kj::mv(unionDiscrim.builderIsDecl),
|
kj::mv(unionDiscrim.builderIsDecl),
|
||||||
spaces(indent), " public final boolean has", titleCase, "() {\n",
|
spaces(indent), " public final boolean has", titleCase, "() {\n",
|
||||||
spaces(indent), " return !_builder.getPointerField(", offset, ").isNull();\n",
|
spaces(indent), " return !_getPointerField(", offset, ").isNull();\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public org.capnproto.AnyPointer.Builder get", titleCase, "() {\n",
|
spaces(indent), " public org.capnproto.AnyPointer.Builder get", titleCase, "() {\n",
|
||||||
unionDiscrim.check,
|
unionDiscrim.check,
|
||||||
spaces(indent), " return new org.capnproto.AnyPointer.Builder(_builder.getPointerField(",
|
spaces(indent), " return new org.capnproto.AnyPointer.Builder(_getPointerField(",
|
||||||
offset, "));\n",
|
offset, "));\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public org.capnproto.AnyPointer.Builder init", titleCase, "() {\n",
|
spaces(indent), " public org.capnproto.AnyPointer.Builder init", titleCase, "() {\n",
|
||||||
unionDiscrim.set,
|
unionDiscrim.set,
|
||||||
spaces(indent), " org.capnproto.AnyPointer.Builder result =\n",
|
spaces(indent), " org.capnproto.AnyPointer.Builder result =\n",
|
||||||
spaces(indent), " new org.capnproto.AnyPointer.Builder(_builder.getPointerField(",
|
spaces(indent), " new org.capnproto.AnyPointer.Builder(_getPointerField(",
|
||||||
offset, "));\n",
|
offset, "));\n",
|
||||||
spaces(indent), " result.clear();\n",
|
spaces(indent), " result.clear();\n",
|
||||||
spaces(indent), " return result;\n",
|
spaces(indent), " return result;\n",
|
||||||
|
@ -973,32 +976,32 @@ private:
|
||||||
kj::strTree(
|
kj::strTree(
|
||||||
kj::mv(unionDiscrim.readerIsDecl),
|
kj::mv(unionDiscrim.readerIsDecl),
|
||||||
spaces(indent), " public boolean has", titleCase, "() {\n",
|
spaces(indent), " public boolean has", titleCase, "() {\n",
|
||||||
spaces(indent), " return !_reader.getPointerField(", offset, ").isNull();\n",
|
spaces(indent), " return !_getPointerField(", offset, ").isNull();\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public ", type, ".Reader get", titleCase, "() {\n",
|
spaces(indent), " public ", type, ".Reader get", titleCase, "() {\n",
|
||||||
unionDiscrim.check,
|
unionDiscrim.check,
|
||||||
spaces(indent), " return ", type,
|
spaces(indent), " return ",
|
||||||
".factory.fromStructReader(_reader.getPointerField(", offset,").getStruct(", defaultParams, "));\n",
|
"_getPointerField(", offset,").getStruct(", type, ".factory,", defaultParams, ");\n",
|
||||||
spaces(indent), " }\n", "\n"),
|
spaces(indent), " }\n", "\n"),
|
||||||
|
|
||||||
kj::strTree(
|
kj::strTree(
|
||||||
kj::mv(unionDiscrim.builderIsDecl),
|
kj::mv(unionDiscrim.builderIsDecl),
|
||||||
spaces(indent), " public final ", type, ".Builder get", titleCase, "() {\n",
|
spaces(indent), " public final ", type, ".Builder get", titleCase, "() {\n",
|
||||||
unionDiscrim.check,
|
unionDiscrim.check,
|
||||||
spaces(indent), " return ", type,
|
spaces(indent), " return ",
|
||||||
".factory.fromStructBuilder(_builder.getPointerField(", offset, ").getStruct(",
|
"_getPointerField(", offset, ").getStruct(",
|
||||||
type, ".STRUCT_SIZE,", defaultParams, "));\n",
|
type, ".factory,", defaultParams,");\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final void set", titleCase, "(", type, ".Reader value) {\n",
|
spaces(indent), " public final void set", titleCase, "(", type, ".Reader value) {\n",
|
||||||
unionDiscrim.set,
|
unionDiscrim.set,
|
||||||
spaces(indent), " _builder.getPointerField(", offset, ").setStruct(value._reader);\n",
|
spaces(indent), " _getPointerField(", offset, ").setStruct(value);\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final ", type, ".Builder init", titleCase, "() {\n",
|
spaces(indent), " public final ", type, ".Builder init", titleCase, "() {\n",
|
||||||
unionDiscrim.set,
|
unionDiscrim.set,
|
||||||
spaces(indent), " return ",
|
spaces(indent), " return ",
|
||||||
type, ".factory.fromStructBuilder(_builder.getPointerField(", offset, ").initStruct(",
|
"_getPointerField(", offset, ").initStruct(",
|
||||||
type, ".STRUCT_SIZE", "));\n",
|
type, ".factory", ");\n",
|
||||||
spaces(indent), " }\n"),
|
spaces(indent), " }\n"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1016,12 +1019,12 @@ private:
|
||||||
kj::mv(unionDiscrim.readerIsDecl),
|
kj::mv(unionDiscrim.readerIsDecl),
|
||||||
spaces(indent), " public boolean has", titleCase, "() {\n",
|
spaces(indent), " public boolean has", titleCase, "() {\n",
|
||||||
unionDiscrim.has,
|
unionDiscrim.has,
|
||||||
spaces(indent), " return !_reader.getPointerField(", offset, ").isNull();\n",
|
spaces(indent), " return !_getPointerField(", offset, ").isNull();\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public ", type, ".Reader",
|
spaces(indent), " public ", type, ".Reader",
|
||||||
" get", titleCase, "() {\n",
|
" get", titleCase, "() {\n",
|
||||||
spaces(indent), " return _reader.getPointerField(",
|
spaces(indent), " return _getPointerField(",
|
||||||
offset, ").get", blobKind, "(", defaultParams, ");\n",
|
offset, ").get", blobKind, "(", defaultParams, ");\n",
|
||||||
spaces(indent), " }\n", "\n"),
|
spaces(indent), " }\n", "\n"),
|
||||||
|
|
||||||
|
@ -1029,24 +1032,24 @@ private:
|
||||||
kj::mv(unionDiscrim.builderIsDecl),
|
kj::mv(unionDiscrim.builderIsDecl),
|
||||||
spaces(indent), " public final boolean has", titleCase, "() {\n",
|
spaces(indent), " public final boolean has", titleCase, "() {\n",
|
||||||
unionDiscrim.has,
|
unionDiscrim.has,
|
||||||
spaces(indent), " return !_builder.getPointerField(", offset, ").isNull();\n",
|
spaces(indent), " return !_getPointerField(", offset, ").isNull();\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final ", type, ".Builder get", titleCase, "() {\n",
|
spaces(indent), " public final ", type, ".Builder get", titleCase, "() {\n",
|
||||||
spaces(indent), " return _builder.getPointerField(",
|
spaces(indent), " return _getPointerField(",
|
||||||
offset, ").get", blobKind, "(", defaultParams, ");\n",
|
offset, ").get", blobKind, "(", defaultParams, ");\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final void set", titleCase, "(", type, ".Reader value) {\n",
|
spaces(indent), " public final void set", titleCase, "(", type, ".Reader value) {\n",
|
||||||
unionDiscrim.set,
|
unionDiscrim.set,
|
||||||
spaces(indent), " _builder.getPointerField(", offset, ").set", blobKind, "(value);\n",
|
spaces(indent), " _getPointerField(", offset, ").set", blobKind, "(value);\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final void set", titleCase, "(", setterInputType, " value) {\n",
|
spaces(indent), " public final void set", titleCase, "(", setterInputType, " value) {\n",
|
||||||
unionDiscrim.set,
|
unionDiscrim.set,
|
||||||
spaces(indent), " _builder.getPointerField(", offset, ").set", blobKind, "( new",
|
spaces(indent), " _getPointerField(", offset, ").set", blobKind, "( new",
|
||||||
type, ".Reader(value));\n",
|
type, ".Reader(value));\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public final ", type, ".Builder init", titleCase, "(int size) {\n",
|
spaces(indent), " public final ", type, ".Builder init", titleCase, "(int size) {\n",
|
||||||
spaces(indent), " return _builder.getPointerField(", offset, ").init", blobKind, "(size);\n",
|
spaces(indent), " return _getPointerField(", offset, ").init", blobKind, "(size);\n",
|
||||||
spaces(indent), " }\n"),
|
spaces(indent), " }\n"),
|
||||||
};
|
};
|
||||||
} else if (kind == FieldKind::LIST) {
|
} else if (kind == FieldKind::LIST) {
|
||||||
|
@ -1063,12 +1066,12 @@ private:
|
||||||
kj::strTree(
|
kj::strTree(
|
||||||
kj::mv(unionDiscrim.readerIsDecl),
|
kj::mv(unionDiscrim.readerIsDecl),
|
||||||
spaces(indent), " public final boolean has", titleCase, "() {\n",
|
spaces(indent), " public final boolean has", titleCase, "() {\n",
|
||||||
spaces(indent), " return !_reader.getPointerField(", offset, ").isNull();\n",
|
spaces(indent), " return !_getPointerField(", offset, ").isNull();\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public final ", readerClass,
|
spaces(indent), " public final ", readerClass,
|
||||||
" get", titleCase, "() {\n",
|
" get", titleCase, "() {\n",
|
||||||
spaces(indent), " return (", listFactory, ").fromPointerReader(_reader.getPointerField(", offset, "),",
|
spaces(indent), " return (", listFactory, ").fromPointerReader(_getPointerField(", offset, "),",
|
||||||
defaultParams, ");\n",
|
defaultParams, ");\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
"\n"),
|
"\n"),
|
||||||
|
@ -1076,22 +1079,22 @@ private:
|
||||||
kj::strTree(
|
kj::strTree(
|
||||||
kj::mv(unionDiscrim.builderIsDecl),
|
kj::mv(unionDiscrim.builderIsDecl),
|
||||||
spaces(indent), " public final boolean has", titleCase, "() {\n",
|
spaces(indent), " public final boolean has", titleCase, "() {\n",
|
||||||
spaces(indent), " return !_builder.getPointerField(", offset, ").isNull();\n",
|
spaces(indent), " return !_getPointerField(", offset, ").isNull();\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public final ", builderClass,
|
spaces(indent), " public final ", builderClass,
|
||||||
" get", titleCase, "() {\n",
|
" get", titleCase, "() {\n",
|
||||||
spaces(indent), " return (", listFactory, ").fromPointerBuilder(_builder.getPointerField(", offset, "),",
|
spaces(indent), " return (", listFactory, ").fromPointerBuilder(_getPointerField(", offset, "),",
|
||||||
defaultParams, ");\n",
|
defaultParams, ");\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public final void set", titleCase, "(", readerClass, " value) {\n",
|
spaces(indent), " public final void set", titleCase, "(", readerClass, " value) {\n",
|
||||||
spaces(indent), " _builder.getPointerField(", offset, ").setList(value.reader);\n",
|
spaces(indent), " _getPointerField(", offset, ").setList(value.reader);\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " public final ", builderClass,
|
spaces(indent), " public final ", builderClass,
|
||||||
" init", titleCase, "(int size) {\n",
|
" init", titleCase, "(int size) {\n",
|
||||||
spaces(indent), " return (", listFactory, ").initFromPointerBuilder(_builder.getPointerField(", offset, "), size);\n",
|
spaces(indent), " return (", listFactory, ").initFromPointerBuilder(_getPointerField(", offset, "), size);\n",
|
||||||
spaces(indent), " }\n"),
|
spaces(indent), " }\n"),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
@ -1107,14 +1110,14 @@ private:
|
||||||
kj::StringTree inlineMethodDefs;
|
kj::StringTree inlineMethodDefs;
|
||||||
};
|
};
|
||||||
|
|
||||||
kj::StringTree makeWhich(StructSchema schema, kj::String member, int indent) {
|
kj::StringTree makeWhich(StructSchema schema, int indent) {
|
||||||
if (schema.getProto().getStruct().getDiscriminantCount() == 0) {
|
if (schema.getProto().getStruct().getDiscriminantCount() == 0) {
|
||||||
return kj::strTree();
|
return kj::strTree();
|
||||||
} else {
|
} else {
|
||||||
auto fields = schema.getUnionFields();
|
auto fields = schema.getUnionFields();
|
||||||
return kj::strTree(
|
return kj::strTree(
|
||||||
spaces(indent), "public Which which() {\n",
|
spaces(indent), "public Which which() {\n",
|
||||||
spaces(indent+1), "switch(", member, ".getShortField(",
|
spaces(indent+1), "switch(_getShortField(",
|
||||||
schema.getProto().getStruct().getDiscriminantOffset(), ")) {\n",
|
schema.getProto().getStruct().getDiscriminantOffset(), ")) {\n",
|
||||||
KJ_MAP(f, fields) {
|
KJ_MAP(f, fields) {
|
||||||
return kj::strTree(spaces(indent+2), "case ", f.getProto().getDiscriminantValue(), " : return ",
|
return kj::strTree(spaces(indent+2), "case ", f.getProto().getDiscriminantValue(), " : return ",
|
||||||
|
@ -1133,12 +1136,14 @@ private:
|
||||||
StructSchema schema, kj::Array<kj::StringTree>&& methodDecls,
|
StructSchema schema, kj::Array<kj::StringTree>&& methodDecls,
|
||||||
int indent) {
|
int indent) {
|
||||||
return kj::strTree(
|
return kj::strTree(
|
||||||
spaces(indent), "public static final class Reader {\n",
|
spaces(indent), "public static final class Reader extends org.capnproto.StructReader {\n",
|
||||||
spaces(indent), " public Reader(org.capnproto.StructReader base){ this._reader = base; }\n",
|
spaces(indent), " public Reader(org.capnproto.SegmentReader segment, int data, int pointers,",
|
||||||
|
"int dataSize, short pointerCount, byte bit0Offset, int nestingLimit){\n",
|
||||||
|
spaces(indent), " super(segment, data, pointers, dataSize, pointerCount, bit0Offset, nestingLimit);\n",
|
||||||
|
spaces(indent), " }\n",
|
||||||
"\n",
|
"\n",
|
||||||
makeWhich(schema, kj::str("_reader"), indent+1),
|
makeWhich(schema, indent+1),
|
||||||
kj::mv(methodDecls),
|
kj::mv(methodDecls),
|
||||||
spaces(indent), " public org.capnproto.StructReader _reader;\n",
|
|
||||||
spaces(indent), "}\n"
|
spaces(indent), "}\n"
|
||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
@ -1147,12 +1152,15 @@ private:
|
||||||
StructSchema schema, kj::Array<kj::StringTree>&& methodDecls,
|
StructSchema schema, kj::Array<kj::StringTree>&& methodDecls,
|
||||||
int indent) {
|
int indent) {
|
||||||
return kj::strTree(
|
return kj::strTree(
|
||||||
spaces(indent), "public static final class Builder {\n",
|
spaces(indent), "public static final class Builder extends org.capnproto.StructBuilder {\n",
|
||||||
spaces(indent), " public Builder(org.capnproto.StructBuilder base){ this._builder = base; }\n",
|
spaces(indent), " public Builder(org.capnproto.SegmentBuilder segment, int data, int pointers,",
|
||||||
spaces(indent), " public org.capnproto.StructBuilder _builder;\n",
|
"int dataSize, short pointerCount, byte bit0Offset){\n",
|
||||||
makeWhich(schema, kj::str("_builder"), indent+1),
|
spaces(indent), " super(segment, data, pointers, dataSize, pointerCount, bit0Offset);\n",
|
||||||
|
spaces(indent), " }\n",
|
||||||
|
makeWhich(schema, indent+1),
|
||||||
spaces(indent), " public final Reader asReader() {\n",
|
spaces(indent), " public final Reader asReader() {\n",
|
||||||
spaces(indent), " return new Reader(this._builder.asReader());\n",
|
spaces(indent), " return new Reader(segment, data, pointers, dataSize, pointerCount, bit0Offset, 0x7fffffff);\n",
|
||||||
|
//spaces(indent), " return new Reader(this._builder.asReader());\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
kj::mv(methodDecls),
|
kj::mv(methodDecls),
|
||||||
spaces(indent), "}\n",
|
spaces(indent), "}\n",
|
||||||
|
@ -1181,17 +1189,20 @@ private:
|
||||||
|
|
||||||
spaces(indent), " public static class Factory implements org.capnproto.StructFactory<Builder, Reader> {\n",
|
spaces(indent), " public static class Factory implements org.capnproto.StructFactory<Builder, Reader> {\n",
|
||||||
spaces(indent),
|
spaces(indent),
|
||||||
" public final Reader fromStructReader(org.capnproto.StructReader reader) {\n",
|
" public final Reader fromStructReader(org.capnproto.SegmentReader segment, int data,",
|
||||||
spaces(indent), " return new Reader(reader);\n",
|
"int pointers, int dataSize, short pointerCount, byte bit0Offset, int nestingLimit) {\n",
|
||||||
|
spaces(indent), " return new Reader(segment,data,pointers,dataSize,pointerCount,bit0Offset,nestingLimit);\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final Builder fromStructBuilder(org.capnproto.StructBuilder builder) {\n",
|
spaces(indent), " public final Builder fromStructBuilder(org.capnproto.SegmentBuilder segment, int data,",
|
||||||
spaces(indent), " return new Builder(builder);\n",
|
"int pointers, int dataSize, short pointerCount, byte bit0Offset) {\n",
|
||||||
|
spaces(indent), " return new Builder(segment, data, pointers, dataSize, pointerCount, bit0Offset);\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final org.capnproto.StructSize structSize() {\n",
|
spaces(indent), " public final org.capnproto.StructSize structSize() {\n",
|
||||||
spaces(indent), " return ", fullName, ".STRUCT_SIZE;\n",
|
spaces(indent), " return ", fullName, ".STRUCT_SIZE;\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
spaces(indent), " public final Reader asReader(Builder builder) {\n",
|
spaces(indent), " public final Reader asReader(Builder builder) {\n",
|
||||||
spaces(indent), " return new Reader(builder._builder.asReader());\n",
|
spaces(indent), " throw new Error();\n",
|
||||||
|
// spaces(indent), " return new Reader(builder._builder.asReader());\n",
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
||||||
spaces(indent), " }\n",
|
spaces(indent), " }\n",
|
||||||
|
|
|
@ -10,7 +10,7 @@ public final class AnyPointer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final <T> T getAsStruct(FromStructReader<T> factory) {
|
public final <T> T getAsStruct(FromStructReader<T> factory) {
|
||||||
return factory.fromStructReader(this.reader.getStruct());
|
return this.reader.getStruct(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final <T> T getAsList(FromPointerReader<T> factory) {
|
public final <T> T getAsList(FromPointerReader<T> factory) {
|
||||||
|
@ -26,7 +26,7 @@ public final class AnyPointer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final <T> T initAsStruct(FromStructBuilder<T> factory) {
|
public final <T> T initAsStruct(FromStructBuilder<T> factory) {
|
||||||
return factory.fromStructBuilder(this.builder.initStruct(factory.structSize()));
|
return this.builder.initStruct(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void clear() {
|
public final void clear() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public interface FromStructBuilder<T> {
|
public interface FromStructBuilder<T> {
|
||||||
T fromStructBuilder(StructBuilder builder);
|
T fromStructBuilder(SegmentBuilder segment, int data, int pointers, int dataSize,
|
||||||
|
short pointerCount, byte bit0Offset);
|
||||||
StructSize structSize();
|
StructSize structSize();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public interface FromStructReader<T> {
|
public interface FromStructReader<T> {
|
||||||
T fromStructReader(StructReader reader);
|
T fromStructReader(SegmentReader segment, int data, int pointers,
|
||||||
|
int dataSize, short pointerCount,
|
||||||
|
byte bit0Offset, int nestingLimit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,17 +85,17 @@ public final class ListBuilder {
|
||||||
this.segment.buffer.putDouble(this.ptr + index * 8, value);
|
this.segment.buffer.putDouble(this.ptr + index * 8, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final StructBuilder getStructElement(int index) {
|
public final <T> T getStructElement(FromStructBuilder<T> factory, int index) {
|
||||||
int indexBit = index * this.step;
|
int indexBit = index * this.step;
|
||||||
int structData = this.ptr + indexBit / 8 ;
|
int structData = this.ptr + indexBit / 8 ;
|
||||||
int structPointers = (structData + (this.structDataSize / 8)) / 8;
|
int structPointers = (structData + (this.structDataSize / 8)) / 8;
|
||||||
|
|
||||||
return new StructBuilder(this.segment,
|
return factory.fromStructBuilder(this.segment,
|
||||||
structData,
|
structData,
|
||||||
structPointers,
|
structPointers,
|
||||||
this.structDataSize,
|
this.structDataSize,
|
||||||
this.structPointerCount,
|
this.structPointerCount,
|
||||||
(byte)(indexBit % 8));
|
(byte)(indexBit % 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ public final class ListReader {
|
||||||
return this.segment.buffer.getDouble(this.ptr + index * 8);
|
return this.segment.buffer.getDouble(this.ptr + index * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructReader getStructElement(int index) {
|
public <T> T getStructElement(FromStructReader<T> factory, int index) {
|
||||||
// TODO check nesting limit
|
// TODO check nesting limit
|
||||||
|
|
||||||
int indexBit = index * this.step;
|
int indexBit = index * this.step;
|
||||||
|
@ -74,8 +74,8 @@ public final class ListReader {
|
||||||
int structData = this.ptr + (indexBit / 8);
|
int structData = this.ptr + (indexBit / 8);
|
||||||
int structPointers = structData + (this.structDataSize / 8);
|
int structPointers = structData + (this.structDataSize / 8);
|
||||||
|
|
||||||
return new StructReader(this.segment, structData, structPointers / 8, this.structDataSize,
|
return factory.fromStructReader(this.segment, structData, structPointers / 8, this.structDataSize,
|
||||||
this.structPointerCount, (byte) (indexBit % 8), this.nestingLimit - 1);
|
this.structPointerCount, (byte) (indexBit % 8), this.nestingLimit - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PointerReader getPointerElement(int index) {
|
public PointerReader getPointerElement(int index) {
|
||||||
|
|
|
@ -17,12 +17,14 @@ public final class PointerBuilder {
|
||||||
return this.segment.buffer.getLong(this.pointer) == 0;
|
return this.segment.buffer.getLong(this.pointer) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final StructBuilder getStruct(StructSize size) {
|
|
||||||
return WireHelpers.getWritableStructPointer(this.pointer, this.segment, size, null, 0);
|
public final <T> T getStruct(FromStructBuilder<T> factory) {
|
||||||
|
return WireHelpers.getWritableStructPointer(factory, this.pointer, this.segment, factory.structSize(), null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final StructBuilder getStruct(StructSize size, SegmentReader defaultBuffer, int defaultOffset) {
|
public final <T> T getStruct(FromStructBuilder<T> factory, SegmentReader defaultReader, int defaultOffset) {
|
||||||
return WireHelpers.getWritableStructPointer(this.pointer, this.segment, size, defaultBuffer, defaultOffset);
|
return WireHelpers.getWritableStructPointer(factory, this.pointer, this.segment, factory.structSize(),
|
||||||
|
defaultReader, defaultOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final ListBuilder getList(byte elementSize, SegmentReader defaultBuffer, int defaultOffset) {
|
public final ListBuilder getList(byte elementSize, SegmentReader defaultBuffer, int defaultOffset) {
|
||||||
|
@ -60,8 +62,8 @@ public final class PointerBuilder {
|
||||||
defaultSize);
|
defaultSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final StructBuilder initStruct(StructSize size) {
|
public final <T> T initStruct(FromStructBuilder<T> factory) {
|
||||||
return WireHelpers.initStructPointer(this.pointer, this.segment, size);
|
return WireHelpers.initStructPointer(factory, this.pointer, this.segment, factory.structSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public final ListBuilder initList(byte elementSize, int elementCount) {
|
public final ListBuilder initList(byte elementSize, int elementCount) {
|
||||||
|
|
|
@ -28,15 +28,17 @@ public final class PointerReader {
|
||||||
return this.segment.buffer.getLong(this.pointer) == 0;
|
return this.segment.buffer.getLong(this.pointer) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructReader getStruct() {
|
public <T> T getStruct(FromStructReader<T> factory) {
|
||||||
return WireHelpers.readStructPointer(this.segment,
|
return WireHelpers.readStructPointer(factory,
|
||||||
|
this.segment,
|
||||||
this.pointer,
|
this.pointer,
|
||||||
null, 0,
|
null, 0,
|
||||||
this.nestingLimit);
|
this.nestingLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructReader getStruct(SegmentReader defaultSegment, int defaultOffset) {
|
public <T> T getStruct(FromStructReader<T> factory, SegmentReader defaultSegment, int defaultOffset) {
|
||||||
return WireHelpers.readStructPointer(this.segment,
|
return WireHelpers.readStructPointer(factory,
|
||||||
|
this.segment,
|
||||||
this.pointer,
|
this.pointer,
|
||||||
defaultSegment, defaultOffset,
|
defaultSegment, defaultOffset,
|
||||||
this.nestingLimit);
|
this.nestingLimit);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class StructBuilder {
|
public class StructBuilder {
|
||||||
final SegmentBuilder segment;
|
protected final SegmentBuilder segment;
|
||||||
final int data; // byte offset to data section
|
protected final int data; // byte offset to data section
|
||||||
final int pointers; // word offset of pointer section
|
protected final int pointers; // word offset of pointer section
|
||||||
final int dataSize; // in bits
|
protected final int dataSize; // in bits
|
||||||
final short pointerCount;
|
protected final short pointerCount;
|
||||||
final byte bit0Offset;
|
protected final byte bit0Offset;
|
||||||
|
|
||||||
public StructBuilder(SegmentBuilder segment, int data,
|
public StructBuilder(SegmentBuilder segment, int data,
|
||||||
int pointers, int dataSize, short pointerCount,
|
int pointers, int dataSize, short pointerCount,
|
||||||
|
@ -19,24 +19,17 @@ public final class StructBuilder {
|
||||||
this.bit0Offset = bit0Offset;
|
this.bit0Offset = bit0Offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final StructReader asReader() {
|
public final boolean _getBooleanField(int offset) {
|
||||||
return new StructReader(this.segment,
|
|
||||||
this.data, this.pointers, this.dataSize,
|
|
||||||
this.pointerCount, this.bit0Offset,
|
|
||||||
0x7fffffff);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean getBooleanField(int offset) {
|
|
||||||
int bitOffset = (offset == 0 ? this.bit0Offset : offset);
|
int bitOffset = (offset == 0 ? this.bit0Offset : offset);
|
||||||
int position = this.data + (bitOffset / 8);
|
int position = this.data + (bitOffset / 8);
|
||||||
return (this.segment.buffer.get(position) & (1 << (bitOffset % 8))) != 0;
|
return (this.segment.buffer.get(position) & (1 << (bitOffset % 8))) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean getBooleanField(int offset, boolean mask) {
|
public final boolean getBooleanField(int offset, boolean mask) {
|
||||||
return this.getBooleanField(offset) ^ mask;
|
return this._getBooleanField(offset) ^ mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setBooleanField(int offset, boolean value) {
|
public final void _setBooleanField(int offset, boolean value) {
|
||||||
int bitOffset = offset;
|
int bitOffset = offset;
|
||||||
if (offset == 0) { bitOffset = this.bit0Offset; }
|
if (offset == 0) { bitOffset = this.bit0Offset; }
|
||||||
byte bitnum = (byte)(bitOffset % 8);
|
byte bitnum = (byte)(bitOffset % 8);
|
||||||
|
@ -46,111 +39,111 @@ public final class StructBuilder {
|
||||||
(byte)((oldValue & (~(1 << bitnum))) | (( value ? 1 : 0) << bitnum)));
|
(byte)((oldValue & (~(1 << bitnum))) | (( value ? 1 : 0) << bitnum)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setBooleanField(int offset, boolean value, boolean mask) {
|
public final void _setBooleanField(int offset, boolean value, boolean mask) {
|
||||||
this.setBooleanField(offset, value ^ mask);
|
this._setBooleanField(offset, value ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final byte getByteField(int offset) {
|
public final byte _getByteField(int offset) {
|
||||||
return this.segment.buffer.get(this.data + offset);
|
return this.segment.buffer.get(this.data + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final byte getByteField(int offset, byte mask) {
|
public final byte _getByteField(int offset, byte mask) {
|
||||||
return (byte)(this.getByteField(offset) ^ mask);
|
return (byte)(this._getByteField(offset) ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setByteField(int offset, byte value) {
|
public final void _setByteField(int offset, byte value) {
|
||||||
this.segment.buffer.put(this.data + offset, value);
|
this.segment.buffer.put(this.data + offset, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setByteField(int offset, byte value, byte mask) {
|
public final void _setByteField(int offset, byte value, byte mask) {
|
||||||
this.setByteField(offset, (byte) (value ^ mask));
|
this._setByteField(offset, (byte) (value ^ mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
public final short getShortField(int offset) {
|
public final short _getShortField(int offset) {
|
||||||
return this.segment.buffer.getShort(this.data + offset * 2);
|
return this.segment.buffer.getShort(this.data + offset * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final short getShortField(int offset, short mask) {
|
public final short _getShortField(int offset, short mask) {
|
||||||
return (short)(this.getShortField(offset) ^ mask);
|
return (short)(this._getShortField(offset) ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setShortField(int offset, short value) {
|
public final void _setShortField(int offset, short value) {
|
||||||
this.segment.buffer.putShort(this.data + offset * 2, value);
|
this.segment.buffer.putShort(this.data + offset * 2, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setShortField(int offset, short value, short mask) {
|
public final void _setShortField(int offset, short value, short mask) {
|
||||||
this.setShortField(offset, (short)(value ^ mask));
|
this._setShortField(offset, (short)(value ^ mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getIntField(int offset) {
|
public final int _getIntField(int offset) {
|
||||||
return this.segment.buffer.getInt(this.data + offset * 4);
|
return this.segment.buffer.getInt(this.data + offset * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getIntField(int offset, int mask) {
|
public final int _getIntField(int offset, int mask) {
|
||||||
return this.getIntField(offset) ^ mask;
|
return this._getIntField(offset) ^ mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setIntField(int offset, int value) {
|
public final void _setIntField(int offset, int value) {
|
||||||
this.segment.buffer.putInt(this.data + offset * 4, value);
|
this.segment.buffer.putInt(this.data + offset * 4, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setIntField(int offset, int value, int mask) {
|
public final void _setIntField(int offset, int value, int mask) {
|
||||||
this.setIntField(offset, value ^ mask);
|
this._setIntField(offset, value ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long getLongField(int offset) {
|
public final long _getLongField(int offset) {
|
||||||
return this.segment.buffer.getLong(this.data + offset * 8);
|
return this.segment.buffer.getLong(this.data + offset * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long getLongField(int offset, long mask) {
|
public final long _getLongField(int offset, long mask) {
|
||||||
return this.getLongField(offset) ^ mask;
|
return this._getLongField(offset) ^ mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setLongField(int offset, long value) {
|
public final void _setLongField(int offset, long value) {
|
||||||
this.segment.buffer.putLong(this.data + offset * 8, value);
|
this.segment.buffer.putLong(this.data + offset * 8, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setLongField(int offset, long value, long mask) {
|
public final void _setLongField(int offset, long value, long mask) {
|
||||||
this.setLongField(offset, value ^ mask);
|
this._setLongField(offset, value ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final float getFloatField(int offset) {
|
public final float _getFloatField(int offset) {
|
||||||
return this.segment.buffer.getFloat(this.data + offset * 4);
|
return this.segment.buffer.getFloat(this.data + offset * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final float getFloatField(int offset, int mask) {
|
public final float _getFloatField(int offset, int mask) {
|
||||||
return Float.intBitsToFloat(
|
return Float.intBitsToFloat(
|
||||||
this.segment.buffer.getInt(this.data + offset * 4) ^ mask);
|
this.segment.buffer.getInt(this.data + offset * 4) ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setFloatField(int offset, float value) {
|
public final void _setFloatField(int offset, float value) {
|
||||||
this.segment.buffer.putFloat(this.data + offset * 4, value);
|
this.segment.buffer.putFloat(this.data + offset * 4, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setFloatField(int offset, float value, int mask) {
|
public final void _setFloatField(int offset, float value, int mask) {
|
||||||
this.segment.buffer.putInt(this.data + offset * 4,
|
this.segment.buffer.putInt(this.data + offset * 4,
|
||||||
Float.floatToIntBits(value) ^ mask);
|
Float.floatToIntBits(value) ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final double getDoubleField(int offset) {
|
public final double _getDoubleField(int offset) {
|
||||||
return this.segment.buffer.getDouble(this.data + offset * 8);
|
return this.segment.buffer.getDouble(this.data + offset * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final double getDoubleField(int offset, long mask) {
|
public final double _getDoubleField(int offset, long mask) {
|
||||||
return Double.longBitsToDouble(
|
return Double.longBitsToDouble(
|
||||||
this.segment.buffer.getLong(this.data + offset * 8) ^ mask);
|
this.segment.buffer.getLong(this.data + offset * 8) ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setDoubleField(int offset, double value) {
|
public final void _setDoubleField(int offset, double value) {
|
||||||
this.segment.buffer.putDouble(this.data + offset * 8, value);
|
this.segment.buffer.putDouble(this.data + offset * 8, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setDoubleField(int offset, double value, long mask) {
|
public final void _setDoubleField(int offset, double value, long mask) {
|
||||||
this.segment.buffer.putLong(this.data + offset * 8,
|
this.segment.buffer.putLong(this.data + offset * 8,
|
||||||
Double.doubleToLongBits(value) ^ mask);
|
Double.doubleToLongBits(value) ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final PointerBuilder getPointerField(int index) {
|
public final PointerBuilder _getPointerField(int index) {
|
||||||
return new PointerBuilder(this.segment, this.pointers + index);
|
return new PointerBuilder(this.segment, this.pointers + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public final class StructList {
|
||||||
}
|
}
|
||||||
|
|
||||||
public T get(int index) {
|
public T get(int index) {
|
||||||
return this.factory.fromStructReader(this.reader.getStructElement(index));
|
return this.reader.getStructElement(factory, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public final class StructList {
|
||||||
}
|
}
|
||||||
|
|
||||||
public T next() {
|
public T next() {
|
||||||
return list.factory.fromStructReader(list.reader.getStructElement(idx++));
|
return list.reader.getStructElement(factory, idx++);
|
||||||
}
|
}
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return idx < list.size();
|
return idx < list.size();
|
||||||
|
@ -84,7 +84,7 @@ public final class StructList {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final T get(int index) {
|
public final T get(int index) {
|
||||||
return this.factory.fromStructBuilder(this.builder.getStructElement(index));
|
return this.builder.getStructElement(factory, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public final class StructList {
|
||||||
}
|
}
|
||||||
|
|
||||||
public T next() {
|
public T next() {
|
||||||
return list.factory.fromStructBuilder(list.builder.getStructElement(idx++));
|
return list.builder.getStructElement(factory, idx++);
|
||||||
}
|
}
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return idx < list.size();
|
return idx < list.size();
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class StructReader {
|
|
||||||
final SegmentReader segment;
|
public class StructReader {
|
||||||
final int data; //byte offset to data section
|
protected final SegmentReader segment;
|
||||||
final int pointers; // word offset of pointer section
|
protected final int data; //byte offset to data section
|
||||||
final int dataSize; // in bits
|
protected final int pointers; // word offset of pointer section
|
||||||
final short pointerCount;
|
protected final int dataSize; // in bits
|
||||||
final byte bit0Offset;
|
protected final short pointerCount;
|
||||||
final int nestingLimit;
|
protected final byte bit0Offset;
|
||||||
|
protected final int nestingLimit;
|
||||||
|
|
||||||
public StructReader() {
|
public StructReader() {
|
||||||
this.segment = SegmentReader.EMPTY;
|
this.segment = SegmentReader.EMPTY;
|
||||||
|
@ -31,7 +32,7 @@ public final class StructReader {
|
||||||
this.nestingLimit = nestingLimit;
|
this.nestingLimit = nestingLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean getBooleanField(int offset) {
|
public final boolean _getBooleanField(int offset) {
|
||||||
// XXX should use unsigned operations
|
// XXX should use unsigned operations
|
||||||
if (offset < this.dataSize) {
|
if (offset < this.dataSize) {
|
||||||
if (offset == 0) {
|
if (offset == 0) {
|
||||||
|
@ -45,11 +46,11 @@ public final class StructReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean getBooleanField(int offset, boolean mask) {
|
public final boolean _getBooleanField(int offset, boolean mask) {
|
||||||
return this.getBooleanField(offset) ^ mask;
|
return this._getBooleanField(offset) ^ mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final byte getByteField(int offset) {
|
public final byte _getByteField(int offset) {
|
||||||
if ((offset + 1) * 8 <= this.dataSize) {
|
if ((offset + 1) * 8 <= this.dataSize) {
|
||||||
return this.segment.buffer.get(this.data + offset);
|
return this.segment.buffer.get(this.data + offset);
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,11 +58,11 @@ public final class StructReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final byte getByteField(int offset, byte mask) {
|
public final byte _getByteField(int offset, byte mask) {
|
||||||
return (byte)(this.getByteField(offset) ^ mask);
|
return (byte)(this._getByteField(offset) ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final short getShortField(int offset) {
|
public final short _getShortField(int offset) {
|
||||||
if ((offset + 1) * 16 <= this.dataSize) {
|
if ((offset + 1) * 16 <= this.dataSize) {
|
||||||
return this.segment.buffer.getShort(this.data + offset * 2);
|
return this.segment.buffer.getShort(this.data + offset * 2);
|
||||||
} else {
|
} else {
|
||||||
|
@ -69,11 +70,11 @@ public final class StructReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final short getShortField(int offset, short mask) {
|
public final short _getShortField(int offset, short mask) {
|
||||||
return (short)(this.getShortField(offset) ^ mask);
|
return (short)(this._getShortField(offset) ^ mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getIntField(int offset) {
|
public final int _getIntField(int offset) {
|
||||||
if ((offset + 1) * 32 <= this.dataSize) {
|
if ((offset + 1) * 32 <= this.dataSize) {
|
||||||
return this.segment.buffer.getInt(this.data + offset * 4);
|
return this.segment.buffer.getInt(this.data + offset * 4);
|
||||||
} else {
|
} else {
|
||||||
|
@ -81,11 +82,11 @@ public final class StructReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getIntField(int offset, int mask) {
|
public final int _getIntField(int offset, int mask) {
|
||||||
return this.getIntField(offset) ^ mask;
|
return this._getIntField(offset) ^ mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long getLongField(int offset) {
|
public final long _getLongField(int offset) {
|
||||||
if ((offset + 1) * 64 <= this.dataSize) {
|
if ((offset + 1) * 64 <= this.dataSize) {
|
||||||
return this.segment.buffer.getLong(this.data + offset * 8);
|
return this.segment.buffer.getLong(this.data + offset * 8);
|
||||||
} else {
|
} else {
|
||||||
|
@ -93,11 +94,11 @@ public final class StructReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long getLongField(int offset, long mask) {
|
public final long _getLongField(int offset, long mask) {
|
||||||
return this.getLongField(offset) ^ mask;
|
return this._getLongField(offset) ^ mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final float getFloatField(int offset) {
|
public final float _getFloatField(int offset) {
|
||||||
if ((offset + 1) * 32 <= this.dataSize) {
|
if ((offset + 1) * 32 <= this.dataSize) {
|
||||||
return this.segment.buffer.getFloat(this.data + offset * 4);
|
return this.segment.buffer.getFloat(this.data + offset * 4);
|
||||||
} else {
|
} else {
|
||||||
|
@ -105,7 +106,7 @@ public final class StructReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final float getFloatField(int offset, int mask) {
|
public final float _getFloatField(int offset, int mask) {
|
||||||
if ((offset + 1) * 32 <= this.dataSize) {
|
if ((offset + 1) * 32 <= this.dataSize) {
|
||||||
return Float.intBitsToFloat(this.segment.buffer.getInt(this.data + offset * 4) ^ mask);
|
return Float.intBitsToFloat(this.segment.buffer.getInt(this.data + offset * 4) ^ mask);
|
||||||
} else {
|
} else {
|
||||||
|
@ -113,7 +114,7 @@ public final class StructReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final double getDoubleField(int offset) {
|
public final double _getDoubleField(int offset) {
|
||||||
if ((offset + 1) * 64 <= this.dataSize) {
|
if ((offset + 1) * 64 <= this.dataSize) {
|
||||||
return this.segment.buffer.getDouble(this.data + offset * 8);
|
return this.segment.buffer.getDouble(this.data + offset * 8);
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,7 +122,7 @@ public final class StructReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final double getDoubleField(int offset, long mask) {
|
public final double _getDoubleField(int offset, long mask) {
|
||||||
if ((offset + 1) * 64 <= this.dataSize) {
|
if ((offset + 1) * 64 <= this.dataSize) {
|
||||||
return Double.longBitsToDouble(this.segment.buffer.getLong(this.data + offset * 8) ^ mask);
|
return Double.longBitsToDouble(this.segment.buffer.getLong(this.data + offset * 8) ^ mask);
|
||||||
} else {
|
} else {
|
||||||
|
@ -129,7 +130,7 @@ public final class StructReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final PointerReader getPointerField(int ptrIndex) {
|
public final PointerReader _getPointerField(int ptrIndex) {
|
||||||
if (ptrIndex < this.pointerCount) {
|
if (ptrIndex < this.pointerCount) {
|
||||||
return new PointerReader(this.segment,
|
return new PointerReader(this.segment,
|
||||||
this.pointers + ptrIndex,
|
this.pointers + ptrIndex,
|
||||||
|
|
|
@ -145,26 +145,29 @@ final class WireHelpers {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
static StructBuilder initStructPointer(int refOffset,
|
|
||||||
SegmentBuilder segment,
|
static <T> T initStructPointer(FromStructBuilder<T> factory,
|
||||||
StructSize size) {
|
int refOffset,
|
||||||
|
SegmentBuilder segment,
|
||||||
|
StructSize size) {
|
||||||
AllocateResult allocation = allocate(refOffset, segment, size.total(), WirePointer.STRUCT);
|
AllocateResult allocation = allocate(refOffset, segment, size.total(), WirePointer.STRUCT);
|
||||||
StructPointer.setFromStructSize(allocation.segment.buffer, allocation.refOffset, size);
|
StructPointer.setFromStructSize(allocation.segment.buffer, allocation.refOffset, size);
|
||||||
return new StructBuilder(allocation.segment, allocation.ptr * Constants.BYTES_PER_WORD,
|
return factory.fromStructBuilder(allocation.segment, allocation.ptr * Constants.BYTES_PER_WORD,
|
||||||
allocation.ptr + size.data,
|
allocation.ptr + size.data,
|
||||||
size.data * 64, size.pointers, (byte)0);
|
size.data * 64, size.pointers, (byte)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static StructBuilder getWritableStructPointer(int refOffset,
|
static <T> T getWritableStructPointer(FromStructBuilder<T> factory,
|
||||||
SegmentBuilder segment,
|
int refOffset,
|
||||||
StructSize size,
|
SegmentBuilder segment,
|
||||||
SegmentReader defaultSegment,
|
StructSize size,
|
||||||
int defaultOffset) {
|
SegmentReader defaultSegment,
|
||||||
|
int defaultOffset) {
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
int target = WirePointer.target(refOffset, ref);
|
int target = WirePointer.target(refOffset, ref);
|
||||||
if (WirePointer.isNull(ref)) {
|
if (WirePointer.isNull(ref)) {
|
||||||
if (defaultSegment == null) {
|
if (defaultSegment == null) {
|
||||||
return initStructPointer(refOffset, segment, size);
|
return initStructPointer(factory, refOffset, segment, size);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("unimplemented");
|
throw new Error("unimplemented");
|
||||||
}
|
}
|
||||||
|
@ -178,9 +181,9 @@ final class WireHelpers {
|
||||||
if (oldDataSize < size.data || oldPointerCount < size.pointers) {
|
if (oldDataSize < size.data || oldPointerCount < size.pointers) {
|
||||||
throw new Error("unimplemented");
|
throw new Error("unimplemented");
|
||||||
} else {
|
} else {
|
||||||
return new StructBuilder(resolved.segment, resolved.ptr * Constants.BYTES_PER_WORD,
|
return factory.fromStructBuilder(resolved.segment, resolved.ptr * Constants.BYTES_PER_WORD,
|
||||||
oldPointerSectionOffset, oldDataSize * Constants.BITS_PER_WORD,
|
oldPointerSectionOffset, oldDataSize * Constants.BITS_PER_WORD,
|
||||||
oldPointerCount, (byte)0);
|
oldPointerCount, (byte)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -417,17 +420,18 @@ final class WireHelpers {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static StructReader readStructPointer(SegmentReader segment,
|
static <T> T readStructPointer(FromStructReader<T> factory,
|
||||||
int refOffset,
|
SegmentReader segment,
|
||||||
SegmentReader defaultSegment,
|
int refOffset,
|
||||||
int defaultOffset,
|
SegmentReader defaultSegment,
|
||||||
int nestingLimit) {
|
int defaultOffset,
|
||||||
|
int nestingLimit) {
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
if (WirePointer.isNull(ref)) {
|
if (WirePointer.isNull(ref)) {
|
||||||
if (defaultSegment == null) {
|
if (defaultSegment == null) {
|
||||||
return new StructReader();
|
throw new Error();//return new StructReader();
|
||||||
} else {
|
} else {
|
||||||
return (new PointerReader(defaultSegment, defaultOffset, 0x7fffffff)).getStruct();
|
return (new PointerReader(defaultSegment, defaultOffset, 0x7fffffff)).getStruct(factory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +440,6 @@ final class WireHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int refTarget = WirePointer.target(refOffset, ref);
|
int refTarget = WirePointer.target(refOffset, ref);
|
||||||
FollowFarsResult resolved = followFars(ref, refTarget, segment);
|
FollowFarsResult resolved = followFars(ref, refTarget, segment);
|
||||||
|
|
||||||
|
@ -448,13 +451,13 @@ final class WireHelpers {
|
||||||
|
|
||||||
// TODO "bounds_check" (read limiting)
|
// TODO "bounds_check" (read limiting)
|
||||||
|
|
||||||
return new StructReader(resolved.segment,
|
return factory.fromStructReader(resolved.segment,
|
||||||
resolved.ptr * Constants.BYTES_PER_WORD,
|
resolved.ptr * Constants.BYTES_PER_WORD,
|
||||||
(resolved.ptr + dataSizeWords),
|
(resolved.ptr + dataSizeWords),
|
||||||
dataSizeWords * Constants.BITS_PER_WORD,
|
dataSizeWords * Constants.BITS_PER_WORD,
|
||||||
StructPointer.ptrCount(resolved.ref),
|
StructPointer.ptrCount(resolved.ref),
|
||||||
(byte)0,
|
(byte)0,
|
||||||
nestingLimit - 1);
|
nestingLimit - 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue