public static List < byte [ ] > decodeSequence ( byte [ ] sequence ) { int index = 0 ; // check tag checkArgument ( sequence [ 0 ] == SEQUENCE_TAG , "Expected sequence tag" ) ; index ++ ; // read length int sequenceDataLength = decodeLength ( sequence , index ) ; index += encodedLengthSize ( sequenceDataLength ) ; checkArgument ( sequenceDataLength + index == sequence . length , "Invalid sequence" ) ; // read elements ImmutableList . Builder < byte [ ] > elements = ImmutableList . builder ( ) ; while ( index < sequence . length ) { int elementStart = index ; // skip the tag index ++ ; // read length int length = decodeLength ( sequence , index ) ; index += encodedLengthSize ( length ) ; byte [ ] data = Arrays . copyOfRange ( sequence , elementStart , index + length ) ; elements . add ( data ) ; index += length ; } return elements . build ( ) ; }
Decodes a sequence of encoded values .