Esempio n. 1
0
//-------------------------------------------------------------------------------------------------
unsigned Message::encode(f8String& to) const
{
	char msg[MAX_MSG_LENGTH], hmsg[MAX_MSG_LENGTH];
	size_t sz(0), hsz(0);

#if defined CODECTIMING
	ostringstream gerr;
	gerr << "encode(" << _msgType << "):";
	IntervalTimer itm;
#endif

	if (!_header)
		throw MissingMessageComponent("header");
	Fields::const_iterator fitr(_header->_fields.find(Common_MsgType));
	static_cast<msg_type *>(fitr->second)->set(_msgType);
	_header->encode(msg, sz);
	MessageBase::encode(msg, sz);
	if (!_trailer)
		throw MissingMessageComponent("trailer");
	_trailer->encode(msg, sz);
	const unsigned msgLen(sz);	// checksummable msglength

	if ((fitr = _header->_fields.find(Common_BeginString)) == _header->_fields.end())
		throw MissingMandatoryField(Common_BeginString);
	_header->_fp.clear(Common_BeginString, FieldTrait::suppress);
	fitr->second->encode(hmsg, hsz);
#if defined MSGRECYCLING
	_header->_fp.set(Common_BeginString, FieldTrait::suppress); // in case we want to reuse
#endif

	if ((fitr = _header->_fields.find(Common_BodyLength)) == _header->_fields.end())
		throw MissingMandatoryField(Common_BodyLength);
	_header->_fp.clear(Common_BodyLength, FieldTrait::suppress);
	static_cast<body_length *>(fitr->second)->set(msgLen);
	fitr->second->encode(hmsg, hsz);
#if defined MSGRECYCLING
	_header->_fp.set(Common_BodyLength, FieldTrait::suppress); // in case we want to reuse
#endif

	::memcpy(hmsg + hsz, msg, sz);
	hsz += sz;

	if ((fitr = _trailer->_fields.find(Common_CheckSum)) == _trailer->_fields.end())
		throw MissingMandatoryField(Common_CheckSum);
	static_cast<check_sum *>(fitr->second)->set(fmt_chksum(calc_chksum(hmsg, hsz)));
	_trailer->_fp.clear(Common_CheckSum, FieldTrait::suppress);
	fitr->second->encode(hmsg, hsz);
#if defined MSGRECYCLING
	_trailer->_fp.set(Common_CheckSum, FieldTrait::suppress); // in case we want to reuse
#endif

#if defined CODECTIMING
	gerr << itm.Calculate();
	GlobalLogger::log(gerr.str());
#endif

	to.assign(hmsg, hsz);
	return to.size();
}
Esempio n. 2
0
File: sized.c Progetto: Tolchi/misc
int do_query(void) {
  int rc = -1;
  UT_array *files;
  UT_array *stats; 
  utarray_new(files,&ut_str_icd);
  utarray_new(stats,&stats_icd);
  if (get_files(files,stats) == -1) goto done;

  /* tally up their sizes */
  int64_t total_sz=0;
  file_stat_t *fs=NULL;
  while ( (fs=(file_stat_t*)utarray_next(stats,fs))) total_sz += fs->sb.st_size;

  char tsz[100],csz[100];
  syslog(LOG_INFO,"directory size: %s (limit %s)", hsz(total_sz, tsz, sizeof(tsz)), 
                                      hsz(cf.sz_bytes, csz, sizeof(csz)));

  rc = 0;

 done:
  utarray_free(files);
  utarray_free(stats);
  return rc;
}