コード例 #1
0
ファイル: encode_decode.c プロジェクト: Holygitzdq/ElVis
// Handler to end a map entry: inserts the value defined during the message into
// the map. This is the 'endmsg' handler on the map entry msgdef.
static bool endmap_handler(void *closure, const void *hd, upb_status* s) {
    map_parse_frame_t* frame = closure;
    const map_handlerdata_t* mapdata = hd;

    VALUE key = native_slot_get(
                    mapdata->key_field_type, Qnil,
                    &frame->key_storage);

    VALUE value_field_typeclass = Qnil;
    VALUE value;

    if (mapdata->value_field_type == UPB_TYPE_MESSAGE ||
            mapdata->value_field_type == UPB_TYPE_ENUM) {
        value_field_typeclass = get_def_obj(mapdata->value_field_subdef);
    }

    value = native_slot_get(
                mapdata->value_field_type, value_field_typeclass,
                &frame->value_storage);

    Map_index_set(frame->map, key, value);
    free(frame);

    return true;
}
コード例 #2
0
ファイル: map.c プロジェクト: Livefyre/protobuf
static int merge_into_self_callback(VALUE key, VALUE value, VALUE self) {
  Map_index_set(self, key, value);
  return ST_CONTINUE;
}