ASP.NET Core中使用Protobuf從入門到實戰(zhàn)
1、Protocol Buffers簡介
ProtoBuf (Google Protocol Buffer)是由google公司用于數(shù)據(jù)交換的序列結(jié)構(gòu)化數(shù)據(jù)格式,具有跨平臺、跨語言、可擴(kuò)展特性,類型于常用的XML及JSON,但具有更小的傳輸體積、更高的編碼、解碼能力,特別適合于數(shù)據(jù)存儲、網(wǎng)絡(luò)數(shù)據(jù)傳輸?shù)葘Υ鎯w積、實時性要求高的領(lǐng)域。?
2、Protocol Buffers特點
? ? ? ? XML、JSON是目前常用的數(shù)據(jù)交換格式,它們可讀性較好。但序列化后的數(shù)據(jù)字節(jié)很大,序列化和反序列化的時間較長,數(shù)據(jù)傳輸效率不高。
? ? ? ? Protobuf和Xml、Json序列化的方式不同,采用了二進(jìn)制字節(jié)的序列化方式,用字段索引和字段類型通過算法計算得到字段之前的關(guān)系映射,從而達(dá)到更高的時間效率和空間效率,特別適合對數(shù)據(jù)大小和傳輸速率比較敏感的場合使用。

ProtoBuf 有兩個語言版本:v2 與 v3,截止目前在使用 v3 的時候,需要在 *.proto 文件首行中明文標(biāo)識syntax="proto3";
否則默認(rèn)為 syntax="proto2"; 推薦使用最新的syntax = "proto3";語法。

四、ASP.NET Core中使用Protobuf格式作為數(shù)據(jù)交換1、方法一:protogen - npm cnmp ?install -g protogen
https://www.npmjs.com/package/protogen語法:protogen -i:input.proto -o:output.cs
方法二:通過源碼編譯C# protogen?
下載地址:https://github.com/protobuf-net/protobuf-net/tags方法三:Protogen官網(wǎng)是支持在線生成的。?
網(wǎng)址 :https://protogen.marcgravell.com/
1、請求=》PB》反序列化為對象—請求數(shù)據(jù)
2、響應(yīng)=》響應(yīng)的數(shù)據(jù)》序列化為PB格式

protobuf-net/protobuf-net: Protocol Buffers library for idiomatic .NET?
?https://github.com/protobuf-net/protobuf-net


對這塊知識感興趣的話,可以學(xué)習(xí)一下阿笨的課程!
我們不生產(chǎn)干貨,我們只是干貨的搬運工!
《ASP.NET Core中使用Protobuf從入門到實戰(zhàn)》

