long encodeDataAsAddress(byte[] bytes, boolean isSerialized, boolean isCompressed) {
    if (bytes.length < MAX_LENGTH_FOR_DATA_AS_ADDRESS) {
      long result = 0L;
      for (byte aByte : bytes) {
        result |= aByte & 0x00ff;
        result <<= 8;
      }
      result |= bytes.length << SIZE_SHIFT | ENCODED_BIT;
      if (isSerialized) {
        result |= SERIALIZED_BIT;
      }
      if (isCompressed) {
        result |= COMPRESSED_BIT;
      }
      return result;
    }

    if (isSerialized && !isCompressed) {
      // Check for some special types that take more than 7 bytes to serialize but that might be
      // able to be inlined with less than 8 bytes.
      if (bytes[0] == DSCODE.LONG.toByte()) {
        // A long is currently always serialized as 8 bytes (9 if you include the dscode). But many
        // long values will actually be small enough for is to encode in 7 bytes.
        if (bytes[1] == 0 && (bytes[2] & 0x80) == 0 || bytes[1] == -1 && (bytes[2] & 0x80) != 0) {
          // The long can be encoded as 7 bytes since the most signification byte is simply an
          // extension of the sign byte on the second most signification byte.
          long result = 0L;
          for (int i = 2; i < bytes.length; i++) {
            result |= bytes[i] & 0x00ff;
            result <<= 8;
          }
          result |= 7 << SIZE_SHIFT | LONG_BIT | SERIALIZED_BIT | ENCODED_BIT;
          return result;
        }
      }
    }

    return 0L;
  }
Returns 0 if the data could not be encoded as an address.
geode-core/src/main/java/org/apache/geode/internal/offheap/OffHeapRegionEntryHelperInstance.java