From 2ed3f5f76c0111ca0cb4c3aeb87925ed08759930 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Thu, 2 Oct 2014 08:46:36 -0400 Subject: [PATCH] expose schema bytes as read-only ByteBuffer, not byte[] --- compiler/src/main/cpp/capnpc-java.c++ | 3 ++- .../src/main/java/org/capnproto/GeneratedClassSupport.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index c6abe58..4997e03 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -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"); /* diff --git a/runtime/src/main/java/org/capnproto/GeneratedClassSupport.java b/runtime/src/main/java/org/capnproto/GeneratedClassSupport.java index e8a6624..7def2ba 100644 --- a/runtime/src/main/java/org/capnproto/GeneratedClassSupport.java +++ b/runtime/src/main/java/org/capnproto/GeneratedClassSupport.java @@ -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"); }