cheneydog
V2EX  ›  问与答

protobuf 在 Server 端这里怎么设计反序列化?

  •  
  •   cheneydog · Mar 9, 2020 · 1966 views
    This topic created in 2441 days ago, the information mentioned may be changed or developed.

    看到的例子都是在既定类上调用 parseFrom,对于 client 端没问题,对于 server 端,不知道是哪条消息过来了如何解。

    所以 protobuf 如何设计,server 端如何用的最佳实践是?

    3 replies  •  2020-03-09 11:45:25 +08:00
    JerryLee13
    JerryLee13
    Mar 9, 2020 via iPhone
    1
    服务端和客户端约定好,比如说前 4 个字节为特定标志,然后再接上序列化好的内容。。。
    cheneydog
    cheneydog
    OP
    Mar 9, 2020
    2
    import "google/protobuf/any.proto";
    cheneydog
    cheneydog
    OP
    Mar 9, 2020
    3
    用泛型解决了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1907 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:16 · PVG 08:16 · LAX 16:16 · JFK 19:16
    ♥ Do have faith in what you're doing.