本文整理汇总了C++中Msg::add_fld方法的典型用法代码示例。如果您正苦于以下问题:C++ Msg::add_fld方法的具体用法?C++ Msg::add_fld怎么用?C++ Msg::add_fld使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Msg
的用法示例。
在下文中一共展示了Msg::add_fld方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: register_fields
void register_fields(Model& model, Msg& msg, VALUE type, VALUE mapping) {
VALUE deflators = rb_get(type, "deflators");
VALUE inflators = rb_get(type, "inflators");
for (VALUE rb_fld : arr2vec(rb_get(type, "fields"))) {
VALUE fld_name = rb_get(rb_fld, "name");
Fld fld;
fld.num = NUM2INT(rb_get(rb_fld, "num"));
fld.name = rb_sym_to_cstr(fld_name);
int fld_type = NUM2INT(rb_get(rb_fld, "type"));
fld.fld_type = fld_type;
if (fld_type == FLD_MESSAGE)
fld.embedded_msg = &get_msg_for_type(model, rb_get(rb_fld, "msg_class"));
fld.wire_type = wire_type_for_fld_type(fld_type);
fld.label = NUM2INT(rb_get(rb_fld, "label"));
if (fld.label == LABEL_REQUIRED)
msg.num_required_fields++;
fld.is_packed = RTEST(rb_get(rb_fld, "packed"));
fld.deflate = rb_hash_aref(deflators, fld_name);
keep_alive(model, fld.deflate);
fld.inflate = rb_hash_aref(inflators, fld_name);
keep_alive(model, fld.inflate);
fld.get_lazy_type = rb_get(rb_fld, "get_lazy_type");
keep_alive(model, fld.get_lazy_type);
if (fld_type == FLD_ENUM) {
fld.enum_module = rb_get(rb_fld, "msg_class");
keep_alive(model, fld.enum_module);
fld.enum_values = arr2vec(rb_get(fld.enum_module, "values"));
// (we don't need to keep_alive() Fixnums)
}
if (msg.target_is_hash) {
fld.target_key = rb_call1(rb_get(mapping, "get_target_key"), rb_fld);
keep_alive(model, fld.target_key);
} else {
VALUE tf = rb_call1(rb_get(mapping, "get_target_field"), rb_fld);
string target_field_name = TYPE(tf) == T_STRING ? RSTRING_PTR(tf) : rb_sym_to_cstr(tf);
fld.target_field_getter = rb_intern(target_field_name.c_str());
fld.target_field_setter = rb_intern((target_field_name + "=").c_str());
}
fld.write = get_val_writer(fld_type);
fld.read = get_val_reader(fld_type);
msg.add_fld(msg, fld);
}
}