当前位置 : 主页 > 大数据 > 区块链 >

protobuf抓包总结

来源:互联网 收集:自由互联 发布时间:2021-06-22
charles工具看到的类型: double 64-bit float 32-bit int32 Varint int64 Varint uint32 Varint uint64 Varint sint32 Varint(值错误) sint64 Varint(值错误) fixed32 32-bit fixed64 64-bit sfixed32 32-bit sfixed64 64-bit bool Vari

charles工具看到的类型:

double 64-bit
float         32-bit
int32 Varint
int64 Varint
uint32 Varint
uint64 Varint
sint32 Varint(值错误)
sint64 Varint(值错误)
fixed32 32-bit
fixed64 64-bit
sfixed32         32-bit
sfixed64         64-bit
bool         Varint(0,1) 
string Length-delimited
bytes

发送包

1.required字段必须赋值,否则会崩溃。
1.int32,int64在发送包层面结果是一样的。
2.optional字段在发送包层面,是允许不存在的。


接送包

1.proto可以部分字段还原,不影响解析
2.int32,int64不影响解析。
3.optional,required不影响解析。
4.可以增加optional字段,不影响解析。
message ViewLayer{
optional int32 key = 1;
optional string name = 2;
optional int32 focus = 3;
optional string path = 4;
optional int32 pageType = 5;
optional int32 catPageKey = 6;
optional string addTest = 7;
optional string layerName = 127;
}
5.不可以增加required字段,会崩溃。
message ViewLayer{
optional int32 key = 1;
optional string name = 2;
optional int32 focus = 3;
optional string path = 4;
optional int32 pageType = 5;
optional int32 catPageKey = 6;
required string addTest = 7;
optional string layerName = 127;
}
崩溃提示

com.google.protobuf.InvalidProtocolBufferException: Message missing required fields: module[0].viewLayer[0].addTest, module[1].viewLayer[0].addTest。。。



还原proto的经验:

public final class Proto$Transfer$Entity extends GeneratedMessageLite implements MCSProto$Transfer$AppInfoEntityOrBuilder {
    public static final int APPPKGNAME_FIELD_NUMBER = 1;
    public static final int APPVERSIONCODE_FIELD_NUMBER = 2;
    public static final int APPVERSIONNAME_FIELD_NUMBER = 3;
    public static final int HASACTIVATED_FIELD_NUMBER = 5;
    public static final int ISHOSTAPP_FIELD_NUMBER = 6;
    public static final int SDKVERSION_FIELD_NUMBER = 4;
    private Object appPkgName_;
    private int appVersionCode_;
    private Object appVersionName_;
    private int bitField0_;
    private static final MCSProto$Transfer$AppInfoEntity defaultInstance;
    private boolean hasActivated_;
    private boolean isHostApp_;
    private byte memoizedIsInitialized;
    private int memoizedSerializedSize;
    private int sdkVersion_;

    private static final long serialVersionUID;


关键字:GeneratedMessageLite

类是Proto$Transfer$Entity,而不是Proto$Transfer$Entity$Builder

Object == string

boolean == bool

int == int32

long == int64

网友评论