private static Map < FEATURE , Integer > tokenize ( byte [ ] tlv ) { HashMap < FEATURE , Integer > m = new HashMap < FEATURE , Integer > ( ) ; if ( tlv . length % 6 != 0 ) { throw new IllegalArgumentException ( "Bad response length: " + tlv . length ) ; } for ( int i = 0 ; i < tlv . length ; i += 6 ) { int ft = tlv [ i + 0 ] & 0xFF ; FEATURE f = FEATURE . fromValue ( ft ) ; byte [ ] c = Arrays . copyOfRange ( tlv , i + 2 , i + 6 ) ; ByteBuffer buffer = ByteBuffer . wrap ( c ) ; buffer . order ( ByteOrder . BIG_ENDIAN ) ; int ci = buffer . getInt ( ) ; m . put ( f , ci ) ; } return m ; }
Parse the features into FEATURE - > control code map