コード例 #1
0
ファイル: hosts_config.cpp プロジェクト: mailru/icqdesktop
    bool hosts_map::unserialize(const tools::tlvpack& _pack)
    {
        auto tlv_scheme = _pack.get_item(host_config_types::hct_active_scheme);
        if (tlv_scheme)
        {
            active_scheme_ = tlv_scheme->get_value<bool>();
        }

        auto tlv_hosts = _pack.get_item(host_config_types::hct_hosts);
        if (tlv_hosts)
        {
            tools::tlvpack pack_hosts = tlv_hosts->get_value<tools::tlvpack>();

            for (auto tlv_host = pack_hosts.get_first(); tlv_host; tlv_host = pack_hosts.get_next())
            {
                tools::tlvpack pack_host = tlv_host->get_value<tools::tlvpack>();

                auto tlv_key = pack_host.get_item(host_config_types::hct_host_key);
                auto tlv_alt = pack_host.get_item(host_config_types::hct_host_alt);

                if (tlv_key && tlv_alt)
                {
                    hosts_[pack_string(tlv_key->get_value<std::string>())] = pack_string(tlv_alt->get_value<std::string>());
                }
            }
        }


        return true;
    }
コード例 #2
0
ファイル: net_agent.hpp プロジェクト: Dzshiftt/Gnomescroll
 inline void packet(char* buff, size_t* buff_n, bool pack)
 {
     pack_u8(&id, buff, buff_n, pack);
     pack_u8(&client_id, buff, buff_n, pack);
     pack_color(&color, buff, buff_n, pack);
     pack_string(username, PLAYER_NAME_MAX_LENGTH+1, buff, buff_n, pack);
 }
コード例 #3
0
ファイル: DiffingTool.cpp プロジェクト: rainiscold/trilinos
void pack_part_names(stk::CommBuffer& buf, const stk::mesh::PartVector& parts)
{
    for(size_t i=0; i<parts.size(); ++i)
    {
        pack_string(buf, parts[i]->name());
    }
}
コード例 #4
0
ファイル: MetaServerPacket.cpp プロジェクト: 9cat/cyphesis
unsigned int
MetaServerPacket::addPacketData(const std::string& s)
{
	unsigned int ret_off = m_writePtr - m_headPtr;
	m_writePtr = pack_string( s , m_writePtr );
	return ret_off;
}
コード例 #5
0
ファイル: pack_p.cpp プロジェクト: SGbo/qmsgpack
quint8 *MsgPackPrivate::pack_stringlist(const QStringList &list, quint8 *p, bool wr)
{
    int len = list.length();
    p = pack_arraylen(len, p, wr);
    foreach (QString item, list)
        p = pack_string(item, p, wr);
    return p;
}
コード例 #6
0
ファイル: hosts_config.cpp プロジェクト: mailru/icqdesktop
    void hosts_map::serialize(tools::tlvpack& _pack) const
    {
        _pack.push_child(tools::tlv(host_config_types::hct_active_scheme, active_scheme_));

        tools::tlvpack pack_hosts;

        for (const auto& _host : hosts_)
        {
            tools::tlvpack pack_host;

            pack_host.push_child(core::tools::tlv(host_config_types::hct_host_key, pack_string(_host.first)));
            pack_host.push_child(core::tools::tlv(host_config_types::hct_host_alt, pack_string(_host.second)));

            pack_hosts.push_child(core::tools::tlv(host_config_types::hct_host, pack_host));
        }

        _pack.push_child(tools::tlv(host_config_types::hct_hosts, pack_hosts));
    }
