首页 > 技术文章 > Protobuf 数据类型

puke 2017-05-16 17:01 原文

 

.proto Type

  Notes C++ Type Java Type
double    double  double
float    float  float
int32 Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead.  int32  int
int64 Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead.  int64  long
uint32 Uses variable-length encoding.  uint32  int
uint64 Uses variable-length encoding.  uint64  long
sint32 Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s.  int32  int
sint64 Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s.   int64  long
fixed32 Always four bytes. More efficient than uint32 if values are often greater than 228  uint32  int
fixed64 Always eight bytes. More efficient than uint64 if values are often greater than 256.  uint64  long
sfixed32 Always four bytes.  int32  int
sfixed64 Always eight bytes.  int64  long
bool    bool  boolean
string A string must always contain UTF-8 encoded or 7-bit ASCII text.  string  String
bytes May contain any arbitrary sequence of bytes. string ByteString

 

 

 public static Dictionary<string, string> MySqlToProbuffer = new Dictionary<string, string>()
        {
            {"varchar", "string"},
            {"longtext", "string"},
            {"text", "string"},
            {"char", "string"},
            {"mediumtext", "string"},
            {"bigint", "int64"},
            {"datetime", "int64"},
            {"timestamp", "int64"},
            {"int", "int32"},
            {"tinyint", "int32"},
            {"smallint", "int32"},
            {"decimal", "double"},
            {"double", "double"},
            {"float", "float"},
            {"bit", "bool"},
            {"blob", "bytes"},
            {"longblob", "bytes"},
            {"varbinary", "bytes"},
            {"binary", "bytes"}
        };

        public static Dictionary<string, string> ProbufferToJava = new Dictionary<string, string>()
        {
            {"string", "String"},
            {"int32", "Integer"},
            {"int64", "Long"},
            {"double", "Double"},
            {"float", "Float"},
            {"bool", "Boolean"},
            {"bytes", "ByteString"},
            {"uint32", "Integer"},
            {"uint64", "Long"},
            {"sint32", "Integer"},
            {"sint64", "Long"},
            {"fixed32", "Integer"},
            {"fixed64", "Long"},
            {"sfixed32", "Integer"},
            {"sfixed64", "Long"},
        };

 

推荐阅读