I use the protocol buffer as a wired data format in a client-server architecture. Domain objects (java beans) will go through the next life cycle.
- Used in client-side business logic.
- Converted to protobuf format
- Sent to server
- Converted back to a domain object
- Used in server side business logic.
The "Protocol Buffers and OO Design" in the ProtoBuf documentation recommends wrapping the generated class inside the correct domain model.
I would like to find the best app.
For example, I have a simple proto definition.
package customer; option java_package = "com.example"; option java_outer_classname = "CustomerProtos"; message Customer { required string name = 1; optional string address = 2; }
This determines the domain model. As you can see, the data is completely stored in the proto-builder object.
package com.example; public class CustomerModel { private CustomerProtos.Customer.Builder builder = CustomerProtos.Customer.newBuilder(); public String getName() { return builder.getName(); } public void setName(String name) { builder.setName(name); } public String getAddress() { return builder.getAddress(); } public void setAddress(String address) { builder.setAddress(address); } public byte[] serialize() { return builder.build().toByteArray(); } }
Is this a good practice? because these objects are used at all stages of the life cycle, but we need a protocol format only in the client-server transfer phase.
Is there a performance issue when accessing the getter / setter methods of the proto builder class specifically when the prototype definition is complex and nested?
oop protocol-buffers
Sujee
source share