TLVStringArrayDecoder extends AbstractTLVDecoder<String[]> { @SuppressWarnings("unchecked") @Override public String[] codec(byte[] source, Object additionInfo) { if (null == decoderProvider) throw new IllegalStateException("TLVbArrayDecoder must be registered to decodeContext."); if (null == source) return null; List<String> ret = Lists.newArrayList(); TLVConfig tlvConfig = decoderProvider.getTlvConfig(); NumberCodec nc = NumberCodecFactory.fetchNumberCodec(decoderProvider.getByteOrder()); ByteArrayInputStream buf = new ByteArrayInputStream(source); while (buf.available() > 0) { buf.skip(tlvConfig.getTagLen()); byte[] lenBytes = new byte[tlvConfig.getLengthLen()]; try { buf.read(lenBytes); } catch (IOException e) { throw new RuntimeException("TLVStringArrayDecoder.codec:", e); } int len = nc.bytes2Int(lenBytes, tlvConfig.getLengthLen()); byte[] dataBytes = new byte[len]; try { buf.read(dataBytes); } catch (IOException e) { throw new RuntimeException("TLVStringArrayDecoder.codec:", e); } TLVDecoder<String> tlvStringDecoder = (TLVDecoder<String>) decoderProvider .lookupCodec(String.class); String v = tlvStringDecoder.codec(dataBytes, null); ret.add(v); } return ret.toArray(new String[0]); }  @Override String[] getCodecKeyes(); @SuppressWarnings("unchecked") @Override String[] codec(byte[] source, Object additionInfo); @Override TLVDecoderProvider getCodecProvider(); @Override void setCodecProvider(TLVDecoderProvider codecPrivoder); @Override boolean isObjectDecoder();  }
@Test public void testTLVStringArrayDecoder() { TLVEncoder<Object> tlvEncoder = TLVCodecProviders.newBigEndianTLVEncoderProvider() .getObjectEncoder(); TLVDecoder<Object> tlvDecoder = TLVCodecProviders.newBigEndianTLVDecoderProvider() .getObjectDecoder(); Bean a = new Bean(); a.setPicVers(new String[] { "aa", "bb" }); List<byte[]> list = tlvEncoder.codec(a, null); byte[] bytes = ByteUtils.union(list); HexUtils.printAsHexCodes(bytes, 1024); Bean _a = (Bean) tlvDecoder.codec(bytes, Bean.class); assertEquals(a, _a); }