basic support for struct constants. still broken
This commit is contained in:
parent
ed7a16e4dc
commit
95d0898c3f
6 changed files with 60 additions and 13 deletions
|
@ -978,7 +978,7 @@ private:
|
||||||
|
|
||||||
uint64_t typeId = field.getContainingStruct().getProto().getId();
|
uint64_t typeId = field.getContainingStruct().getProto().getId();
|
||||||
kj::String defaultParams = defaultOffset == 0 ? kj::str() : kj::str(
|
kj::String defaultParams = defaultOffset == 0 ? kj::str() : kj::str(
|
||||||
"Schemas.b_", kj::hex(typeId), ", ", defaultOffset * 8, ", ", defaultSize);
|
"Schemas.b_", kj::hex(typeId), ".buffer, ", defaultOffset * 8, ", ", defaultSize);
|
||||||
|
|
||||||
kj::String blobKind = typeBody.which() == schema::Type::TEXT ? kj::str("Text") : kj::str("Data");
|
kj::String blobKind = typeBody.which() == schema::Type::TEXT ? kj::str("Text") : kj::str("Data");
|
||||||
kj::String setterInputType = typeBody.which() == schema::Type::TEXT ? kj::str("String") : kj::str("byte []");
|
kj::String setterInputType = typeBody.which() == schema::Type::TEXT ? kj::str("String") : kj::str("byte []");
|
||||||
|
@ -1343,7 +1343,7 @@ private:
|
||||||
kj::strTree(spaces(indent),
|
kj::strTree(spaces(indent),
|
||||||
"public static final org.capnproto.Text.Reader ", upperCase,
|
"public static final org.capnproto.Text.Reader ", upperCase,
|
||||||
" = new org.capnproto.Text.Reader(Schemas.b_",
|
" = new org.capnproto.Text.Reader(Schemas.b_",
|
||||||
kj::hex(proto.getId()), ", ", schema.getValueSchemaOffset(),
|
kj::hex(proto.getId()), ".buffer, ", schema.getValueSchemaOffset(),
|
||||||
", ", constProto.getValue().getText().size(), ");\n")
|
", ", constProto.getValue().getText().size(), ");\n")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1354,18 +1354,18 @@ private:
|
||||||
kj::strTree(spaces(indent),
|
kj::strTree(spaces(indent),
|
||||||
"public static final org.capnproto.Data.Reader ", upperCase,
|
"public static final org.capnproto.Data.Reader ", upperCase,
|
||||||
" = new org.capnproto.Data.Reader(Schemas.b_",
|
" = new org.capnproto.Data.Reader(Schemas.b_",
|
||||||
kj::hex(proto.getId()), ", ", schema.getValueSchemaOffset(),
|
kj::hex(proto.getId()), ".buffer, ", schema.getValueSchemaOffset(),
|
||||||
", ", constProto.getValue().getData().size(), ");\n")
|
", ", constProto.getValue().getData().size(), ");\n")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case schema::Value::STRUCT: {
|
case schema::Value::STRUCT: {
|
||||||
kj::String constType = kj::strTree(
|
|
||||||
"::capnp::_::ConstStruct<", typeName_, ">").flatten();
|
|
||||||
return ConstText {
|
return ConstText {
|
||||||
true,
|
true,
|
||||||
kj::strTree("const ", constType, ' ', scope, upperCase, "(::capnp::schemas::b_",
|
kj::strTree(spaces(indent),
|
||||||
kj::hex(proto.getId()), ".words + ", schema.getValueSchemaOffset(), ");\n")
|
"public static final ", typeName_, ".Reader ", upperCase, "=\n",
|
||||||
|
spaces(indent), " new ", typeName_, ".Reader((new org.capnproto.PointerReader(Schemas.b_",
|
||||||
|
kj::hex(proto.getId()), ",", schema.getValueSchemaOffset(), ",0x7fffffff)).getStruct());\n")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1490,7 +1490,7 @@ private:
|
||||||
|
|
||||||
// Java limits method code size to 64KB. Maybe we should use class.getResource()?
|
// Java limits method code size to 64KB. Maybe we should use class.getResource()?
|
||||||
auto schemaDef = kj::strTree(
|
auto schemaDef = kj::strTree(
|
||||||
"public static final java.nio.ByteBuffer b_", hexId, " =\n",
|
"public static final org.capnproto.SegmentReader b_", hexId, " =\n",
|
||||||
" org.capnproto.GeneratedClassSupport.decodeRawBytes(\n",
|
" org.capnproto.GeneratedClassSupport.decodeRawBytes(\n",
|
||||||
" ", kj::mv(schemaLiteral), " \"\"",
|
" ", kj::mv(schemaLiteral), " \"\"",
|
||||||
");\n");
|
");\n");
|
||||||
|
|
|
@ -140,6 +140,11 @@ class EncodingSuite extends FunSuite {
|
||||||
(TestConstants.DATA_CONST.toArray()) should equal (TestUtil.data("bar"));
|
(TestConstants.DATA_CONST.toArray()) should equal (TestUtil.data("bar"));
|
||||||
|
|
||||||
(TestConstants.ENUM_CONST) should equal (TestEnum.CORGE);
|
(TestConstants.ENUM_CONST) should equal (TestEnum.CORGE);
|
||||||
|
{
|
||||||
|
val subReader = TestConstants.STRUCT_CONST;
|
||||||
|
//subReader.getBoolField() should equal (true);
|
||||||
|
//subReader.getInt8Field() should equal (-12);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,6 +270,48 @@ struct TestConstants {
|
||||||
const float64Const :Float64 = -123e45;
|
const float64Const :Float64 = -123e45;
|
||||||
const textConst :Text = "foo";
|
const textConst :Text = "foo";
|
||||||
const dataConst :Data = "bar";
|
const dataConst :Data = "bar";
|
||||||
|
const structConst :TestAllTypes = (
|
||||||
|
voidField = void,
|
||||||
|
boolField = true,
|
||||||
|
int8Field = -12,
|
||||||
|
int16Field = 3456,
|
||||||
|
int32Field = -78901234,
|
||||||
|
int64Field = 56789012345678,
|
||||||
|
uInt8Field = 90,
|
||||||
|
uInt16Field = 1234,
|
||||||
|
uInt32Field = 56789012,
|
||||||
|
uInt64Field = 345678901234567890,
|
||||||
|
float32Field = -1.25e-10,
|
||||||
|
float64Field = 345,
|
||||||
|
textField = "baz",
|
||||||
|
dataField = "qux",
|
||||||
|
structField = (
|
||||||
|
textField = "nested",
|
||||||
|
structField = (textField = "really nested")),
|
||||||
|
enumField = baz,
|
||||||
|
# interfaceField can't have a default
|
||||||
|
|
||||||
|
voidList = [void, void, void],
|
||||||
|
boolList = [false, true, false, true, true],
|
||||||
|
int8List = [12, -34, -0x80, 0x7f],
|
||||||
|
int16List = [1234, -5678, -0x8000, 0x7fff],
|
||||||
|
int32List = [12345678, -90123456, -0x80000000, 0x7fffffff],
|
||||||
|
int64List = [123456789012345, -678901234567890, -0x8000000000000000, 0x7fffffffffffffff],
|
||||||
|
uInt8List = [12, 34, 0, 0xff],
|
||||||
|
uInt16List = [1234, 5678, 0, 0xffff],
|
||||||
|
uInt32List = [12345678, 90123456, 0, 0xffffffff],
|
||||||
|
uInt64List = [123456789012345, 678901234567890, 0, 0xffffffffffffffff],
|
||||||
|
float32List = [0, 1234567, 1e37, -1e37, 1e-37, -1e-37],
|
||||||
|
float64List = [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306],
|
||||||
|
textList = ["quux", "corge", "grault"],
|
||||||
|
dataList = ["garply", "waldo", "fred"],
|
||||||
|
structList = [
|
||||||
|
(textField = "x structlist 1"),
|
||||||
|
(textField = "x structlist 2"),
|
||||||
|
(textField = "x structlist 3")],
|
||||||
|
enumList = [qux, bar, grault]
|
||||||
|
# interfaceList can't have a default
|
||||||
|
);
|
||||||
# ...
|
# ...
|
||||||
const enumConst :TestEnum = corge;
|
const enumConst :TestEnum = corge;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class GeneratedClassSupport {
|
public final class GeneratedClassSupport {
|
||||||
public static java.nio.ByteBuffer decodeRawBytes(String s) {
|
public static SegmentReader decodeRawBytes(String s) {
|
||||||
try {
|
try {
|
||||||
return java.nio.ByteBuffer.wrap(s.getBytes("ISO_8859-1")).asReadOnlyBuffer();
|
return new SegmentReader(java.nio.ByteBuffer.wrap(s.getBytes("ISO_8859-1")).asReadOnlyBuffer(), null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new Error("could not decode raw bytes from String");
|
throw new Error("could not decode raw bytes from String");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ public final class PointerReader {
|
||||||
final int nestingLimit;
|
final int nestingLimit;
|
||||||
|
|
||||||
public PointerReader() {
|
public PointerReader() {
|
||||||
this.segment = null;
|
this.segment = SegmentReader.EMPTY;
|
||||||
this.pointer = 0; // XXX ?
|
this.pointer = 0;
|
||||||
this.nestingLimit = 0x7fffffff;
|
this.nestingLimit = 0x7fffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class SegmentReader {
|
public class SegmentReader {
|
||||||
|
|
||||||
final ByteBuffer buffer;
|
public final ByteBuffer buffer;
|
||||||
final Arena arena;
|
final Arena arena;
|
||||||
|
|
||||||
public SegmentReader(ByteBuffer buffer, Arena arena) {
|
public SegmentReader(ByteBuffer buffer, Arena arena) {
|
||||||
|
|
Loading…
Reference in a new issue