Example #1
0
void StarsNode::unpackState(std::streambuf & in) {
    uint32_t size;
    in.sgetn((char *)&size, 4);
    msgpack::unpacker upk;
    upk.reserve_buffer(size);
    in.sgetn(upk.buffer(), size);
    upk.buffer_consumed(size);
    MsgpackInArchive ar(upk);
    ar & power & mem & disk & static_cast<SimOverlayBranch &>(getBranch()) & static_cast<SimOverlayLeaf &>(getLeaf());
    switch (Configuration::getInstance().getPolicy()) {
        case Configuration::IBPolicy:
            static_cast<IBPDispatcher &>(getDisp()).serializeState(ar);
            break;
        case Configuration::MMPolicy:
            static_cast<MMPDispatcher &>(getDisp()).serializeState(ar);
            break;
        case Configuration::DPolicy:
            static_cast<DPDispatcher &>(getDisp()).serializeState(ar);
            break;
        case Configuration::FSPolicy:
            static_cast<FSPDispatcher &>(getDisp()).serializeState(ar);
            break;
        default:
            break;
    }
}
Example #2
0
/**
   read whole contents of streambuf 'buf'

   \return size of data malloced and copied into \param[out] buffer unless size
   is 0 (in which case buffer is set to NULL for convenience, so you can blindly free)

   requires put pointer is at end for determining size (e.g. just-written iostream)
*/
inline std::size_t read_streambuf_malloc(std::streambuf& buf, void*& buffer) {
  typedef std::streambuf::pos_type Pos;
  typedef std::streambuf::off_type Off;
  Pos sz = buf.pubseekoff(0, std::ios::end, std::ios_base::out);
  if (sz > 0 && seek_ok(sz) && seek_ok(buf.pubseekpos(0, std::ios_base::in)))
    return buf.sgetn((char*)(buffer = std::malloc(sz)), sz);
  else {
    buffer = 0;
    return 0;
  }
}
//////////////////////////////////////////////////////////////////////////////
// STATIC
void
read(std::streambuf & istrm, void * dataIn, size_t dataInLen)
{
	std::streamsize cnt = dataInLen;
#ifdef BLOCXX_WIN32
// VC10 warns that sgetn is unsafe.
#pragma warning(push)
#pragma warning(disable:4996)
#endif
	if (istrm.sgetn(static_cast<char *>(dataIn), cnt) != cnt)
#ifdef BLOCXX_WIN32
#pragma warning(pop)
#endif
	{
		BLOCXX_THROW(IOException, "Failed reading data");
	}
}
Example #4
0
Ttamanio Bloque::deserializar(std::streambuf&entrada){
	unsigned char nrocomponetes;
	Ttamanio offset=sizeof(unsigned char);
	entrada.sgetn((char*)&nrocomponetes,offset);
	Ttamanio i=0;
	while(i<nrocomponetes and i<componentes.size()){
		offset+=componentes.at(i)->deserializar(entrada);
		i++;
	}
	/*le sobran componentes*/
	while(i<componentes.size()){
		delete componentes.at(i);
		componentes.erase(componentes.begin()+i);
	}
	/*le faltan componentes*/
	Componente* auxiliar;
	while(i<nrocomponetes){
		auxiliar=componentes.at(0)->clonar();
		offset+=auxiliar->deserializar(entrada);
		componentes.push_back(auxiliar);
		i++;
	}
	return offset;
}
Example #5
0
 virtual std::streamsize xsgetn(char *pBuffer, std::streamsize sz) override {
   ASSERT(_streambuf);
   return _streambuf->sgetn(pBuffer, sz);
 }