@Test public void testBasicConversion() throws Exception { AddressBookProtos.Person john = AddressBookProtos.Person.newBuilder() .setId(1234) .setName("Joltie Root") .setEmail("joltie.root@example.com") .addPhones( AddressBookProtos.Person.PhoneNumber.newBuilder() .setNumber("555-4321") .setType(AddressBookProtos.Person.PhoneType.HOME) ).build(); AddressBookProtos.AddressBook book = AddressBookProtos.AddressBook.newBuilder() .addPeople(john).build(); byte[] addressBook = book.toByteArray(); InputStream is = null; try { is = this.getClass().getClassLoader().getResourceAsStream("addressbook.desc"); byte[] bytes = IOUtils.toByteArray(is); Decoder<Row> decoder = new ProtobufDecoderUsingDescriptor(bytes, "AddressBook"); Assert.assertNotNull(decoder); List<Row> rows = decoder.decode(addressBook); Assert.assertNotNull(rows); Assert.assertEquals("Joltie Root", rows.get(0).getValue("people_name")); Assert.assertEquals(1234, rows.get(0).getValue("people_id")); Assert.assertEquals("joltie.root@example.com", rows.get(0).getValue("people_email")); Assert.assertEquals("555-4321", rows.get(0).getValue("people_phones_number")); Assert.assertEquals("HOME", rows.get(0).getValue("people_phones_type")); } finally { if (is != null) { is.close(); } } }
@Override public List<Row> decode(byte[] bytes) throws DecoderException { List<Row> rows = new ArrayList<>(); try { DynamicMessage message = DynamicMessage.parseFrom(descriptor, bytes); Row row = new Row(); decodeMessage(message, row, null); rows.add(row); } catch (InvalidProtocolBufferException e) { throw new DecoderException(e.getMessage()); } return rows; }
ProtobufDecoderUsingDescriptor implements Decoder<Row> { @Override public List<Row> decode(byte[] bytes) throws DecoderException { List<Row> rows = new ArrayList<>(); try { DynamicMessage message = DynamicMessage.parseFrom(descriptor, bytes); Row row = new Row(); decodeMessage(message, row, null); rows.add(row); } catch (InvalidProtocolBufferException e) { throw new DecoderException(e.getMessage()); } return rows; } }
ProtobufDecoderUsingDescriptor implements Decoder<Row> { @Override public List<Row> decode(byte[] bytes) throws DecoderException { List<Row> rows = new ArrayList<>(); try { DynamicMessage message = DynamicMessage.parseFrom(descriptor, bytes); Row row = new Row(); decodeMessage(message, row, null); rows.add(row); } catch (InvalidProtocolBufferException e) { throw new DecoderException(e.getMessage()); } return rows; } ProtobufDecoderUsingDescriptor(byte[] bytes, String name); }
ProtobufDecoderUsingDescriptor implements Decoder<Row> { @Override public List<Row> decode(byte[] bytes) throws DecoderException { List<Row> rows = new ArrayList<>(); try { DynamicMessage message = DynamicMessage.parseFrom(descriptor, bytes); Row row = new Row(); decodeMessage(message, row, null); rows.add(row); } catch (InvalidProtocolBufferException e) { throw new DecoderException(e.getMessage()); } return rows; } ProtobufDecoderUsingDescriptor(byte[] bytes, String name); @Override List<Row> decode(byte[] bytes); }
ProtobufDecoderUsingDescriptor implements Decoder<Row> { @Override public List<Row> decode(byte[] bytes) throws DecoderException { List<Row> rows = new ArrayList<>(); try { DynamicMessage message = DynamicMessage.parseFrom(descriptor, bytes); Row row = new Row(); decodeMessage(message, row, null); rows.add(row); } catch (InvalidProtocolBufferException e) { throw new DecoderException(e.getMessage()); } return rows; } ProtobufDecoderUsingDescriptor(byte[] bytes, String name); @Override List<Row> decode(byte[] bytes);  }