コード例 #7
0
ファイル: rbkit_event_packer.c プロジェクト: alfie-max/rbkit
static void pack_cpu_sample_event(rbkit_cpu_sample_event *event, msgpack_packer *packer) {
  rbkit_cpu_sample *sample;
  size_t count;

  msgpack_pack_map(packer, 3);
  sample = event->sample;

  // Keys 1 & 2 - event type and timestamp
  pack_event_header(packer, event->event_header.event_type);

  // Key 3 : Payload
  msgpack_pack_int(packer, rbkit_message_field_payload);
  // Value 3: Array of samples
  msgpack_pack_array(packer, sample->frame_count);

  for(count = 0; count != sample->frame_count; count++){
    msgpack_pack_map(packer, 6);

    // method_name
    msgpack_pack_int(packer, rbkit_message_field_method_name);
    pack_string(packer, sample->frames[count].method_name);

    // label
    msgpack_pack_int(packer, rbkit_message_field_label);
    pack_string(packer, sample->frames[count].label);

    // file
    msgpack_pack_int(packer, rbkit_message_field_file);
    pack_string(packer, sample->frames[count].file);

    // line
    msgpack_pack_int(packer, rbkit_message_field_line);
    msgpack_pack_unsigned_long(packer, sample->frames[count].line);

    // singleton_method
    msgpack_pack_int(packer, rbkit_message_field_singleton_method);
    msgpack_pack_int(packer, sample->frames[count].is_singleton_method);

    // thread_od
    msgpack_pack_int(packer, rbkit_message_field_thread_id);
    msgpack_pack_unsigned_long(packer, sample->frames[count].thread_id);
  }
}
コード例 #8
0
ファイル: DiffingTool.cpp プロジェクト: rainiscold/trilinos
void pack_part_names_except(stk::CommBuffer& buf, const stk::mesh::PartVector& parts, stk::mesh::Part* skipPart)
{
    for(size_t i=0; i<parts.size(); ++i)
    {
        if (skipPart==nullptr || parts[i]->mesh_meta_data_ordinal() != skipPart->mesh_meta_data_ordinal())
        {
            pack_string(buf, parts[i]->name());
        }
    }
}
コード例 #9
0
static void init(grib_accessor* a, const long len, grib_arguments* params) {
  int n=0;
  grib_accessor_codetable* self  = (grib_accessor_codetable*)a;
  grib_action* act=(grib_action*)(a->creator);

  self->tablename = grib_arguments_get_string(a->parent->h,params,n++);
  self->masterDir = grib_arguments_get_name(a->parent->h,params,n++);
  self->localDir = grib_arguments_get_name(a->parent->h,params,n++);

  /*if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE)
    printf("-------- %s type string (%ld)\n",a->name,a->flags);*/

  if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) {
    a->length = 0;
	if (!a->vvalue) 
		a->vvalue = grib_context_malloc_clear(a->parent->h->context,sizeof(grib_virtual_value));
    a->vvalue->type=grib_accessor_get_native_type(a);
    a->vvalue->length=len;
    if (act->default_value!=NULL) {
      const char* p = 0;
      size_t len = 1;
      long l;
      int ret=0;
      double d;
      char tmp[1024];
      grib_expression* expression=grib_arguments_get_expression(a->parent->h,act->default_value,0);
      int type = grib_expression_native_type(a->parent->h,expression);
      switch(type) {
        case GRIB_TYPE_DOUBLE:
          grib_expression_evaluate_double(a->parent->h,expression,&d);
          grib_pack_double(a,&d,&len);
          break;

        case GRIB_TYPE_LONG:
          grib_expression_evaluate_long(a->parent->h,expression,&l);
          grib_pack_long(a,&l,&len);
          break;

        default:
          len = sizeof(tmp);
          p = grib_expression_evaluate_string(a->parent->h,expression,tmp,&len,&ret);
          if (ret != GRIB_SUCCESS) {
			  grib_context_log(a->parent->h->context,GRIB_LOG_FATAL,
							   "unable to evaluate %s as string",a->name);
          }
          len = strlen(p)+1;
          pack_string(a,p,&len);
          break;
      }
    }
  } else
    a->length = len;

}
コード例 #10
0
static int pack_long(grib_accessor* a, const long* val, size_t *len)
{
    char buf[80];
    size_t s;
    sprintf(buf,"%ld",*val);
#if 0
    if(*len > 1)
        return GRIB_NOT_IMPLEMENTED;
#endif
    s = strlen(buf)+1;
    return pack_string(a,buf,&s);
}
コード例 #11
0
ファイル: rbkit_event_packer.c プロジェクト: alfie-max/rbkit
static void pack_obj_created_event(rbkit_obj_created_event *event, msgpack_packer *packer) {
  msgpack_pack_map(packer, 3);
  pack_event_header(packer, event->event_header.event_type);

  msgpack_pack_int(packer, rbkit_message_field_payload);
  msgpack_pack_map(packer, 2);
  msgpack_pack_int(packer, rbkit_message_field_object_id);
  msgpack_pack_unsigned_long_long(packer, event->object_id);
  msgpack_pack_int(packer, rbkit_message_field_class_name);
  pack_string(packer, event->klass);
  //TODO: pack allocation info as well
}
コード例 #12
0
ファイル: resultfile.cpp プロジェクト: mfranberg/besiq
bool
bresultfile::set_header(const std::vector<std::string> &col_names)
{
    if( m_fp == NULL )
    {
        return false;
    }

    fseek( m_fp, 0L, SEEK_SET );
    m_col_names = col_names;
    
    std::string packed_snp_names = pack_string( m_snp_names );
    std::string packed_col_names = pack_string( m_col_names );

    m_header.snp_names_length = packed_snp_names.size( ) + 1;
    m_header.col_names_length = packed_col_names.size( ) + 1;
    m_header.num_float_cols = m_col_names.size( );

    size_t bytes_written = fwrite( &m_header, sizeof( result_header ), 1, m_fp );
    if( bytes_written != 1 )
    {
        return false;
    }

    bytes_written = fwrite( packed_snp_names.c_str( ), 1, m_header.snp_names_length, m_fp );
    if( bytes_written != m_header.snp_names_length )
    {
        return false;
    }

    bytes_written = fwrite( packed_col_names.c_str( ), 1, m_header.col_names_length, m_fp );
    if( bytes_written != m_header.col_names_length )
    {
        return false;
    }

    return true;
}
コード例 #13
0
ファイル: pack_helper.c プロジェクト: cmusatyalab/coda
int pack_struct_MultiCallEntry(BUFFER *buf, MultiCallEntry *ptr)
{
    if (pack_string(buf, ptr->name))
        return -1;
    if (pack_integer(buf, ptr->countent))
        return -1;
    if (pack_integer(buf, ptr->countexit))
        return -1;
    if (pack_integer(buf, ptr->tsec))
        return -1;
    if (pack_integer(buf, ptr->tusec))
        return -1;
    if (pack_integer(buf, ptr->counttime))
        return -1;
    return 0;
}
コード例 #14
0
ファイル: sph.c プロジェクト: KonstantinosKr/solfec
/* pack sphere into double and integer buffers (d and i buffers are of initial
 * dsize and isize, while the final numberof of doubles and ints is packed) */
