<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          ASP.NET Core中使用Protobuf從入門到實戰(zhàn)

          共 1167字,需瀏覽 3分鐘

           ·

          2021-02-07 03:50

          一、Protocol Buffers簡介和特點

          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ù)大小和傳輸速率比較敏感的場合使用。

          0be999f5422376b88a5ce35e471cd190.webp

          二、Protobuf協(xié)議文件(proto3)指南

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

          5e6b8ae2fe21e238f6abfbb9c918f715.webp

          三、如何將.proto文件生成C#類文件

          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/

          四、ASP.NET Core中使用Protobuf格式作為數(shù)據(jù)交換

          1、請求=》PB》反序列化為對象—請求數(shù)據(jù)

          2、響應(yīng)=》響應(yīng)的數(shù)據(jù)》序列化為PB格式

          b1bbfb2cb315c8a1c6834e916c88506b.webp

          五、NET Core客戶端調(diào)用Protobuf格式的WebApi

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

          ?https://github.com/protobuf-net/protobuf-net

          09bbd7b693e7293531e8c89e7265da2c.webp

          fcfb1927708640f55bb1f1e685d7a0ad.webp

          對這塊知識感興趣的話,可以學(xué)習(xí)一下阿笨的課程!

          我們不生產(chǎn)干貨,我們只是干貨的搬運工!

          ASP.NET Core中使用Protobuf從入門到實戰(zhàn)

          1054047de822d26b4ece4a0a52e6a8c2.webp

          瀏覽 79
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  懂色av无码任你操久久久久蜜桃av | 亚洲V无码| jizz中国成熟丰满女人 | 伊人色色综合网 | 欧美中日韩在线 |