/** * Helper method for implementing {@link LiteralByteString#hashCode()}. */ static int hashCode(byte[] bytes, int offset, int length) { // The hash code for a byte array should be the same as the hash code for a // ByteString with the same content. This is to ensure that the generated // hashCode() method will return the same value as the pure reflection // based hashCode() method. int h = Internal.partialHash(length, bytes, offset, length); return h == 0 ? 1 : h; }
@Override protected final int partialHash(int h, int offset, int length) { return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length); }
/** * Helper method for implementing {@link Message#hashCode()} for bytes * field. */ public static int hashCodeByteBuffer(ByteBuffer bytes) { if (bytes.hasArray()) { // Fast path. int h = partialHash(bytes.capacity(), bytes.array(), bytes.arrayOffset(), bytes.capacity()); return h == 0 ? 1 : h; } else { // Read the data into a temporary byte array before calculating the // hash value. final int bufferSize = bytes.capacity() > DEFAULT_BUFFER_SIZE ? DEFAULT_BUFFER_SIZE : bytes.capacity(); final byte[] buffer = new byte[bufferSize]; final ByteBuffer duplicated = bytes.duplicate(); duplicated.clear(); int h = bytes.capacity(); while (duplicated.remaining() > 0) { final int length = duplicated.remaining() <= bufferSize ? duplicated.remaining() : bufferSize; duplicated.get(buffer, 0, length); h = partialHash(h, buffer, 0, length); } return h == 0 ? 1 : h; } }
/** * Helper method for implementing {@link LiteralByteString#hashCode()}. */ static int hashCode(byte[] bytes, int offset, int length) { // The hash code for a byte array should be the same as the hash code for a // ByteString with the same content. This is to ensure that the generated // hashCode() method will return the same value as the pure reflection // based hashCode() method. int h = Internal.partialHash(length, bytes, offset, length); return h == 0 ? 1 : h; }
/** * Helper method for implementing {@link LiteralByteString#hashCode()}. */ static int hashCode(byte[] bytes, int offset, int length) { // The hash code for a byte array should be the same as the hash code for a // ByteString with the same content. This is to ensure that the generated // hashCode() method will return the same value as the pure reflection // based hashCode() method. int h = Internal.partialHash(length, bytes, offset, length); return h == 0 ? 1 : h; }
@Override protected final int partialHash(int h, int offset, int length) { return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length); }
@Override protected final int partialHash(int h, int offset, int length) { return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length); }
/** * Helper method for implementing {@link Message#hashCode()} for bytes * field. */ public static int hashCodeByteBuffer(ByteBuffer bytes) { if (bytes.hasArray()) { // Fast path. int h = partialHash(bytes.capacity(), bytes.array(), bytes.arrayOffset(), bytes.capacity()); return h == 0 ? 1 : h; } else { // Read the data into a temporary byte array before calculating the // hash value. final int bufferSize = bytes.capacity() > DEFAULT_BUFFER_SIZE ? DEFAULT_BUFFER_SIZE : bytes.capacity(); final byte[] buffer = new byte[bufferSize]; final ByteBuffer duplicated = bytes.duplicate(); duplicated.clear(); int h = bytes.capacity(); while (duplicated.remaining() > 0) { final int length = duplicated.remaining() <= bufferSize ? duplicated.remaining() : bufferSize; duplicated.get(buffer, 0, length); h = partialHash(h, buffer, 0, length); } return h == 0 ? 1 : h; } }
/** * Helper method for implementing {@link Message#hashCode()} for bytes * field. */ public static int hashCodeByteBuffer(ByteBuffer bytes) { if (bytes.hasArray()) { // Fast path. int h = partialHash(bytes.capacity(), bytes.array(), bytes.arrayOffset(), bytes.capacity()); return h == 0 ? 1 : h; } else { // Read the data into a temporary byte array before calculating the // hash value. final int bufferSize = bytes.capacity() > DEFAULT_BUFFER_SIZE ? DEFAULT_BUFFER_SIZE : bytes.capacity(); final byte[] buffer = new byte[bufferSize]; final ByteBuffer duplicated = bytes.duplicate(); duplicated.clear(); int h = bytes.capacity(); while (duplicated.remaining() > 0) { final int length = duplicated.remaining() <= bufferSize ? duplicated.remaining() : bufferSize; duplicated.get(buffer, 0, length); h = partialHash(h, buffer, 0, length); } return h == 0 ? 1 : h; } }