void SPHERE_Pack (SPHERE *sph, int *dsize, double **d, int *doubles, int *isize, int **i, int *ints)
{
  pack_int (isize, i, ints, sph->surface);
  pack_int (isize, i, ints, sph->volume);

  pack_doubles (dsize, d, doubles, sph->cur_center, 3);
  pack_doubles (dsize, d, doubles, (double*)sph->cur_point, 9);
  pack_double  (dsize, d, doubles, sph->cur_radius);

  pack_doubles (dsize, d, doubles, sph->ref_center, 3);
  pack_doubles (dsize, d, doubles, (double*)sph->ref_point, 9);
  pack_double  (dsize, d, doubles, sph->ref_radius);

  pack_int (isize, i, ints, sph->mat ? 1 : 0); /* pack material existence flag */
  if (sph->mat) pack_string (isize, i, ints, sph->mat->label);
}
コード例 #15
0
ファイル: rbkit_event_packer.c プロジェクト: alfie-max/rbkit
static void pack_value_object(msgpack_packer *packer, VALUE value) {
  VALUE rubyString;
  char *keyString;
  switch (TYPE(value)) {
    case T_FIXNUM:
      msgpack_pack_long(packer, FIX2LONG(value));
      break;
    case T_FLOAT:
      msgpack_pack_double(packer, rb_num2dbl(value));
      break;
    default:
      rubyString = rb_funcall(value, rb_intern("to_s"), 0, 0);
      keyString = StringValueCStr(rubyString);
      pack_string(packer, keyString);
      break;
  }
}
コード例 #16
0
ファイル: pack_p.cpp プロジェクト: SGbo/qmsgpack
quint8 *MsgPackPrivate::pack(const QVariant &v, quint8 *p, bool wr, QVector<QByteArray> &user_data)
{
    QMetaType::Type t = (QMetaType::Type)v.type();
    if (v.isNull() && !v.isValid())
        p = pack_nil(p, wr);
    else if (t == QMetaType::Int)
        p = pack_int(v.toInt(), p, wr);
    else if (t == QMetaType::UInt)
        p = pack_uint(v.toUInt(), p, wr);
    else if (t == QMetaType::Bool)
        p = pack_bool(v, p, wr);
    else if (t == QMetaType::QString)
        p = pack_string(v.toString(), p, wr);
    else if (t == QMetaType::QVariantList)
        p = pack_array(v.toList(), p, wr, user_data);
    else if (t == QMetaType::QStringList)
        p = pack_stringlist(v.toStringList(), p, wr);
    else if (t == QMetaType::LongLong)
        p = pack_longlong(v.toLongLong(), p, wr);
    else if (t == QMetaType::ULongLong)
        p = pack_ulonglong(v.toULongLong(), p, wr);
    else if (t == QMetaType::Double)
        p = pack_double(v.toDouble(), p, wr);
    else if (t == QMetaType::Float)
        p = pack_float(v.toFloat(), p, wr);
    else if (t == QMetaType::QByteArray)
        p = pack_bin(v.toByteArray(), p, wr);
    else if (t == QMetaType::QVariantMap)
        p = pack_map(v.toMap(), p, wr, user_data);
    else {
        if (t == QMetaType::User)
            t = (QMetaType::Type)v.userType();
        QReadLocker locker(&packers_lock);
        bool has_packer = user_packers.contains(t);
        if (has_packer)
            has_packer &= user_packers[t].packer != 0;
        locker.unlock();
        if (has_packer)
            p = pack_user(v, p, wr, user_data);
        else
            qWarning() << "MsgPack::pack can't pack type:" << t;
    }

    return p;
}
コード例 #17
0
static void
sem_object_end(void *state)
{
	PackState		_state = (PackState) state;
	msgpack_sbuffer	*buf;
	JsonContainer	current_container, parent_container;
	msgpack_packer 	*pk;
	JsonObjectField	field;
	size_t			packed_size;
	char			*packed_data;
	JsonValue		value;

	current_container = _state->current_container;
	pk = _state->pk;

	/* start to pack map */
	msgpack_pack_map(pk, current_container->via.object.length);

	/* pack each field */
	field = current_container->via.object.start;
	while (field != NULL) {
		/* pack key */
		pack_string(pk, field->key);
		/* pack value */
		pack_value(pk, field->value);
		/* next field*/
		field = field->next;
	}

	/* retrieve packed binary and reset buffer of packer */
	buf = _state->buf;
	packed_size = buf->size;
	packed_data = msgpack_sbuffer_release(buf);

	/* set packed binary to the last value of parent conationer */
	parent_container = current_container->parent;
	value = value_to_be_set(parent_container);
	value->type = MSGPACK_BINARY;
	value->via.msg.size = packed_size;
	value->via.msg.data = packed_data;

	/* step back to parent level */
	_state->current_container = parent_container;
	destroy_container(current_container);
}
コード例 #18
0
ファイル: message.c プロジェクト: splone/splonebox-core
int message_serialize_request(struct message_request *req,
    msgpack_packer *pk)
{
  if (!pk || !req)
    return (-1);

  msgpack_pack_array(pk, 4);
  pack_uint8(pk, MESSAGE_TYPE_REQUEST);
  pack_uint32(pk, req->msgid);

  if (req->method.str == NULL || (pack_string(pk, req->method) == -1))
    return (-1);

  if (pack_params(pk, req->params) == -1)
    return (-1);

  return (0);
}
コード例 #19
0
ファイル: eli.c プロジェクト: tkoziara/solfec
/* pack ellipsoid into double and integer buffers (d and i buffers are of initial
 * dsize and isize, while the final numberof of doubles and ints is packed) */
