本文整理汇总了Java中com.google.protobuf.ByteString.asReadOnlyByteBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java ByteString.asReadOnlyByteBuffer方法的具体用法?Java ByteString.asReadOnlyByteBuffer怎么用?Java ByteString.asReadOnlyByteBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.ByteString
的用法示例。
在下文中一共展示了ByteString.asReadOnlyByteBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSerializeToBuffer
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
public void testSerializeToBuffer() throws Exception {
SerializableException error = null;
try {
throw new NullPointerException();
} catch (Exception ex) {
error = new SerializableException(ex);
}
assertNotNull(error);
int size = error.getSerializedSize();
ByteBuffer b = ByteBuffer.allocate(size);
error.serializeToBuffer(b);
b.rewind();
int expected = b.getInt();
assertTrue(expected > 0);
assertTrue(expected <= size);
b.rewind();
// Make sure we can still do this with a BufferPool
DBBPool buffer_pool = new DBBPool(false, false);
BBContainer bc = buffer_pool.acquire(size);
error.serializeToBuffer(bc.b);
bc.b.rewind();
assertEquals(expected, bc.b.getInt());
bc.b.rewind();
ByteString bs = ByteString.copyFrom(b);
ByteBuffer bs_b = bs.asReadOnlyByteBuffer();
// System.err.println("NEW: " + StringUtil.md5sum(b));
assertEquals(expected, bs_b.getInt());
}
示例2: getBytesFromResponse
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
byte[] getBytesFromResponse(ByteString response) {
ByteBuffer bb = response.asReadOnlyByteBuffer();
bb.rewind();
byte[] bytes;
if (bb.hasArray()) {
bytes = bb.array();
} else {
bytes = response.toByteArray();
}
return bytes;
}
示例3: byteStringToByteBuffer
import com.google.protobuf.ByteString; //导入方法依赖的package包/类
public static ByteBuffer byteStringToByteBuffer(ByteString byteString) {
return byteString == null ? null : byteString.asReadOnlyByteBuffer();
}