com.google.protobuf.nano.CodedInputByteBufferNano Java Examples
The following examples show how to use
com.google.protobuf.nano.CodedInputByteBufferNano.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NanoUtils.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Override public T parse(InputStream stream) { try { // TODO(simonma): Investigate whether we can do 0-copy here. CodedInputByteBufferNano input = CodedInputByteBufferNano.newInstance(toByteArray(stream)); input.setSizeLimit(Integer.MAX_VALUE); T message = factory.newInstance(); message.mergeFrom(input); return message; } catch (IOException ipbe) { throw Status.INTERNAL.withDescription("Failed parsing nano proto message").withCause(ipbe) .asRuntimeException(); } }
Example #2
Source File: ProtoUtilsTest.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@Test public void testWriteToFile() throws Exception { final SettingsProto.Settings message = new SettingsProto.Settings(); message.scrobbleEnabled = true; message.theme = 666; final String fileName = "protoUtilsWriteToFile"; final Context context = RuntimeEnvironment.application; // Delete old copies context.deleteFile(fileName); // Write actual file ProtoUtils.writeToFile(context, fileName, message); // Read final InputStream is = context.openFileInput(fileName); final byte[] readBytes = ByteStreams.toByteArray(is); assertNotNull(readBytes); // Create from read final SettingsProto.Settings read = new SettingsProto.Settings() .mergeFrom(CodedInputByteBufferNano.newInstance(readBytes)); // compare assertEquals(message.scrobbleEnabled, read.scrobbleEnabled); assertEquals(message.theme, read.theme); }