本文整理匯總了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();
}