ptoto type | java type |
---|---|
double | double |
float | float |
int32 | int |
int64 | long |
uint32 | int[Note] |
uint64 | long[Note] |
sint32 | int |
sint64 | long |
fixed32 | int[Note] |
fixed64 | long[Note] |
sfixed32 | int |
sfixed64 | long |
bool | boolean |
string | String |
bytes | ByteString |
[Note] In Java, unsigned 32-bit and 64-bit integers are represented using their signed logarithms, with the top bit only stored in the sign bit.
enum TrafficLightColor {
TRAFFIC_LIGHT_COLOR_INVALID = 0;
TRAFFIC_LIGHT_COLOR_UNSET = 1;
TRAFFIC_LIGHT_COLOR_GREEN = 2;
TRAFFIC_LIGHT_COLOR_YELLOW = 3;
TRAFFIC_LIGHT_COLOR_RED = 4;
}
Enumerations are constants, so use uppercase
message VipIDToRidReq {
repeated uint32 vipID = 1;
}
The bottom layer is actually an ArrayList
PB does not support unordered and non-repeating collections, and can only borrow arrays to implement
, and needs to remove duplicates by itself
.
message BatchOnlineRes {
map<uint32, uint32> onlineMap = 1;//online status
}
message BatchAnchorInfoRes {
map<uint32, AnchorInfo> list = 1; //user information map list
}
/*
* The function of the corresponding interface: get user information in batches or individually
*/
message AnchorInfo {
uint32 ownerUid = 1 [json_name="uid"]; //user id
string nickName = 2 [json_name="nn"]; //User nickname
string smallAvatar = 3 [json_name="savt"]; //full path of user avatar - small
string middleAvatar = 4 [json_name="mavt"]; //Full path of user avatar - middle
string bigAvatar = 5 [json_name="bavt"]; //Full path of user avatar - big
string avatar = 6 [json_name="avt"]; //User avatar
}
Feature | Java Interface | Protobuf | Remarks |
---|---|---|---|
Method Overloading | √ | × | |
Generic/templated | √ | × | |
method inheritance | √ | × | |
Nested definition | √ | Partial support | PB only supports message and enum nesting |
import file | √ | √ | |
field is null | √ | × | |
Multiple input parameters | √ | × | PB only supports single input parameters |
0 input parameters | √ | × | PB must have input parameters |
0 output parameters | √ | × | PB must have output parameters |
The input/output parameters are abstract classes | √ | × | The input/output parameters of PB must be concrete classes |
The input/output parameters are interfaces | √ | × | The input/output parameters of PB must be concrete |
The input parameter/output parameter is the basic type | √ | × | The input parameter/output parameter of PB must be a structure |