Java Code Examples for com.google.common.primitives.UnsignedBytes#MAX_VALUE

The following examples show how to use com.google.common.primitives.UnsignedBytes#MAX_VALUE . 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: KeyUtils.java    From tikv-client-lib-java with Apache License 2.0 5 votes vote down vote up
/**
 * The next key for bytes domain It first plus one at LSB and if LSB overflows, a zero byte is
 * appended at the end Original bytes will be reused if possible
 *
 * @param key key to encode
 * @return encoded results
 */
public static byte[] prefixNext(byte[] key) {
  int i;
  for (i = key.length - 1; i >= 0; i--) {
    if (key[i] != UnsignedBytes.MAX_VALUE) {
      key[i]++;
      break;
    }
  }
  if (i == -1) {
    return getNextKeyInByteOrder(key);
  }
  return key;
}
 
Example 2
Source File: UtilsTest.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMessageUtil() {
    final byte[] result = new byte[] { UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
        UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
        UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
        UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
        UnsignedBytes.MAX_VALUE, 0, 23, 3, 32, 5, 14, 21 };
    final ByteBuf formattedMessage = Unpooled.buffer();
    MessageUtil.formatMessage(3, Unpooled.wrappedBuffer(new byte[] { 32, 5, 14, 21 }), formattedMessage);
    assertArrayEquals(result, ByteArray.getAllBytes(formattedMessage));
}
 
Example 3
Source File: AddressUtils.java    From dhcp4j with Apache License 2.0 5 votes vote down vote up
/**
 * Performs an arbitrary-precision decrement of a byte array.
 *
 * @param in The array to decrement.
 * @return The same input array.
 */
@Nonnull
public static byte[] decrement(@Nonnull byte[] in) {
    for (int i = in.length - 1; i >= 0; i--) {
        if (UnsignedBytes.toInt(in[i]) > 0) {
            in[i]--;
            break;
        }
        in[i] = UnsignedBytes.MAX_VALUE;
    }

    return in;
}
 
Example 4
Source File: AddressUtils.java    From dhcp4j with Apache License 2.0 5 votes vote down vote up
/**
 * Performs an arbitrary-precision decrement of a byte array.
 *
 * @param in The array to decrement.
 * @return The same input array.
 */
@Nonnull
public static byte[] decrement(@Nonnull byte[] in) {
    for (int i = in.length - 1; i >= 0; i--) {
        if (UnsignedBytes.toInt(in[i]) > 0) {
            in[i]--;
            break;
        }
        in[i] = UnsignedBytes.MAX_VALUE;
    }

    return in;
}
 
Example 5
Source File: ParsingTools.java    From mongowp with Apache License 2.0 4 votes vote down vote up
/**
 * Translate a byte to the {@link BsonType} it represents, as specified on the
 * <a href="http://bsonspec.org/spec.html">BSON Spec</a>
 *
 * @param typeByte
 * @return
 * @throws NettyBsonReaderException
 */
@Nonnull
protected static BsonType getBsonType(byte typeByte) throws NettyBsonReaderException {
  switch (typeByte) {
    case 0x01:
      return DOUBLE;
    case 0x02:
      return STRING;
    case 0x03:
      return DOCUMENT;
    case 0x04:
      return ARRAY;
    case 0x05:
      return BINARY;
    case 0x06:
      return UNDEFINED;
    case 0x07:
      return OBJECT_ID;
    case 0x08:
      return BOOLEAN;
    case 0x09:
      return DATETIME;
    case 0x0A:
      return NULL;
    case 0x0B:
      return REGEX;
    case 0x0C:
      return DB_POINTER;
    case 0x0D:
      return JAVA_SCRIPT;
    case 0x0E:
      return DEPRECATED;
    case 0x0F:
      return JAVA_SCRIPT_WITH_SCOPE;
    case 0x10:
      return INT32;
    case 0x11:
      return TIMESTAMP;
    case 0x12:
      return INT64;
    case 0x13:
      return DECIMAL128;
    case UnsignedBytes.MAX_VALUE:
      return MIN;
    case 0x7F:
      return MAX;
    default:
      throw new NettyBsonReaderException("It is not defined the type associated with the byte "
          + UnsignedBytes.toString(typeByte, 16));
  }
}
 
Example 6
Source File: ParsingTools.java    From mongowp with Apache License 2.0 4 votes vote down vote up
protected static byte getByte(BsonType bsonType) throws NettyBsonReaderException {
  switch (bsonType) {
    case DOUBLE:
      return 0x01;
    case STRING:
      return 0x02;
    case DOCUMENT:
      return 0x03;
    case ARRAY:
      return 0x04;
    case BINARY:
      return 0x05;
    case UNDEFINED:
      return 0x06;
    case OBJECT_ID:
      return 0x07;
    case BOOLEAN:
      return 0x08;
    case DATETIME:
      return 0x09;
    case NULL:
      return 0x0A;
    case REGEX:
      return 0x0B;
    case DB_POINTER:
      return 0x0C;
    case JAVA_SCRIPT:
      return 0x0D;
    case DEPRECATED:
      return 0x0E;
    case JAVA_SCRIPT_WITH_SCOPE:
      return 0x0F;
    case INT32:
      return 0x10;
    case TIMESTAMP:
      return 0x11;
    case INT64:
      return 0x12;
    case DECIMAL128:
      return 0x13;
    case MIN:
      return UnsignedBytes.MAX_VALUE;
    case MAX:
      return 0x7F;
    default:
      throw new NettyBsonReaderException("It is not defined the byte associated with the type "
          + bsonType);
  }
}