1.代码
Student.Builder builder = Student.newBuilder(); builder.setId(1); builder.setName("段小秋"); builder.setEmail("31346337@qq.com"); //序列化 Student stu = builder.build(); System.out.println(stu); byte[] data = stu.toByteArray(); Student student = Student.parseFrom(data); System.out.println(student);
参考上一节:protobuf 使用