Java Code Examples for com.google.protobuf.ByteString#iterator()

The following examples show how to use com.google.protobuf.ByteString#iterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RowFilter.java    From heroic with Apache License 2.0 6 votes vote down vote up
static int compareByteStrings(final ByteString a, final ByteString b) {
    final ByteString.ByteIterator left = a.iterator();
    final ByteString.ByteIterator right = b.iterator();

    while (left.hasNext() && right.hasNext()) {
        final int c = Integer.compareUnsigned(left.nextByte(), right.nextByte());

        if (c != 0) {
            return c;
        }
    }

    if (left.hasNext()) {
        return 1;
    }

    if (right.hasNext()) {
        return -1;
    }

    return 0;
}
 
Example 2
Source File: BigtableBackendTest.java    From heroic with Apache License 2.0 6 votes vote down vote up
int compare(ByteString a, ByteString b) {
    ByteIterator itA = a.iterator();
    ByteIterator itB = b.iterator();

    while (itA.hasNext()) {
        if (!itB.hasNext()) {
            return -1;
        }

        int bA = itA.nextByte() & 0xff;
        int bB = itB.nextByte() & 0xff;

        int c = Integer.compare(bA, bB);

        if (c != 0) {
            return c;
        }
    }

    if (itB.hasNext()) {
        return 1;
    }

    return 0;
}
 
Example 3
Source File: ProtoSpanDeserializer.java    From jaeger-analytics-java with Apache License 2.0 5 votes vote down vote up
private String asHexString(ByteString id) {
  ByteIterator iterator = id.iterator();
  StringBuilder out = new StringBuilder();
  while (iterator.hasNext()) {
    byte b = iterator.nextByte();
    out.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
  }
  return out.toString();
}
 
Example 4
Source File: LegacyConfigsHandler.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Nullable
private ExperimentPayload deserializePayload(ByteString legacyExperimentPayload) {
  try {
    Iterator<Byte> byteIterator = legacyExperimentPayload.iterator();
    byte[] payloadArray = new byte[legacyExperimentPayload.size()];
    for (int index = 0; index < payloadArray.length; index++) {
      payloadArray[index] = byteIterator.next();
    }
    return ExperimentPayload.parseFrom(payloadArray);
  } catch (InvalidProtocolBufferException e) {
    Log.d(TAG, "Payload was not defined or could not be deserialized.", e);
    return null;
  }
}
 
Example 5
Source File: ProtoUnmarshaler.java    From Mastering-Distributed-Tracing with MIT License 5 votes vote down vote up
private String asHexString(ByteString id) {
    ByteIterator iterator = id.iterator();
    StringBuilder out = new StringBuilder();
    while (iterator.hasNext()) {
        byte b = iterator.nextByte();
        out.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
    }
    return out.toString();
}
 
Example 6
Source File: ByteStringTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testIterator() throws Exception {
  ByteString s1 = ByteString.copyFrom("foo".getBytes("UTF-8"));
  ByteString s2 = ByteString.copyFrom("你好".getBytes("UTF-8"));
  Iterator<Byte> i1 = s1.iterator();
  Iterator<Byte> i2 = s2.iterator();
  for (int i = 0; i < s1.size(); i++) {
    assertEquals((Byte) s1.byteAt(i), i1.next());
  }
  for (int i = 0; i < s2.size(); i++) {
    assertEquals((Byte) s2.byteAt(i), i2.next());
  }
}