The byte following the tag length (a short) is the tag type.

The current code is correct.

On Sun, Aug 6, 2017 at 5:40 AM, Chia-Ping Tsai <chia7...@apache.org> wrote:

> According to the following code:
>   public ArrayBackedTag(byte tagType, byte[] tag) {
>     int tagLength = tag.length + TYPE_LENGTH_SIZE;
>     if (tagLength > MAX_TAG_LENGTH) {
>       throw new IllegalArgumentException(
>           "Invalid tag data being passed. Its length can not exceed " +
> MAX_TAG_LENGTH);
>     }
>     length = TAG_LENGTH_SIZE + tagLength;
>     bytes = new byte[length];
>     int pos = Bytes.putAsShort(bytes, 0, tagLength);
>     pos = Bytes.putByte(bytes, pos, tagType);
>     Bytes.putBytes(bytes, pos, tag, 0, tag.length);
>     this.type = tagType;
>   }
> The layout of the byte array should be:
> |tag legnth (2 bytes)|tag type(1 byte)|tag|
>
> It seems to me that the "bytes[offset + TYPE_LENGTH_SIZE]" is correct.
>
> On 2017-08-06 16:35, Lars George <lars.geo...@gmail.com> wrote:
> > Hi,
> >
> > I found this reading through tags in 1.3, but checked in trunk as
> > well. There is this code:
> >
> >   public ArrayBackedTag(byte[] bytes, int offset, int length) {
> >     if (length > MAX_TAG_LENGTH) {
> >       throw new IllegalArgumentException(
> >           "Invalid tag data being passed. Its length can not exceed "
> > + MAX_TAG_LENGTH);
> >     }
> >     this.bytes = bytes;
> >     this.offset = offset;
> >     this.length = length;
> >     this.type = bytes[offset + TAG_LENGTH_SIZE];
> >   }
> >
> > I am concerned about the last line of the code, using the wrong constant?
> >
> >   public final static int TYPE_LENGTH_SIZE = Bytes.SIZEOF_BYTE;
> >   public final static int TAG_LENGTH_SIZE = Bytes.SIZEOF_SHORT;
> >
> > Should this not read
> >
> >     this.type = bytes[offset + TYPE_LENGTH_SIZE];
> >
> > Would this not read the type from the wrong place in the array?
> >
> > Cheers,
> > Lars
> >
>

Reply via email to