Пример #1
0
WError WEffect::SaveToStream(WFile* file, std::ostream& outputStream) {
	if (!Valid())
		return WError(W_NOTVALID);

	uint tmp;

	outputStream.write((char*)&m_topology, sizeof(m_topology));
	outputStream.write((char*)&m_depthStencilState, sizeof(m_depthStencilState));
	outputStream.write((char*)&m_rasterizationState, sizeof(m_rasterizationState));
	tmp = m_blendStates.size();
	outputStream.write((char*)&tmp, sizeof(tmp));
	outputStream.write((char*)m_blendStates.data(), m_blendStates.size() * sizeof(VkPipelineColorBlendAttachmentState));
	tmp = m_shaders.size();
	outputStream.write((char*)&tmp, sizeof(tmp));
	std::streampos shaderIdsBegin = outputStream.tellp();
	for (uint i = 0; i < m_shaders.size(); i++) {
		tmp = 0;
		outputStream.write((char*)&tmp, sizeof(tmp));
	}
	_MarkFileEnd(file, outputStream.tellp());
	for (uint i = 0; i < m_shaders.size(); i++) {
		WError err = file->SaveAsset(m_shaders[i], &tmp);
		if (!err)
			return err;
		outputStream.seekp(shaderIdsBegin + std::streamoff(i * sizeof(uint)));
		outputStream.write((char*)&tmp, sizeof(tmp));
	}

	return WError(W_SUCCEEDED);
}
Пример #2
0
	void recursive_treewrite(std::ostream &out, radix_tree_node<std::string, std::unordered_set<zsr::filecount>> *n, zsr::offset treestart)
	{
		static int nwritten = 0;
		logb(++nwritten);
		treesize nval = 0;
		if (n->m_children.count("") && n->m_children[""]->m_value) nval = n->m_children[""]->m_value->second.size();
		treesize nchild = 0;
		for (const std::pair<const std::string, radix_tree_node<std::string, std::unordered_set<zsr::filecount>> *> child : n->m_children) if (child.first != "" && child.second) nchild++; // TODO Probably a faster way?
		zsr::serialize(out, nchild);
		std::deque<zsr::offset> childpos{};
		for (const std::pair<const std::string, radix_tree_node<std::string, std::unordered_set<zsr::filecount>> *> child : n->m_children)
		{
			if (child.first == "" || ! child.second) continue;
			uint16_t namelen = child.first.size();
			zsr::serialize(out, namelen);
			out.write(&child.first[0], namelen);
			childpos.push_back(static_cast<zsr::offset>(out.tellp()));
			zsr::serialize(out, ptrfill);
		}
		zsr::serialize(out, nval);
		if (n->m_children.count("") && n->m_children[""]->m_value)
			for (const zsr::filecount &i : n->m_children[""]->m_value->second) zsr::serialize(out, i);
		for (const std::pair<const std::string, radix_tree_node<std::string, std::unordered_set<zsr::filecount>> *> child : n->m_children)
		{
			if (child.first == "" || ! child.second) continue;
			zsr::offset childstart = static_cast<zsr::offset>(out.tellp()) - treestart;
			out.seekp(childpos.front());
			zsr::serialize(out, childstart);
			out.seekp(0, std::ios_base::end);
			recursive_treewrite(out, child.second, treestart);
			childpos.pop_front();
		}
	}
