diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index c10da83..d6d6fbd 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -1464,10 +1464,24 @@ private: auto schemaLiteral = kj::StringTree(KJ_MAP(w, rawSchema) { const byte* bytes = reinterpret_cast(&w); - return kj::strTree(KJ_MAP(i, kj::range(0, sizeof(word))) { - auto text = kj::toCharSequence(kj::implicitCast(bytes[i])); - return kj::strTree(kj::repeat(' ', 4 - text.size()), text, ","); - }); + return kj::strTree( + "\"", + KJ_MAP(i, kj::range(0, sizeof(word))) { + switch(bytes[i]) { + case 0x0a: + return kj::strTree("\\n"); + case 0x0d: + return kj::strTree("\\r"); + case 0x22: + return kj::strTree("\\\""); + case 0x5c: + return kj::strTree("\\\\"); + default: + auto text = kj::hex(bytes[i]); + return kj::strTree("\\u", kj::repeat('0', 4 - text.size()), text); + } + }, + "\" +"); }, "\n "); std::set deps; @@ -1501,10 +1515,9 @@ private: // Java limits method code size to 64KB. Maybe we should use class.getResource()? auto schemaDef = kj::strTree( - "public static final class b_", hexId, " {\n", - " public static final byte[] bytes =\n", - " {", kj::mv(schemaLiteral), " };\n", - "}\n"); + "public static final byte[] b_", hexId, " = org.capnproto.GeneratedClassSupport.decodeRawBytes(\n", + " ", kj::mv(schemaLiteral), " \"\"", + ");\n"); /* deps.size() == 0 ? kj::strTree() : kj::strTree( "static const ::capnp::_::RawSchema* const d_", hexId, "[] = {\n", @@ -1708,9 +1721,9 @@ private: "public final class ", outerClassname, " {\n", KJ_MAP(n, nodeTexts) { return kj::mv(n.outerTypeDef); }, "\n", - //"public static final class Schemas {\n", - //KJ_MAP(n, nodeTexts) { return kj::mv(n.capnpSchemaDefs); }, - //"}\n", + "public static final class Schemas {\n", + KJ_MAP(n, nodeTexts) { return kj::mv(n.capnpSchemaDefs); }, + "}\n", "}\n", "\n") };