use of com.google.protobuf.ByteString in project bazel by bazelbuild.
the class GrpcActionCache method createFileFromStream.
private ContentDigest createFileFromStream(Map<ContentDigest, Pair<Path, FileMetadata>> metadataMap, Iterator<CasDownloadReply> replies) throws IOException, CacheNotFoundException {
Preconditions.checkArgument(replies.hasNext());
CasDownloadReply reply = replies.next();
if (reply.hasStatus()) {
handleDownloadStatus(reply.getStatus());
}
BlobChunk chunk = reply.getData();
ContentDigest digest = chunk.getDigest();
Preconditions.checkArgument(metadataMap.containsKey(digest));
Pair<Path, FileMetadata> metadata = metadataMap.get(digest);
Path path = metadata.first;
FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
try (OutputStream stream = path.getOutputStream()) {
ByteString data = chunk.getData();
data.writeTo(stream);
long bytesLeft = digest.getSizeBytes() - data.size();
while (bytesLeft > 0) {
Preconditions.checkArgument(replies.hasNext());
reply = replies.next();
if (reply.hasStatus()) {
handleDownloadStatus(reply.getStatus());
}
chunk = reply.getData();
data = chunk.getData();
Preconditions.checkArgument(!chunk.hasDigest());
Preconditions.checkArgument(chunk.getOffset() == digest.getSizeBytes() - bytesLeft);
data.writeTo(stream);
bytesLeft -= data.size();
}
path.setExecutable(metadata.second.getExecutable());
}
return digest;
}
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 j2objc by google.
the class CompatibilityTest method checkGetExtensions.
private void checkGetExtensions(TypicalDataOrBuilder data) {
assertEquals(123, ((Integer) data.getExtension(Typical.myPrimitiveExtension)).intValue());
Object msg = data.getExtension(Typical.myExtension);
assertTrue(msg instanceof TypicalDataMessage);
assertEquals(321, ((TypicalDataMessage) msg).getMyMessageInt());
Object result = data.getExtension(Typical.myRepeatedPrimitiveExtension);
assertTrue(result instanceof List);
assertTrue(((List) result).get(0) instanceof Integer);
assertEquals(3, data.getExtensionCount(Typical.myRepeatedPrimitiveExtension));
assertEquals(2, ((Integer) data.getExtension(Typical.myRepeatedPrimitiveExtension, 1)).intValue());
assertEquals(3, ((Integer) data.getExtension(Typical.myRepeatedPrimitiveExtension, 2)).intValue());
assertEquals(2, data.getExtensionCount(Typical.myRepeatedExtension));
result = data.getExtension(Typical.myRepeatedExtension, 1);
assertTrue(result instanceof TypicalDataMessage);
assertEquals(543, ((TypicalDataMessage) result).getMyMessageInt());
assertEquals(TypicalData.EnumType.VALUE1, data.getExtension(Typical.myEnumExtension));
result = data.getExtension(Typical.myBytesExtension);
assertTrue(result instanceof ByteString);
assertEquals("abc", new String(((ByteString) result).toByteArray()));
result = data.getExtension(Typical.myBoolExtension);
assertEquals(Boolean.TRUE, result);
assertEquals(456, ((Integer) data.getExtension(MsgWithNestedExtensions.intExt)).intValue());
}
Aggregations