Пример #3
0
bool VehicleStateBasicLux::serialize(std::ostream& os) const
{
	const std::istream::pos_type startPos = os.tellp();

	lock();

	ibeo::writeLE(os, m_timestamp);
	ibeo::writeLE(os, m_scanNumber);
	ibeo::writeLE(os, m_errorFlags);
	ibeo::writeLE(os, m_longitudinalVelocity);
	ibeo::writeLE(os, m_steeringWheeAngle);
	ibeo::writeLE(os, m_wheelAngle);
	ibeo::writeLE(os, m_reserved0);

	ibeo::writeLE(os, m_xPos);
	ibeo::writeLE(os, m_yPos);
	ibeo::writeLE(os, m_courseAngle);

	ibeo::writeLE(os, m_timeDiff);
	ibeo::writeLE(os, m_xDiff);
	ibeo::writeLE(os, m_yDiff);
	ibeo::writeLE(os, m_yaw);

	ibeo::writeLE(os, m_reserved1);
	ibeo::writeLE(os, m_currentYawRate);
	ibeo::writeLE(os, m_reserved2);

	unlock();

	return !os.fail() && ((os.tellp() - startPos) == this->getSerializedSize());
}
Пример #4
0
void OSGA_Archive::IndexBlock::write(std::ostream& out)
{
    pos_type currentPos = ARCHIVE_POS( out.tellp() );

    if (_filePosition==pos_type(0))
    {
        OSG_INFO<<"OSGA_Archive::IndexBlock::write() setting _filePosition"<<std::endl;
        _filePosition = currentPos;
    }
    else
    {
         out.seekp( STREAM_POS( _filePosition ) );
    }
    OSG_INFO<<"OSGA_Archive::IndexBlock::write() to _filePosition"<< ARCHIVE_POS( out.tellp() )<<std::endl;

    out.write(reinterpret_cast<char*>(&_blockSize), sizeof(_blockSize));
    out.write(reinterpret_cast<char*>(&_filePositionNextIndexBlock), sizeof(_filePositionNextIndexBlock));
    out.write(reinterpret_cast<char*>(&_offsetOfNextAvailableSpace), sizeof(_offsetOfNextAvailableSpace));

    out.write(reinterpret_cast<char*>(_data),_blockSize);

    if( _filePosition < currentPos ) // move file ptr to the end of file
        out.seekp( STREAM_POS( currentPos ) );

    OSG_INFO<<"OSGA_Archive::IndexBlock::write() end"<<std::endl;
}
Пример #5
0
	inline std::ostream::pos_type get_size(std::ostream& stream)
	{
		auto original_pos = stream.tellp();
		stream.seekp(0, std::ios::end);
		auto pos = stream.tellp();
		stream.seekp(original_pos);
		return pos;
	}
Пример #6
0
//-------------------------------------------------------------------------------------------------
size_t MessageBase::encode_group(const unsigned short fnum, std::ostream& to) const
{
	const std::ios::pos_type where(to.tellp());
	GroupBase *grpbase(find_group(fnum));
	if (!grpbase)
		throw InvalidRepeatingGroup(fnum, FILE_LINE);
	for (const auto *pp : grpbase->_msgs)
		pp->encode(to);
	return to.tellp() - where;
}
Пример #7
0
//-------------------------------------------------------------------------------------------------
size_t MessageBase::encode_group(const unsigned short fnum, std::ostream& to) const
{
	const std::ios::pos_type where(to.tellp());
	GroupBase *grpbase(find_group(fnum));
	if (!grpbase)
		throw InvalidRepeatingGroup(fnum);
	for (GroupElement::iterator itr(grpbase->_msgs.begin()); itr != grpbase->_msgs.end(); ++itr)
		(*itr)->encode(to);
	return to.tellp() - where;
}
Пример #8
0
	int request::serialize(std::ostream& ostr) const
	{
		std::ostream::off_type len=ostr.tellp();
		if (len<0)len=0;
		BOOST_ASSERT(!host().empty());
		ostr << m_method << " " <<m_strUri<< " " << version() << "\r\n";
		if(header::serialize(ostr)<0)
			return -1;
		ostr << "\r\n";
		return static_cast<int>(ostr.tellp()-len);
	}