void ELLIP_Pack (ELLIP *eli, int *dsize, double **d, int *doubles, int *isize, int **i, int *ints)
{
  pack_int (isize, i, ints, eli->surface);
  pack_int (isize, i, ints, eli->volume);

  pack_doubles (dsize, d, doubles, eli->cur_center, 3);
  pack_doubles (dsize, d, doubles, (double*)eli->cur_point, 9);

  pack_doubles (dsize, d, doubles, eli->ref_center, 3);
  pack_doubles (dsize, d, doubles, (double*)eli->ref_point, 9);

  pack_doubles (dsize, d, doubles, eli->ref_sca, 3);
  pack_doubles (dsize, d, doubles, eli->ref_rot, 9);

  pack_doubles (dsize, d, doubles, eli->cur_sca, 3);
  pack_doubles (dsize, d, doubles, eli->cur_rot, 9);

  pack_int (isize, i, ints, eli->mat ? 1 : 0); /* pack material existence flag */
  if (eli->mat) pack_string (isize, i, ints, eli->mat->label);
}
コード例 #20
0
static inline void
pack_scalar(msgpack_packer *pk, const JsonValueScalar scalar)
{
	switch (scalar.token_type) {
		case JSON_TOKEN_STRING:
			pack_string(pk, scalar.token);
			break;
		case JSON_TOKEN_NUMBER:
			pack_number(pk, scalar.token);
			break;
		case JSON_TOKEN_TRUE:
			msgpack_pack_true(pk);
			break;
		case JSON_TOKEN_FALSE:
			msgpack_pack_false(pk);
			break;
		case JSON_TOKEN_NULL:
			msgpack_pack_nil(pk);
			break;
		default:
			/* TODO: parse error */
			break;
	}
}
コード例 #21
0
ファイル: fc_pack.c プロジェクト: Comanche93/eech
void pack_local_force_data (entity *en, pack_modes mode)
{

	int
		count,
		loop;

	force
		*raw;

	campaign_criteria_type
		*campaign_criteria;

	ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES));

	ASSERT (en);

	raw = (force *) get_local_entity_data (en);
	
	switch (mode)
	{
		////////////////////////////////////////
		case PACK_MODE_SERVER_SESSION:
		////////////////////////////////////////
		{
         pack_string (en, STRING_TYPE_FORCE_NAME, raw->force_name);

			// keysite_force
	
			// pilot	root
	
			pack_list_root (en, LIST_TYPE_DIVISION, &raw->division_root);
	
			pack_list_root (en, LIST_TYPE_CAMPAIGN_OBJECTIVE, &raw->campaign_objective_root);
	
			// air_registry_root
			// ground_registry_root
			// sea_registry_root

//			pack_list_root (en, LIST_TYPE_INDEPENDENT_GROUP, &raw->independent_group_root);
	
			// force_link
		
			// update link
		
			// task generation //////////////////////////////////////////////
		
			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_TASKS; loop ++)
			{
				pack_int_value (en, INT_TYPE_VALID, raw->task_generation [loop].valid);

				pack_int_value (en, INT_TYPE_TASK_GENERATION, raw->task_generation [loop].created);
			}
			/////////////////////////////////////////////////////////////////
		
			// campaign criteria ////////////////////////////////////////////
		
			count = 0;
		
			campaign_criteria = raw->campaign_criteria;
		
			while (campaign_criteria)
			{
				count ++;
		
				campaign_criteria = campaign_criteria->next;
			}
		
			pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_COUNT, count);
		
			campaign_criteria = raw->campaign_criteria;
		
			while (campaign_criteria)
			{
		
				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_TYPE, campaign_criteria->criteria_type);
		
				pack_int_value (en, INT_TYPE_VALID, campaign_criteria->valid);
		
				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_RESULT, campaign_criteria->result);
		
				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE, campaign_criteria->value1);
		
				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE, campaign_criteria->value2);
		
				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE, campaign_criteria->value3);
		
				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE, campaign_criteria->value4);
		
				campaign_criteria = campaign_criteria->next;
			}
			/////////////////////////////////////////////////////////////////
		
			// force_info_criteria
		
			for (loop = 0; loop < NUM_FORCE_INFO_CATAGORIES; loop ++)
			{
				pack_int_value (en, INT_TYPE_VALUE, raw->force_info_current_hardware [loop]);
		
				pack_int_value (en, INT_TYPE_VALUE, raw->force_info_reserve_hardware [loop]);
			}
			/////////////////////////////////////////////////////////////////
	
			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_GROUPS; loop ++)
			{
				pack_int_value (en, INT_TYPE_VALUE, raw->kills [loop]);
				pack_int_value (en, INT_TYPE_VALUE, raw->losses [loop]);
//				pack_int_value (en, INT_TYPE_VALUE, raw->group_count [loop]);
			}

			pack_float_value (en, FLOAT_TYPE_SLEEP, raw->sleep);
		
			pack_int_value (en, INT_TYPE_FORCE_ATTITUDE, raw->force_attitude);

			// sector_count
		
			pack_int_value (en, INT_TYPE_COLOUR, raw->colour);
		
			pack_int_value (en, INT_TYPE_SIDE, raw->side);
	
			break;
		}

		////////////////////////////////////////
		case PACK_MODE_CLIENT_SESSION:
		////////////////////////////////////////
		{

         pack_string (en, STRING_TYPE_FORCE_NAME, raw->force_name);

			// keysite_force
	
			pack_list_root (en, LIST_TYPE_PILOT, &raw->pilot_root);

			pack_list_root (en, LIST_TYPE_DIVISION, &raw->division_root);

			pack_list_root (en, LIST_TYPE_CAMPAIGN_OBJECTIVE, &raw->campaign_objective_root);

			//	air_registry_root
			//	ground_registry_root
			//	sea_registry_root

//			pack_list_root (en, LIST_TYPE_INDEPENDENT_GROUP, &raw->independent_group_root);
	
			pack_list_link (en, LIST_TYPE_FORCE, &raw->force_link);

			// update link

			// task generation //////////////////////////////////////////////

			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_TASKS; loop ++)
			{
				pack_int_value (en, INT_TYPE_VALID, raw->task_generation [loop].valid);

				pack_int_value (en, INT_TYPE_TASK_GENERATION, raw->task_generation [loop].created);
			}
			/////////////////////////////////////////////////////////////////

			// campaign criteria ////////////////////////////////////////////

			count = 0;

			campaign_criteria = raw->campaign_criteria;

			while (campaign_criteria)
			{
				count ++;

				campaign_criteria = campaign_criteria->next;
			}

			pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_COUNT, count);

			campaign_criteria = raw->campaign_criteria;

			while (campaign_criteria)
			{

				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_TYPE, campaign_criteria->criteria_type);

				pack_int_value (en, INT_TYPE_VALID, campaign_criteria->valid);

				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_RESULT, campaign_criteria->result);

				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE, campaign_criteria->value1);

				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE, campaign_criteria->value2);

				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE, campaign_criteria->value3);

				pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE, campaign_criteria->value4);

				campaign_criteria = campaign_criteria->next;
			}
			/////////////////////////////////////////////////////////////////

			// force_info_criteria

			for (loop = 0; loop < NUM_FORCE_INFO_CATAGORIES; loop ++)
			{
				pack_int_value (en, INT_TYPE_VALUE, raw->force_info_current_hardware [loop]);

				pack_int_value (en, INT_TYPE_VALUE, raw->force_info_reserve_hardware [loop]);
			}
			/////////////////////////////////////////////////////////////////

			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_GROUPS; loop ++)
			{
				pack_int_value (en, INT_TYPE_VALUE, raw->kills [loop]);
				pack_int_value (en, INT_TYPE_VALUE, raw->losses [loop]);
//				pack_int_value (en, INT_TYPE_VALUE, raw->group_count [loop]);
			}

			pack_float_value (en, FLOAT_TYPE_SLEEP, raw->sleep);

			pack_int_value (en, INT_TYPE_FORCE_ATTITUDE, raw->force_attitude);

			pack_int_value (en, INT_TYPE_FORCE_SECTOR_COUNT, raw->sector_count);

			pack_int_value (en, INT_TYPE_COLOUR, raw->colour);

			pack_int_value (en, INT_TYPE_SIDE, raw->side);

			break;
		}
		////////////////////////////////////////
		case PACK_MODE_BROWSE_SESSION:
		////////////////////////////////////////
		{
         pack_string (en, STRING_TYPE_FORCE_NAME, raw->force_name);

			// keysite_force_root

			pack_list_root (en, LIST_TYPE_PILOT, &raw->pilot_root);

			pack_list_link (en, LIST_TYPE_FORCE, &raw->force_link);

			// update link

			// task_generation

			// campaign_criteria

			// force_info_catagories

			// sleep

			pack_int_value (en, INT_TYPE_FORCE_ATTITUDE, raw->force_attitude);

			pack_int_value (en, INT_TYPE_COLOUR, raw->colour);

			pack_int_value (en, INT_TYPE_SIDE, raw->side);

			break;
		}
	}
}
コード例 #22
0
/*
 * Loads the contents of the inventory.txt file into
 * a database. Note that because the itemname
 * secondary database is associated to the inventorydb
 * (see env_setup() in gettingstarted_common.c), the
 * itemname index is automatically created when this
 * database is loaded.
 */
