public static <T>List<T> decode(InputStream data,Parser<T> parser) throws IOException {
  CodedInputStream stream=CodedInputStream.newInstance(data);
  List<T> list=new ArrayList<>();
  while (!stream.isAtEnd()) {
    int size=stream.readRawVarint32();
    byte[] element=stream.readRawBytes(size);
    T decoded=parser.parseFrom(element);
    list.add(decoded);
  }
  return list;
}

public static < T > List < T > decode ( InputStream data , Parser < T > parser ) throws IOException { CodedInputStream stream = CodedInputStream . newInstance ( data ) ; List < T > list = new ArrayList < > ( ) ; while ( ! stream . isAtEnd ( ) ) { int size = stream . readRawVarint32 ( ) ; byte [ ] element = stream . readRawBytes ( size ) ; T decoded = parser . parseFrom ( element ) ; list . add ( decoded ) ; } return list ; }
decode custom protobuf variable length array .
