cheneydog
V2EX  ›  问与答

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

  •  
  •   cheneydog · Mar 9, 2020 · 1640 views
    This topic created in 2264 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
        1
    JerryLee13  
       Mar 9, 2020 via iPhone
    服务端和客户端约定好,比如说前 4 个字节为特定标志,然后再接上序列化好的内容。。。
    cheneydog
        2
    cheneydog  
    OP
       Mar 9, 2020
    import "google/protobuf/any.proto";
    cheneydog
        3
    cheneydog  
    OP
       Mar 9, 2020
    用泛型解决了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1179 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 23:18 · PVG 07:18 · LAX 16:18 · JFK 19:18
    ♥ Do have faith in what you're doing.