Search in sources :

Example 16 with ByteString

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()));
}
Also used : TypicalData(protos.TypicalData) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString)

Example 17 with ByteString

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());
}
Also used : VirtualActionInput(com.google.devtools.build.lib.actions.cache.VirtualActionInput) ByteString(com.google.protobuf.ByteString) OutputStream(java.io.OutputStream) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 18 with ByteString

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);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ActionInput(com.google.devtools.build.lib.actions.ActionInput) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 19 with ByteString

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"));
}
Also used : ActionInput(com.google.devtools.build.lib.actions.ActionInput) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 20 with ByteString

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;
    }
}
Also used : RecyclableHeapByteBuf(com.yahoo.pulsar.common.api.Commands.RecyclableHeapByteBuf) ByteString(com.google.protobuf.ByteString)

Aggregations

ByteString (com.google.protobuf.ByteString)159 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)27 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)18 ServerRequest (com.pokegoapi.main.ServerRequest)13 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)10 Map (java.util.Map)10 HashMap (java.util.HashMap)9 List (java.util.List)9 AggregateResponse (org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse)9 BeforeTest (org.testng.annotations.BeforeTest)9 Test (org.testng.annotations.Test)9 Connection (org.apache.hadoop.hbase.client.Connection)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 Scan (org.apache.hadoop.hbase.client.Scan)7 DeleteRangeResponse (com.coreos.jetcd.api.DeleteRangeResponse)6 RangeResponse (com.coreos.jetcd.api.RangeResponse)6 RpcCallback (com.google.protobuf.RpcCallback)6 RpcController (com.google.protobuf.RpcController)6