int
load_inventory_database(STOCK_DBS my_stock, char *inventory_file)
{
    DBT key, data;
    char buf[MAXLINE];
    char databuf[MAXDATABUF];
    size_t bufLen, dataLen;
    FILE *ifp;

    /*
     * Rather than lining everything up nicely in a struct, we're being
     * deliberately a bit sloppy here. This function illustrates how to
     * store mixed data that might be obtained from various locations
     * in your application.
     */
    float price;
    int quantity;
    char category[MAXFIELD], name[MAXFIELD];
    char vendor[MAXFIELD], sku[MAXFIELD];

    /* Load the inventory database */
    ifp = fopen(inventory_file, "r");
    if (ifp == NULL) {
	fprintf(stderr, "Error opening file '%s'\n", inventory_file);
	    return (-1);
    }

    while (fgets(buf, MAXLINE, ifp) != NULL) {
	/*
	 * Scan the line into the appropriate buffers and variables.
	 * Convenient, but not particularly safe. In a real
	 * program, there would be a lot more defensive code here.
	 */
	sscanf(buf,
	  "%20[^#]#%20[^#]#%f#%i#%20[^#]#%20[^\n]",
	  name, sku, &price, &quantity, category, vendor);

	/*
	 * Now pack it into a single contiguous memory location for
	 * storage.
	 */
	memset(databuf, 0, MAXDATABUF);
	bufLen = 0;
	dataLen = 0;

	dataLen = sizeof(float);
	memcpy(databuf, &price, dataLen);
	bufLen += dataLen;

	dataLen = sizeof(int);
	memcpy(databuf + bufLen, &quantity, dataLen);
	bufLen += dataLen;

	bufLen = pack_string(databuf, name, bufLen);
	bufLen = pack_string(databuf, sku, bufLen);
	bufLen = pack_string(databuf, category, bufLen);
	bufLen = pack_string(databuf, vendor, bufLen);

	/* Zero out the DBTs */
	memset(&key, 0, sizeof(DBT));
	memset(&data, 0, sizeof(DBT));

	/* The key is the item's SKU */
	key.data = sku;
	key.size = (u_int32_t)strlen(sku) + 1;

	/* The data is the information that we packed into databuf. */
	data.data = databuf;
	data.size = (u_int32_t)bufLen;

	/* Put the data into the database */
	my_stock.vendor_dbp->put(my_stock.inventory_dbp, 0, &key, &data, 0);
    } /* end vendors database while loop */

    /* Cleanup */
    fclose(ifp);

    return (0);
}
コード例 #23
0
ファイル: rbkit_event_packer.c プロジェクト: alfie-max/rbkit
static void pack_object_space_dump_event(rbkit_object_space_dump_event *event, msgpack_packer *packer) {
  size_t objects_in_batch;
  size_t objects_left;
  size_t count = 0;
  size_t i = 0;
  rbkit_object_dump_page *prev;
  rbkit_object_data *data;
  rbkit_object_dump_page * page;

  msgpack_pack_map(packer, 5);
  pack_event_header(packer, event->event_header.event_type);

  // Incrementing integer holding the correlation_id
  // indicating the event which the message belongs to
  msgpack_pack_int(packer, rbkit_message_field_correlation_id);
  msgpack_pack_int(packer, event->correlation_id);
  
  // dump total number of messages in batch
  msgpack_pack_int(packer, rbkit_message_field_complete_message_count);
  msgpack_pack_unsigned_long(packer, event->object_count);

  msgpack_pack_int(packer, rbkit_message_field_payload);

  // Find the batch size
  objects_in_batch = MAX_OBJECT_DUMPS_IN_MESSAGE ;
  objects_left = event->object_count - event->packed_objects;
  if(objects_left < MAX_OBJECT_DUMPS_IN_MESSAGE)
    objects_in_batch = objects_left;

  // Set size of array to hold all objects
  msgpack_pack_array(packer, objects_in_batch);

  // Iterate through all object data
  while(count < objects_in_batch) {
    if(event->current_page_index == RBKIT_OBJECT_DUMP_PAGE_SIZE) {
      event->current_page_index = 0;
      prev = event->current_page;
      event->current_page = event->current_page->next;
      free(prev);
    }
    page = event->current_page;
    i = event->current_page_index;
    data = &(page->data[i]);
    /* Object dump is a map that looks like this :
     * {
     *   object_id: <OBJECT_ID_IN_HEX>,
     *   class: <CLASS_NAME>,
     *   references: [<OBJECT_ID_IN_HEX>, <OBJECT_ID_IN_HEX>, ...],
     *   file: <FILE_PATH>,
     *   line: <LINE_NO>,
     *   size: <SIZE>
     * }
     */

    msgpack_pack_map(packer, 6);

    // Key1 : rbkit_message_field_object_id
    msgpack_pack_int(packer, rbkit_message_field_object_id);

    // Value1 : pointer address of object
    msgpack_pack_unsigned_long_long(packer, data->object_id);

    // Key2 : rbkit_message_field_class_name
    msgpack_pack_int(packer, rbkit_message_field_class_name);

    // Value2 : Class name of object
    pack_string(packer, data->class_name);

    // Key3 : rbkit_message_field_references
    msgpack_pack_int(packer, rbkit_message_field_references);

    // Value3 : References held by the object
    msgpack_pack_array(packer, data->reference_count);
    if(data->reference_count != 0) {
      size_t count = 0;
      for(; count < data->reference_count; count++ )
        msgpack_pack_unsigned_long_long(packer, data->references[count]);
      free(data->references);
    }

    // Key4 : rbkit_message_field_file
    msgpack_pack_int(packer, rbkit_message_field_file);

    // Value4 : File path where object is defined
    pack_string(packer, data->file);

    // Key5 : rbkit_message_field_line
    msgpack_pack_int(packer, rbkit_message_field_line);

    // Value5 : Line no where object is defined
    if(data->line == 0)
      msgpack_pack_nil(packer);
    else
      msgpack_pack_unsigned_long(packer, data->line);

    // Key6 : rbkit_message_field_size
    msgpack_pack_int(packer, rbkit_message_field_size);

    // Value6 : Size of the object in memory
    if(data->size == 0)
      msgpack_pack_nil(packer);
    else
      msgpack_pack_unsigned_long(packer, data->size);

    event->current_page_index++;
    event->packed_objects++;
    count++;
  }
}
コード例 #24
0
ファイル: attributes.hpp プロジェクト: Dzshiftt/Gnomescroll
 inline void packet(char* buff, size_t* buff_n, bool pack)
 {
     pack_u8(&attribute_group, buff, buff_n, pack);
     pack_u8(&attribute_type, buff, buff_n, pack);
     pack_string(value, STRING_ATTRIBUTE_MAX_LENGTH+1, buff, buff_n, pack);
 }
