代码之家  ›  专栏  ›  技术社区  ›  Zheng Wang

如何使用Ignite c++瘦客户端将自定义的十进制对象(例如由protobuf生成)编码为二进制格式

  •  0
  • Zheng Wang  · 技术社区  · 1 年前

    与Ignite Java客户端不同 https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/binary/BinaryWriter.html

    C++瘦客户端没有提供写/读十进制方法。 我想知道如何使用c++瘦客户端实现十进制。

    这是我的BinaryType类模板。

    namespace ignite { namespace binary {
    template <>
    struct BinaryType<some_namespace::Product> : BinaryTypeDefaultAll<some_namespace::Product> {
      static void GetTypeName(std::string& dst) { dst = "PRODUCT_OMS_V1_TYPE"; };
      static void Write(BinaryWriter& writer, const some_namespace::Product& obj)
      {
        writer.WriteInt32("id", obj.id());
        writer.WriteString("name", obj.name());
        writer.WriteObject<some_namespace::DecimalValue>("price", obj.price());
      };
      static void Read(BinaryReader& reader, some_namespace::Product& dst)
      {
        dst.set_id(reader.ReadInt32("id"));
        dst.set_name(reader.ReadString("name"));
        dst.mutable_price()->CopyFrom(reader.ReadObject<some_namespace::DecimalValue>("price"));
      };
    }} // namespace ignite::binary
    

    some_namespace::Product是我编译的protobuf消息

    message Product {
      int32 id = 1;
      string name = 2;
      DecimalValue price = 3;
    }
    
    message DecimalValue {
      int64 units = 1;
      int32 nanos = 2;
    }
    
    0 回复  |  直到 1 年前