TestObjectWritableProtos.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:hadoop 作者:
/**
 * Write a protobuf to a buffer 'numProtos' times, and then
 * read them back, making sure all data comes through correctly.
 */
private void doTest(int numProtos) throws IOException {
  Configuration conf = new Configuration();
  DataOutputBuffer out = new DataOutputBuffer();

  // Write numProtos protobufs to the buffer
  Message[] sent = new Message[numProtos];
  for (int i = 0; i < numProtos; i++) {
    // Construct a test protocol buffer using one of the
    // protos that ships with the protobuf library
    Message testProto = DescriptorProtos.EnumValueDescriptorProto.newBuilder()
      .setName("test" + i).setNumber(i).build();
    ObjectWritable.writeObject(out, testProto,
        DescriptorProtos.EnumValueDescriptorProto.class, conf);
    sent[i] = testProto;
  }

  // Read back the data
  DataInputBuffer in = new DataInputBuffer();
  in.reset(out.getData(), out.getLength());

  for (int i = 0; i < numProtos; i++) {
    Message received = (Message)ObjectWritable.readObject(in, conf);

    assertEquals(sent[i], received);
  }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号