コード例 #25
0
int captureScreen()
{
	char dstpath[MAX_PATH_LENGTH];
	char* scrimage;
	int width, height;
	Evas* ev = NULL;
	Evas_Object* img;
	screenshot_data sdata;
	probeInfo_t	probeInfo;
	int ret = 0;
	static pthread_mutex_t captureScreenLock = PTHREAD_MUTEX_INITIALIZER;

	pthread_mutex_lock(&captureScreenLock);

	probeBlockStart();

	setProbePoint(&probeInfo);
	sdata.ximage = NULL;
	scrimage = captureScreenShotX(&width, &height, &sdata);
	if(scrimage != NULL)
	{
		ev = create_canvas(width, height);
		if(likely(ev != NULL))
		{
			snprintf(dstpath, sizeof(dstpath),
				 SCREENSHOT_DIRECTORY "/%d_%d.png", getpid(),
				 probeInfo.eventIndex);

			// make image buffer
			if((img = evas_object_image_add(ev)) != NULL)
			{
				//image buffer set
				evas_object_image_data_set(img, NULL);
				evas_object_image_size_set(img, width, height);
				evas_object_image_data_set(img, scrimage);

				// resize image
				if(height > MAX_HEIGHT)
				{
					width = width * MAX_HEIGHT / height;
					height = MAX_HEIGHT;
					evas_object_resize(img, width, height);
					evas_object_image_fill_set(img, 0, 0, width, height);
				}
				evas_object_image_data_update_add(img, 0, 0, width, height);

				//save file
				if(evas_object_image_save(img, dstpath, NULL, "compress=5") != 0)
				{
					chmod(dstpath, 0777);

					/* welcome to the hell */
					log_t log;
					PREPARE_LOCAL_BUF_THOUGH((char *)&log);

					/* skip header */
					LOCAL_BUF += offsetof(log_t, data);
					/* pack screenshot name */
					BUF_PTR = pack_string(LOCAL_BUF, dstpath); /* file name */
					LOCAL_BUF = BUF_PTR;

					/* pack probe */
					PACK_COMMON_BEGIN(MSG_PROBE_SCREENSHOT, API_ID_captureScreen, "", 0);
					PACK_COMMON_END('d', 0, 0, 0);
					PACK_SCREENSHOT(dstpath, getOrientation());
					SET_MSG_LEN();
					log.length = GET_MSG_LEN() + MSG_LEN_OFFSET + strlen(dstpath) + 1;

					/* send all message */
					printLog(&log, MSG_IMAGE);
				}
				else
				{
					// captureScreen : evas_object_image_save failed
					ret = -1;
				}
			}
			else
			{
				// captureScreen : evas_object_image_add failed
				ret = -1;
			}
		}
		else
		{
			// captureScreen : create canvas failed
			ret = -1;
		}
	}
	else
	{
		// captureScreen : captureScreenShotX failed
		ret = -1;
	}

	// release resources
	releaseScreenShotX(&sdata);
	if(ev)
		destroy_canvas(ev);

	probeBlockEnd();

	pthread_mutex_unlock(&captureScreenLock);
	return ret;
}
コード例 #26
0
ファイル: StoC.hpp プロジェクト: Dzshiftt/Gnomescroll
 inline void packet(char* buff, size_t* buff_n, bool pack)
 {
     pack_u16(&id, buff, buff_n, pack);
     pack_string(msg, MECH_TEXT_SIZE_MAX+1, buff, buff_n, pack);
 }
