1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.codec.delimited;
21
22 import java.io.IOException;
23 import java.nio.ByteBuffer;
24 import java.util.LinkedList;
25 import java.util.List;
26
27 import org.apache.mina.generated.protoc.AddressBookProtos.Person;
28 import org.apache.mina.util.ByteBufferOutputStream;
29
30
31
32
33
34
35 public class ProtobufTest extends DelimitTest<Person> {
36
37 @Override
38 public List<Person> getObjects() {
39
40 List<Person> list = new LinkedList<Person>();
41
42 list.add(Person.newBuilder().setId(1).setName("Jean Dupond").setEmail("john.white@bigcorp.com").build());
43 list.add(Person.newBuilder().setId(2).setName("Marie Blanc").setEmail("marie.blanc@bigcorp.com").build());
44
45 return list;
46 }
47
48 @Override
49 protected ByteBuffer delimitWithOriginal() throws IOException {
50 ByteBufferOutputStream bbos = new ByteBufferOutputStream();
51 bbos.setElastic(true);
52
53 for (Person p : getObjects()) {
54 p.writeDelimitedTo(bbos);
55 }
56 return bbos.getByteBuffer();
57 }
58
59 @Override
60 public SizePrefixedEncoder<Person> getSerializer() {
61 return ProtobufEncoder.newInstance(Person.class);
62 }
63 }