Skip to content

Commit e4a67f3

Browse files
author
Furkan Danismaz
committed
Protobuf Serialization & Parse
1 parent 6da681a commit e4a67f3

5 files changed

Lines changed: 229 additions & 200 deletions

File tree

protobuf/output

38 Bytes
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fd.protobuf;
2+
3+
import com.fd.protobuf.proto.AddressBookProtos;
4+
5+
import java.io.*;
6+
7+
public class App {
8+
9+
public static void main(String[] args) throws IOException {
10+
AddressBookProtos.Person furkan = AddressBookProtos.Person.newBuilder()
11+
.setId(123)
12+
.setName("furkan danismaz")
13+
.setEmail("...")
14+
.addPhones(
15+
AddressBookProtos.Person.PhoneNumber.newBuilder()
16+
.setNumber("555-1234")
17+
.setType(AddressBookProtos.Person.PhoneType.MOBILE)
18+
.build())
19+
.build();
20+
21+
OutputStream os = new FileOutputStream(new File("./output"));
22+
furkan.writeTo(os);
23+
24+
InputStream is = new FileInputStream(new File("./output"));
25+
AddressBookProtos.Person parsedPerson = AddressBookProtos.Person.parseFrom(is);
26+
27+
System.out.println(parsedPerson);
28+
}
29+
}

0 commit comments

Comments
 (0)