ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
tools_pb_field.h File Reference

Protobuf字段反射辅助工具 More...

#include "actor/protocol/nprotocol_template.h"
#include "tools/tools.h"
#include "tools/type.h"
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/message.h>
#include <unordered_set>
#include <vector>

Classes

class  ngl::tools::pb_field
 Protobuf字段反射辅助工具类 More...

Namespaces

namespace  ngl::tools
 工具函数命名空间。

Enumerations

enum  { ngl::tools::epb_mid = 1 }
 Protobuf结构标识常量 More...

Detailed Description

Protobuf字段反射辅助工具

提供Protobuf消息的字段级操作,包括:

  • 按字段编号选择性拷贝
  • 字段编号与名称的映射查询
  • 支持基础类型、repeated字段和嵌套消息类型
    Note
    所有类和函数均位于 ngl::tools 命名空间下。
    // 选择性字段拷贝示例
    MyMessage src, dst;
    std::map<int, ngl::tools::epb_field> field_map;
    field_map[1] = ngl::tools::epb_field::some_field;
    ngl::tools::pb_field::copy(src, &dst, field_map, true);
    // 获取字段编号示例
    std::map<int, std::string> field_map;
    ngl::tools::pb_field::field_numbers<MyMessage>(field_map);