Пример #9
0
void ossimNitfTagInformation::writeStream(std::ostream &out)
{
   theTagOffset = out.tellp(); // Capture the offset.
   out.write(theTagName, 6);
   out.write(theTagLength, 5);
   if(theTagData.valid())
   {
      theTagDataOffset = out.tellp();
      theTagData->writeStream(out);
   }
}
Пример #10
0
size_t emit_padded(std::ostream &out, T data, size_t size) {
    size_t pos = out.tellp();
    out << data;
    size_t written = (size_t)out.tellp() - pos;
    internal_assert(written <= size);
    while (written < size) {
        out << ' ';
        written++;
    }
    return pos;
}
Пример #11
0
void VSTPresets::SaveProgram(std::ostream &f, CVstPlugin &plugin)
//---------------------------------------------------------------
{
	bool writeChunk = plugin.ProgramsAreChunks();
	ChunkHeader header;
	header.chunkMagic = cMagic;
	header.version = 1;
	header.fxID = plugin.GetUID();
	header.fxVersion = plugin.GetVersion();

	// Write unfinished header... We need to update the size once we're done writing.
	std::streamoff start = f.tellp();
	Write(header, f);

	const uint32 numParams = plugin.GetNumParameters();
	WriteBE(numParams, f);

	char name[MAX(kVstMaxProgNameLen + 1, 256)];
	plugin.Dispatch(effGetProgramName, 0, 0, name, 0);
	f.write(name, 28);

	if(writeChunk)
	{
		char *chunk = nullptr;
		uint32 chunkSize = mpt::saturate_cast<uint32>(plugin.Dispatch(effGetChunk, 1, 0, &chunk, 0));
		if(chunkSize && chunk)
		{
			WriteBE(chunkSize, f);
			f.write(chunk, chunkSize);
		} else
		{
			// The plugin returned no chunk! Gracefully go back and save parameters instead...
			writeChunk = false;
		}
	}
	if(!writeChunk)
	{
		for(uint32 p = 0; p < numParams; p++)
		{
			WriteBE(plugin.GetParameter(p), f);
		}
	}

	// Now we know the correct chunk size.
	std::streamoff end = f.tellp();
	header.byteSize = static_cast<VstInt32>(end - start - 8);
	header.fxMagic = writeChunk ? chunkPresetMagic : fMagic;
	header.ConvertEndianness();
	f.seekp(start);
	Write(header, f);
	f.seekp(end);
}
Пример #12
0
WError WMaterial::SaveToStream(WFile* file, std::ostream& outputStream) {
	if (!Valid())
		return WError(W_NOTVALID);

	VkDevice device = m_app->GetVulkanDevice();

	// write the UBO data
	uint tmp = m_uniformBuffers.size();
	outputStream.write((char*)&tmp, sizeof(tmp));
	for (uint i = 0; i < m_uniformBuffers.size(); i++) {
		UNIFORM_BUFFER_INFO* UBO = &m_uniformBuffers[i];
		outputStream.write((char*)&UBO->descriptor.range, sizeof(UBO->descriptor.range));
		void* data;
		VkResult vkRes = vkMapMemory(device, m_uniformBuffers[i].memory, 0, UBO->descriptor.range, 0, (void **)&data);
		if (vkRes)
			return WError(W_UNABLETOMAPBUFFER);
		outputStream.write((char*)data, UBO->descriptor.range);
		vkUnmapMemory(device, m_uniformBuffers[0].memory);
	}

	// write the texture data
	tmp = m_sampler_info.size();
	outputStream.write((char*)&tmp, sizeof(tmp));
	std::streampos texturesOffset = outputStream.tellp();
	for (uint i = 0; i < m_sampler_info.size(); i++) {
		SAMPLER_INFO* SI = &m_sampler_info[i];
		tmp = 0;
		outputStream.write((char*)&tmp, sizeof(tmp));
		outputStream.write((char*)&SI->sampler_info->binding_index, sizeof(SI->sampler_info->binding_index));
	}
	outputStream.write((char*)&tmp, sizeof(tmp)); // effect id
	_MarkFileEnd(file, outputStream.tellp());

	// save dependencies
	for (uint i = 0; i < m_sampler_info.size(); i++) {
		SAMPLER_INFO* SI = &m_sampler_info[i];
		if (SI->img) {
			WError err = file->SaveAsset(SI->img, &tmp);
			if (!err)
				return err;
			outputStream.seekp(texturesOffset + std::streamoff(i * (2 * sizeof(uint))));
			outputStream.write((char*)&tmp, sizeof(tmp));
		}
	}
	WError err = file->SaveAsset(m_effect, &tmp);
	if (!err)
		return err;
	outputStream.seekp(texturesOffset + std::streamoff(m_sampler_info.size() * (2 * sizeof(uint))));
	outputStream.write((char*)&tmp, sizeof(tmp));

	return WError(W_SUCCEEDED);
}
Пример #13
0
void AVR::write(std::ostream& os, const AVRTexture& texture)
{
	os.write("TEXT", 4);
	auto sizePos = os.tellp();
	os.seekp(4, std::ios::cur);
	auto startPos = os.tellp();

	os.write(texture.mPath.c_str(), texture.mPath.length() + 1);

	auto endPos = os.tellp();
	uint32_t size = endPos - startPos;
	os.seekp(sizePos);
	os.write((char*) &size, 4);
	os.seekp(endPos);
}
Пример #14
0
// call from infitof2 - counting
void
threshold_result::write3( std::ostream& os, const threshold_result& t )
{
    if ( os.tellp() == std::streamoff(0) )
        os << "## trig#, prot#, timestamp(s), epoch_time(ns), events, threshold(mV), algo(0=absolute,1=average,2=differential)"
           "\t[time(s), peak-front(s), peak-front(mV), peak-end(s), peak-end(mV)]";

    if ( auto data = t.data() ) {

        os << boost::format( "\n%d, %d, %.8lf, %.8lf, 0x%08x, %.8lf, %d" )
           % data->serialnumber_
           % data->method_.protocolIndex()
           % data->meta_.initialXTimeSeconds
           % t.data()->timeSinceEpoch_
           % t.data()->wellKnownEvents_
           % ( t.threshold_level() * std::milli::den )
           % t.algo();

        if ( ! t.indecies2().empty() ) {
            for ( auto& idx : t.indecies2() ) {

                auto apex  = data->xy( idx.apex );

                os << boost::format( ",\t%.14le, %.6f, %d, %.6f, %d, %.6f" )
                   % apex.first    // apex (time)
                   % ( t.data()->toVolts( apex.second ) * std::milli::den )
                   % ( int( idx.first ) - int( idx.apex ) )   // front-apex distance
                   % ( t.data()->toVolts( int64_t( (*data)[ idx.first ] ) ) * std::milli::den )     // front intensity
                   % ( int( idx.second ) - int( idx.apex ) )
                   % ( t.data()->toVolts( int64_t( (*data)[ idx.second ] ) ) * std::milli::den );
            }
        }
    }
}
Пример #15
0
void bil::dumpConfiguration(const V5Configuration& cfg, std::ostream& cfgOut, std::ostream& indexOut)
{
    // collect list with all frame addresses and their frames
    V5Configuration::pairconstptrs_t pairs = cfg.contents();

    // loop over list
    size_t frameCount = pairs.size();
    for (size_t i = 0; i < frameCount; ++i)
    {
        // get pointer to current pair
        const V5Configuration::pair_t* pairPtr = pairs[i];

        // write one line with raw frame address info and frame data offset
        const V5FrameAddress& address = pairPtr->first;
        indexOut << toRawAddressString(address) << '\t';
        printHex(indexOut, cfgOut.tellp());
        indexOut << "\t(" << toSymbolicString(address) << "):";
        indexOut << V5CfgColumn::toString(address.columnType()) << '\n';
        if (!indexOut) throw IOException();

        // write frame data
        const V5CfgFrame& frame = pairPtr->second;
        cfgOut.write(reinterpret_cast<const char*>(frame.data()), V5CfgFrame::WORDCOUNT << 2);
        if (!cfgOut) throw IOException();
    }
}
Пример #16
0
inline
void write_shader_source(
	std::ostream& output,
	shader_source_header& header,
	const_memory_block source_text
)
{
	span_size_t spos = 0;

	if(output.tellp() >= 0)
	{
		spos = span_size_t(output.tellp());
	}

	write_shader_source(output, header, source_text, spos);
}
Пример #17
0
bool test_output_seekable(std::ostream& io)
{
    int i;  // old 'for' scope workaround.

    // Test seeking with ios::cur
    for (i = 0; i < data_reps; ++i) {
        for (int j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
        io.seekp(-chunk_size, BOOST_IOS::cur);
        io.write(narrow_data(), chunk_size);
    }

    // Test seeking with ios::beg
    std::streamoff off = 0;
    io.seekp(0, BOOST_IOS::beg);
    for (i = 0; i < data_reps; ++i, off += chunk_size) {
        for (int j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
        io.seekp(off, BOOST_IOS::beg);
        io.write(narrow_data(), chunk_size);
    }
    
    // Test seeking with ios::end
    io.seekp(0, BOOST_IOS::end);
    off = io.tellp();
    io.seekp(-off, BOOST_IOS::end);
    for (i = 0; i < data_reps; ++i, off -= chunk_size) {
        for (int j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
        io.seekp(-off, BOOST_IOS::end);
        io.write(narrow_data(), chunk_size);
    }
    return true;
}
Пример #18
0
std::streamsize VoidElement::write(std::ostream& output)
{
    // Fill in the offset of this element in the byte stream.
    offset_ = output.tellp();

    return write_id(output) + write_body(output);
}
Пример #19
0
void SplitGeoRec::addFixup(OSG::UInt32 part, std::ostream &s, OSG::UInt32 ind)
{
    static Pnt3f dummy;
    
    // Do we already have this index and partition in the fixup list?
    FixupMap::iterator it;
    if((it = _fixups.lower_bound(ind)) != _fixups.end())
    {
        FixupMap::iterator end = _fixups.upper_bound(ind);
        for(it; it != end; ++it)
        {
            if(it->second.part == part)
                return;
        }
    }

    long o = s.tellp();

    FDEBUG(("SplitGeoRec::addFixup: adding fixup for %d in partition %d "
            "at %d.\n", ind, part, o));
    
    _fixups.insert(
        std::pair<OSG::UInt32, FixupRec>(ind, FixupRec(part, o, ind)));   

    writePnt(s, ind, dummy);
}
Пример #20
0
bool VSTPresets::SaveFile(std::ostream &f, CVstPlugin &plugin, bool bank)
//-----------------------------------------------------------------------
{
	if(!bank)
	{
		SaveProgram(f, plugin);
	} else
	{
		bool writeChunk = plugin.ProgramsAreChunks();
		ChunkHeader header;
		header.chunkMagic = cMagic;
		header.version = 2;
		header.fxID = plugin.GetUID();
		header.fxVersion = plugin.GetVersion();

		// Write unfinished header... We need to update the size once we're done writing.
		Write(header, f);

		uint32 numProgs = std::max(plugin.GetNumPrograms(), VstInt32(1)), curProg = plugin.GetCurrentProgram();
		WriteBE(numProgs, f);
		WriteBE(curProg, f);
		char reserved[124];
		MemsetZero(reserved);
		Write(reserved, f);

		if(writeChunk)
		{
			char *chunk = nullptr;
			uint32 chunkSize = mpt::saturate_cast<uint32>(plugin.Dispatch(effGetChunk, 0, 0, &chunk, 0));
			if(chunkSize && chunk)
			{
				WriteBE(chunkSize, f);
				f.write(chunk, chunkSize);
			} else
			{
				// The plugin returned no chunk! Gracefully go back and save parameters instead...
				writeChunk = false;
			}
		}
		if(!writeChunk)
		{
			for(uint32 p = 0; p < numProgs; p++)
			{
				plugin.SetCurrentProgram(p);
				SaveProgram(f, plugin);
			}
			plugin.SetCurrentProgram(curProg);
		}

		// Now we know the correct chunk size.
		std::streamoff end = f.tellp();
		header.byteSize = static_cast<VstInt32>(end - 8);
		header.fxMagic = writeChunk ? chunkBankMagic : bankMagic;
		header.ConvertEndianness();
		f.seekp(0);
		Write(header, f);
	}

	return true;
}
Пример #21
0
 AP4_Stream::AP4_Stream(
     std::ostream & os)
     : is_(NULL)
     , os_(&os)
     , ref_(1)
 {
     offset_ = os.tellp();
 }
Пример #22
0
void
Model::save(std::ostream & ofs) {
  // write a signature into the file
  char chunk[16];
  if (full) {
    strncpy(chunk, SEGMENTOR_MODEL_FULL, 16);
  } else {
    strncpy(chunk, SEGMENTOR_MODEL_MINIMAL, 16);
  }

  ofs.write(chunk, 16);

  if (full) {
    ofs.write(reinterpret_cast<const char *>(&end_time), sizeof(int));
  }

  int off = ofs.tellp();

  unsigned labels_offset    = 0;
  unsigned lexicon_offset   = 0;
  unsigned feature_offset   = 0;
  unsigned parameter_offset   = 0;

  write_uint(ofs, 0); //  the label offset
  write_uint(ofs, 0); //  the internal lexicon offset
  write_uint(ofs, 0); //  the features offset
  write_uint(ofs, 0); //  the parameter offset

  labels_offset = ofs.tellp();
  labels.dump(ofs);

  lexicon_offset = ofs.tellp();
  internal_lexicon.dump(ofs);

  feature_offset = ofs.tellp();
  space.dump(ofs);

  parameter_offset = ofs.tellp();
  param.dump(ofs, full);

  ofs.seekp(off);
  write_uint(ofs, labels_offset);
  write_uint(ofs, lexicon_offset);
  write_uint(ofs, feature_offset);
  write_uint(ofs, parameter_offset);
}
Пример #23
0
void Title::print(std::ostream& os) {
  os << "TLDR - " + name + "\n"; // format of first line
  for (auto i = name.length() + 7; i > 0; --i) { // underlining
    os << '=';
  }
  os << "\n\n";
  position = os.tellp(); // record the position of printing
}
Пример #24
0
void FGaussShell::PrintAligned( std::ostream &xout, uint Indent ) const
{
   using namespace fmt;
   std::streampos
      p0 = xout.tellp(),
      p1;
//    xout << fi(iCenter, 3) << " "
   xout << fi(pFn->Contractions.size(), 3) << ":"
        << "spdfghiklm"[AngularMomentum()]
        << "   "
        << ff(vCenter[0],8,4) << " " << ff(vCenter[1],8,4) << " " << ff(vCenter[2],8,4)
        << "    ";
   p1 = xout.tellp();

   for ( uint iExp = 0; iExp < pFn->Exponents.size(); ++ iExp ){
      if ( iExp != 0 ){
         xout << "\n";
         for ( uint i = 0; i < Indent + p1 - p0; ++ i )
            xout << " ";
      }
      xout << fmt::ff(pFn->Exponents[iExp],16,7) << "  ";

      double
         fRenorm = 1.0/GaussNormalizationSpher( pFn->Exponents[iExp], pFn->AngularMomentum );
//       fRenorm = 1.;
      std::stringstream
         str;
      for ( uint iCo = 0; iCo < pFn->Contractions.size(); ++ iCo ){
         aic::FGaussBfn::FContraction const
            &Co = pFn->Contractions[iCo];
         uint
            w = 9, p = 5;
         if ( Co.nBegin <= iExp && iExp < Co.nEnd ) {
            str << " " << fmt::ff(Co.Coeffs[iExp - Co.nBegin]*fRenorm, w, p);
         } else {
            str << " " << fmt::fc("  - - - -", w);
         }
      }
      std::string
         s = str.str();
      while( !s.empty() && (s[s.size()-1] == ' ' || s[s.size()-1] == '-' ) )
         s.resize(s.size() - 1);
      xout << s;
   }
}
Пример #25
0
bool ObjectLux::serialize(std::ostream& os) const
{
	const std::istream::pos_type startPos = os.tellp();

	ibeo::writeLE(os, m_id);
	ibeo::writeLE(os, m_age);
	ibeo::writeLE(os, m_predictionAge);
	ibeo::writeLE(os, m_relativeTimestamp);
	m_refPoint.serialize(os);
	m_refPointSigma.serialize(os);
	m_closestPoint.serialize(os);
	m_boundingBoxCenter.serialize(os);

	ibeo::writeLE(os, m_boundingBoxWidth);
	ibeo::writeLE(os, m_boundingBoxLength);

	m_objectBoxCenter.serialize(os);
	ibeo::writeLE(os, m_objectBoxSizeX);
	ibeo::writeLE(os, m_objectBoxSizeY);
	ibeo::writeLE(os, m_objectBoxOrientation);

	m_absVelocity.serialize(os);
	ibeo::writeLE(os, m_absVelSigmaX);
	ibeo::writeLE(os, m_absVelSigmaY);

	m_relVelocity.serialize(os);

	const UINT16 c=m_class;
	ibeo::writeLE(os, c);

	ibeo::writeLE(os, m_classAge);
	ibeo::writeLE(os, m_classCertainty);

	if (m_numContourPointsIsValid)
		ibeo::writeLE(os, m_numContourPoints);
	else
		ibeo::writeLE(os, ObjectLux::contourIsInvalid);

	std::vector<Point2d>::const_iterator cpIter = m_contourPoints.begin();
	for (; cpIter != m_contourPoints.end(); ++cpIter) {
		cpIter->serialize(os);
	}

	return !os.fail() && ((os.tellp() - startPos) == this->getSerializedSize());
}
Пример #26
0
void ABCVm::writeBranchAddress(std::map<uint32_t,BasicBlock>& basicBlocks, int here, int offset, std::ostream& out)
{
	int dest=here+offset;
	auto it=basicBlocks.find(dest);
	assert(it!=basicBlocks.end());
	//We need to add a fixup for this branch
	it->second.fixups.push_back(out.tellp());
	writeInt32(out, 0xffffffff);
}
Пример #27
0
/** Write data to a file section.
 *
 *   @param f       Output steam to which to write
 *   @param offset  Byte offset relative to start of this section
 *   @param bufsize Size of @p buf in bytes
 *   @param buf     Buffer of bytes to be written
 *
 *  @returns Returns the section-relative byte offset for the first byte beyond what would have been written if all bytes
 *  of the buffer were written.
 *
 *  The buffer is allowed to extend past the end of the section as long as the part that extends beyond is all zeros. The
 *  zeros will not be written to the output file.  Furthermore, any trailing zeros that extend beyond the end of the file will
 *  not be written (end-of-file is determined by SgAsmGenericFile::get_orig_size()) */
rose_addr_t
SgAsmGenericSection::write(std::ostream &f, rose_addr_t offset, size_t bufsize, const void *buf) const
{
    size_t nwrite, nzero;

    ROSE_ASSERT(this != NULL);

    /* Don't write past end of section */
    if (offset>=get_size()) {
        nwrite = 0;
        nzero  = bufsize;
    } else if (offset+bufsize<=get_size()) {
        nwrite = bufsize;
        nzero = 0;
    } else {
        nwrite = get_size() - offset;
        nzero = bufsize - nwrite;
    }

    /* Don't write past end of current EOF if we can help it. */
    f.seekp(0, std::ios::end);
    rose_addr_t filesize = f.tellp();
    while (nwrite>0 && 0==((const char*)buf)[nwrite-1] && get_offset()+offset+nwrite>filesize)
        --nwrite;

    /* Write bytes to file. This is a good place to set a break point if you're trying to figure out what section is writing
     * to a particular file address. For instance, if byte 0x7c is incorrect in the unparsed file you would set a conditional
     * breakpoint for o<=0x7c && o+nwrite>0x7c */
    ROSE_ASSERT(f);
    off_t o = get_offset() + offset;
    f.seekp(o);
    ROSE_ASSERT(f);
    f.write((const char*)buf, nwrite);
    ROSE_ASSERT(f);

    /* Check that truncated data is all zero and fail if it isn't */
    for (size_t i=nwrite; i<bufsize; i++) {
        if (((const char*)buf)[i]) {
            char mesg[1024];
            sprintf(mesg, "non-zero value truncated: buf[0x%zx]=0x%02x", i, ((const unsigned char*)buf)[i]);
            fprintf(stderr, "SgAsmGenericSection::write: error: %s", mesg);
            fprintf(stderr, " in [%d] \"%s\"\n", get_id(), get_name()->get_string(true).c_str());
            fprintf(stderr, "    section is at file offset 0x%08"PRIx64" (%"PRIu64"), size 0x%"PRIx64" (%"PRIu64") bytes\n", 
                    get_offset(), get_offset(), get_size(), get_size());
            fprintf(stderr, " write %" PRIuPTR " byte%s at section offset 0x%08"PRIx64"\n", bufsize, 1==bufsize?"":"s", offset);
            fprintf(stderr, "      ");
            HexdumpFormat hf;
            hf.prefix = "      ";
            hexdump(stderr, get_offset()+offset, (const unsigned char*)buf, bufsize, hf);
            fprintf(stderr, "\n");
            throw SgAsmGenericFile::ShortWrite(this, offset, bufsize, mesg);
        }
    }

    return offset+bufsize;
}
Пример #28
0
bool ObjectListEcu::serialize(std::ostream& os) const
{
	const std::istream::pos_type startPos = os.tellp();

	lock();

	ibeo::writeBE(os, m_scanStartTimestamp);
	const UINT16 nbOfObjects = this->m_objects.size();
	ibeo::writeBE(os, nbOfObjects);

	std::vector<ObjectEcu>::const_iterator objIter = m_objects.begin();
	for (; objIter != m_objects.end(); ++objIter) {
		objIter->serialize(os);
	}

	unlock();

	return !os.fail() && ((os.tellp() - startPos) == this->getSerializedSize());
}
Пример #29
0
void BoWBinaryWriter::writeHeader(std::ostream& file, BoWFileType type) const
{
  BOWLOGINIT;
  LDEBUG << "BoWBinaryWriter::writeHeader version=" << BOW_VERSION << " ; type=" << type;
    Misc::writeString(file,BOW_VERSION);
    Misc::writeOneByteInt(file,type);
    // write entity types
    MediaticData::MediaticData::single().writeEntityTypes(file);
    LDEBUG << "BoWBinaryWriter::writeHeader end file at: " << file.tellp();
}
Пример #30
0
	void disktree_writer::write(std::ostream &out)
	{
		loga("Writing title index");
		if (! stree_.m_root)
		{
			constexpr treesize fill{0};
			for (int i = 0; i < 2; i++) zsr::serialize(out, fill);
			return;
		}
		recursive_treewrite(out, stree_.m_root, static_cast<zsr::offset>(out.tellp()));
	}