You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "larry chen (Jira)" <ji...@apache.org> on 2021/03/30 06:24:00 UTC
[jira] [Updated] (HBASE-25708) Bytes.toInt(byte[] bytes)-why set
default offset as zero
[ https://issues.apache.org/jira/browse/HBASE-25708?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
larry chen updated HBASE-25708:
-------------------------------
Priority: Major (was: Minor)
> Bytes.toInt(byte[] bytes)-why set default offset as zero
> --------------------------------------------------------
>
> Key: HBASE-25708
> URL: https://issues.apache.org/jira/browse/HBASE-25708
> Project: HBase
> Issue Type: Improvement
> Components: community
> Reporter: larry chen
> Priority: Major
>
> As we know, when using Bytes.tobytes(int), the method convert the int value to byte-array with big endian.
> So, when we try to extract the right int-value from byte-array, we use method 'Bytes.toInt(byte[] bytes)', and int the method, it sets the offset as zero.
>
> it shows like this
> /**
> * Converts a byte array to an int value
> * @param bytes byte array
> * @return the int value
> */
> public static int toInt(byte[] bytes) {
> return toInt(bytes, 0, SIZEOF_INT);
> }
> My question is :
> why don't we set the offset as (bytes.length - SIZEOF_INT)?
>
> Recently, we have long-value stored in hbase, as we try to extract, we decode the byte-array as int-value, it leads some incorrect-value like 0.
>
> The usage of decoding-int-value from long-value-byte-array is wrong, I'm just curious about the start point of setting offset as 0
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)