コード例 #27
0
ファイル: packets.hpp プロジェクト: Dzshiftt/Gnomescroll
 inline void packet(char* buff, size_t* buff_n, bool pack)
 {
     pack_string(this->token, AUTH_TOKEN_LENGTH+1, buff, buff_n, pack);
 }
コード例 #28
0
ファイル: serializable.cpp プロジェクト: CheezBoiger/CatDBMS
serial pack_string_packet(string_packet* str, serial input) {
  return pack_string(str->str, str->len, input);
}
コード例 #29
0
ファイル: net_agent.hpp プロジェクト: Dzshiftt/Gnomescroll
 inline void packet(char* buff, size_t* buff_n, bool pack)
 {
     pack_u8(&id, buff, buff_n, pack);
     pack_string(name, PLAYER_NAME_MAX_LENGTH+1, buff, buff_n, pack);
 }
コード例 #30
0
static int pack_string(grib_accessor* a, const char* buffer, size_t *len)
{
  grib_accessor_codetable* self = (grib_accessor_codetable*)a;
  grib_codetable*          table ;

  long i;
  size_t size = 1;

  typedef int (*cmpproc)(const char*, const char*);

  cmpproc cmp = a->flags | GRIB_ACCESSOR_FLAG_LOWERCASE ? strcasecmp : strcmp;

  if(!self->table) self->table = load_table(self);
  table=self->table;

  if(!table)
    return GRIB_ENCODING_ERROR;

  if (a->set) {
	  int err=grib_set_string(a->parent->h,a->set,buffer,len);
	  if (err!=0) return err;
  }

  for(i = 0 ; i < table->size; i++)
    if(table->entries[i].abbreviation)
		  if(cmp(table->entries[i].abbreviation,buffer) == 0)
        return grib_pack_long(a,&i,&size);

  if (a->flags & GRIB_ACCESSOR_FLAG_NO_FAIL) {
	  grib_action* act=(grib_action*)(a->creator);
	  if (act->default_value!=NULL) {
		  const char* p = 0;
		  size_t len = 1;
		  long l;
		  int ret=0;
		  double d;
		  char tmp[1024];
		  grib_expression* expression=grib_arguments_get_expression(a->parent->h,act->default_value,0);
		  int type = grib_expression_native_type(a->parent->h,expression);
		  switch(type) {
			  case GRIB_TYPE_DOUBLE:
				  grib_expression_evaluate_double(a->parent->h,expression,&d);
				  grib_pack_double(a,&d,&len);
				  break;

			  case GRIB_TYPE_LONG:
				  grib_expression_evaluate_long(a->parent->h,expression,&l);
				  grib_pack_long(a,&l,&len);
				  break;

			  default:
				  len = sizeof(tmp);
				  p = grib_expression_evaluate_string(a->parent->h,expression,tmp,&len,&ret);
				  if (ret != GRIB_SUCCESS) {
					  grib_context_log(a->parent->h->context,GRIB_LOG_FATAL,
									   "unable to evaluate %s as string",a->name);
					  return ret;
				  }
				  len = strlen(p)+1;
				  pack_string(a,p,&len);
				  break;
		  }
		  return GRIB_SUCCESS;
	  }
	
  }
  return GRIB_ENCODING_ERROR;
}