expose schema bytes as read-only ByteBuffer, not byte[]

This commit is contained in:
David Renshaw 2014-10-02 08:46:36 -04:00
parent 32d2a7bbda
commit 2ed3f5f76c
2 changed files with 4 additions and 3 deletions

View file

@ -1553,7 +1553,8 @@ private:
// Java limits method code size to 64KB. Maybe we should use class.getResource()?
auto schemaDef = kj::strTree(
"public static final byte[] b_", hexId, " = org.capnproto.GeneratedClassSupport.decodeRawBytes(\n",
"public static final java.nio.ByteBuffer b_", hexId, " =\n",
" org.capnproto.GeneratedClassSupport.decodeRawBytes(\n",
" ", kj::mv(schemaLiteral), " \"\"",
");\n");
/*

View file

@ -1,9 +1,9 @@
package org.capnproto;
public final class GeneratedClassSupport {
public static byte[] decodeRawBytes(String s) {
public static java.nio.ByteBuffer decodeRawBytes(String s) {
try {
return s.getBytes("ISO_8859-1");
return java.nio.ByteBuffer.wrap(s.getBytes("ISO_8859-1")).asReadOnlyBuffer();
} catch (Exception e) {
throw new Error("could not decode raw bytes from String");
}