Java 类com.google.protobuf.nano.CodedInputByteBufferNano 实例源码

项目:FMTech    文件:ParcelableProto.java   
private static ParcelableProto<MessageNano> createFromParcel(Parcel paramAnonymousParcel)
{
  int i = paramAnonymousParcel.readInt();
  if (i == -1) {
    return new ParcelableProto(null, (byte)0);
  }
  byte[] arrayOfByte = new byte[i];
  paramAnonymousParcel.readByteArray(arrayOfByte);
  String str = paramAnonymousParcel.readString();
  try
  {
    MessageNano localMessageNano = (MessageNano)Class.forName(str).getConstructor(null).newInstance(null);
    localMessageNano.mergeFrom(CodedInputByteBufferNano.newInstance(arrayOfByte, 0, i));
    ParcelableProto localParcelableProto = new ParcelableProto(localMessageNano, (byte)0);
    return localParcelableProto;
  }
  catch (Exception localException)
  {
    throw new IllegalArgumentException("Exception when unmarshalling: " + str, localException);
  }
}
项目:FMTech    文件:ParcelableProto.java   
private static ParcelableProto<MessageNano> createFromParcel(Parcel paramAnonymousParcel)
{
  int i = paramAnonymousParcel.readInt();
  if (i == -1) {
    return new ParcelableProto(null, (byte)0);
  }
  byte[] arrayOfByte = new byte[i];
  paramAnonymousParcel.readByteArray(arrayOfByte);
  String str = paramAnonymousParcel.readString();
  try
  {
    MessageNano localMessageNano = (MessageNano)Class.forName(str).getConstructor(null).newInstance(null);
    localMessageNano.mergeFrom(CodedInputByteBufferNano.newInstance(arrayOfByte, 0, i));
    ParcelableProto localParcelableProto = new ParcelableProto(localMessageNano, (byte)0);
    return localParcelableProto;
  }
  catch (Exception localException)
  {
    throw new IllegalArgumentException("Exception when unmarshalling: " + str, localException);
  }
}
项目:PainlessMusicPlayer    文件:ProtoUtilsTest.java   
@Test
public void testWriteToFile() throws Exception {
    final WearPlaybackData.PlaybackPosition message = new WearPlaybackData.PlaybackPosition();
    message.mediaId = 666L;
    message.position = 128;

    final String fileName = "protoUtilsWriteToFile";

    final Context context = InstrumentationRegistry.getContext();

    // 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 WearPlaybackData.PlaybackPosition read = new WearPlaybackData.PlaybackPosition()
            .mergeFrom(CodedInputByteBufferNano.newInstance(readBytes));

    // compare
    assertEquals(message.mediaId, read.mediaId);
    assertEquals(message.position, read.position);
}
项目:flatbuffers-java-benchmark    文件:ProtoNanoBench.java   
public ProtoNanoBench() {
    // Somehow there is an issue with deserializing data that has been
    // serialized with nano. It throws an exception about an invalid tag zero.
    // TODO: debug further and report
    inputBytes = new ProtoBench().fooBarContainer.toByteArray();
    input = CodedInputByteBufferNano.newInstance(inputBytes);
}
项目:h2o-3    文件:DeepwaterCaffeModel.java   
private Cmd call(Cmd cmd) {
  try {
    OutputStream stdin = _process.getOutputStream();

    int len = cmd.getSerializedSize();
    ByteBuffer buffer = ByteBuffer.allocate(4 + len);
    buffer.putInt(len);
    CodedOutputByteBufferNano ou = CodedOutputByteBufferNano.newInstance(
        buffer.array(), buffer.position(), buffer.remaining());
    cmd.writeTo(ou);
    buffer.position(buffer.position() + len);
    stdin.write(buffer.array(), 0, buffer.position());
    stdin.flush();

    InputStream stdout = _process.getInputStream();
    int read = stdout.read(buffer.array(), 0, 4);
    if (read != 4)
      throw new RuntimeException();
    buffer.position(0);
    buffer.limit(read);
    len = buffer.getInt();
    if (buffer.capacity() < len)
      buffer = ByteBuffer.allocate(len);
    buffer.position(0);
    buffer.limit(len);

    while (buffer.position() < buffer.limit()) {
      read = stdout.read(buffer.array(), buffer.position(), buffer.limit());
      buffer.position(buffer.position() + read);
    }

    Cmd res = new Cmd();
    CodedInputByteBufferNano in = CodedInputByteBufferNano.newInstance(
        buffer.array(), 0, buffer.position());
    res.mergeFrom(in);
    return res;
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}