use of com.google.protobuf.ByteString in project j2objc by google.
the class CompatibilityTest method testSetAndGetRepeatedBytes.
public void testSetAndGetRepeatedBytes() throws Exception {
List<ByteString> list = new ArrayList<ByteString>();
list.add(ByteString.copyFrom("def".getBytes()));
list.add(ByteString.copyFrom("ghi".getBytes()));
TypicalData data = TypicalData.newBuilder().addRepeatedBytes(ByteString.copyFrom("abc".getBytes())).addAllRepeatedBytes(list).setRepeatedBytes(2, ByteString.copyFrom("jkl".getBytes())).build();
assertEquals(3, data.getRepeatedBytesCount());
assertEquals("abc", new String(data.getRepeatedBytes(0).toByteArray()));
byte[] bytes = data.toByteArray();
TypicalData other = TypicalData.parseFrom(bytes);
assertEquals("abc", new String(other.getRepeatedBytes(0).toByteArray()));
assertEquals("def", new String(other.getRepeatedBytesList().get(1).toByteArray()));
assertEquals("jkl", new String(other.getRepeatedBytes(2).toByteArray()));
}
use of com.google.protobuf.ByteString in project bazel by bazelbuild.
the class DigestTest method testFromVirtualInput.
@Test
public void testFromVirtualInput() throws Exception {
Pair<ByteString, Long> result = Digest.fromVirtualActionInput(new VirtualActionInput() {
@Override
public void writeTo(OutputStream out) throws IOException {
out.write(UGLY.getBytes(UTF_8));
}
@Override
public String getExecPathString() {
throw new UnsupportedOperationException();
}
@Override
public PathFragment getExecPath() {
throw new UnsupportedOperationException();
}
});
assertEquals(UGLY_DIGEST, result.first.toStringUtf8());
assertEquals(UGLY.length(), result.second.longValue());
}
use of com.google.protobuf.ByteString in project bazel by bazelbuild.
the class SingleBuildFileCacheTest method testUnreadableFileWhenFileSystemSupportsDigest.
@Test
public void testUnreadableFileWhenFileSystemSupportsDigest() throws Exception {
byte[] expectedDigestRaw = MessageDigest.getInstance("md5").digest("randomtext".getBytes(StandardCharsets.UTF_8));
ByteString expectedDigest = ByteString.copyFrom(expectedDigestRaw);
md5Overrides.put("/unreadable", expectedDigestRaw);
ActionInput input = ActionInputHelper.fromPath("/unreadable");
Path file = fs.getPath("/unreadable");
file.getOutputStream().close();
file.chmod(0);
ByteString actualDigest = ByteString.copyFrom(underTest.getDigest(input));
assertThat(expectedDigest).isEqualTo(actualDigest);
}
use of com.google.protobuf.ByteString in project bazel by bazelbuild.
the class SingleBuildFileCacheTest method testBasic.
@Test
public void testBasic() throws Exception {
ActionInput empty = ActionInputHelper.fromPath("/empty");
assertEquals(0, underTest.getSizeInBytes(empty));
byte[] digestBytes = underTest.getDigest(empty);
ByteString digest = ByteString.copyFromUtf8(BaseEncoding.base16().lowerCase().encode(digestBytes));
assertEquals(EMPTY_MD5, digest.toStringUtf8());
assertEquals("/empty", underTest.getInputFromDigest(digest).getExecPathString());
assert (underTest.contentsAvailableLocally(digest));
ByteString other = ByteString.copyFrom("f41d8cd98f00b204e9800998ecf8427e", "UTF-16");
assert (!underTest.contentsAvailableLocally(other));
assert (calls.containsKey("/empty"));
}
use of com.google.protobuf.ByteString in project pulsar by yahoo.
the class ByteBufCodedInputStream method readBytes.
/** Read a {@code bytes} field value from the stream. */
public ByteString readBytes() throws IOException {
final int size = readRawVarint32();
if (size == 0) {
return ByteString.EMPTY;
} else {
RecyclableHeapByteBuf heapBuf = RecyclableHeapByteBuf.get();
if (size > heapBuf.writableBytes()) {
heapBuf.capacity(size);
}
heapBuf.writeBytes(buf, size);
ByteString res = ByteString.copyFrom(heapBuf.array(), heapBuf.arrayOffset(), heapBuf.readableBytes());
heapBuf.recycle();
return res;
}
}
Aggregations