/********************************************************************** * TABMAPToolBlock::InitNewBlock() * * Initialize a newly created block so that it knows to which file it * is attached, its block size, etc . and then perform any specific * initialization for this block type, including writing a default * block header, etc. and leave the block ready to receive data. * * This is an alternative to calling ReadFromFile() or InitBlockFromData() * that puts the block in a stable state without loading any initial * data in it. * * Returns 0 if successful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/ int TABMAPToolBlock::InitNewBlock(VSILFILE *fpSrc, int nBlockSize, int nFileOffset /* = 0*/) { #ifdef DEBUG_VERBOSE CPLDebug( "MITAB", "Instantiating new TOOL block at offset %d", nFileOffset); #endif /*----------------------------------------------------------------- * Start with the default initialization *----------------------------------------------------------------*/ if ( TABRawBinBlock::InitNewBlock(fpSrc, nBlockSize, nFileOffset) != 0) return -1; /*----------------------------------------------------------------- * And then set default values for the block header. *----------------------------------------------------------------*/ m_nNextToolBlock = 0; m_numDataBytes = 0; GotoByteInBlock(0x000); if (m_eAccess != TABRead) { WriteInt16(TABMAP_TOOL_BLOCK); // Block type code WriteInt16(0); // num. bytes used, excluding header WriteInt32(0); // Pointer to next tool block } if (CPLGetLastErrorNo() != 0) return -1; return 0; }
/********************************************************************** * TABMAPIndexBlock::InitNewBlock() * * Initialize a newly created block so that it knows to which file it * is attached, its block size, etc . and then perform any specific * initialization for this block type, including writing a default * block header, etc. and leave the block ready to receive data. * * This is an alternative to calling ReadFromFile() or InitBlockFromData() * that puts the block in a stable state without loading any initial * data in it. * * Returns 0 if succesful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/ int TABMAPIndexBlock::InitNewBlock(FILE *fpSrc, int nBlockSize, int nFileOffset /* = 0*/) { /*----------------------------------------------------------------- * Start with the default initialisation *----------------------------------------------------------------*/ if ( TABRawBinBlock::InitNewBlock(fpSrc, nBlockSize, nFileOffset) != 0) return -1; /*----------------------------------------------------------------- * And then set default values for the block header. *----------------------------------------------------------------*/ m_numEntries = 0; m_nMinX = 1000000000; m_nMinY = 1000000000; m_nMaxX = -1000000000; m_nMaxY = -1000000000; if (m_eAccess != TABRead) { GotoByteInBlock(0x000); WriteInt16(TABMAP_INDEX_BLOCK); // Block type code WriteInt16(0); // num. index entries } if (CPLGetLastErrorNo() != 0) return -1; return 0; }
static void WriteWaveMp3( FILE * file, hb_wave_mp3_t * mp3 ) { WriteInt16( file, mp3->Id ); WriteInt32( file, mp3->Flags ); WriteInt16( file, mp3->BlockSize ); WriteInt16( file, mp3->FramesPerBlock ); WriteInt16( file, mp3->CodecDelay ); }
static void WriteWaveFormatEx( FILE * file, hb_wave_formatex_t * format ) { WriteInt32( file, format->FourCC ); WriteInt32( file, format->BytesCount ); WriteInt16( file, format->FormatTag ); WriteInt16( file, format->Channels ); WriteInt32( file, format->SamplesPerSec ); WriteInt32( file, format->AvgBytesPerSec ); WriteInt16( file, format->BlockAlign ); WriteInt16( file, format->BitsPerSample ); WriteInt16( file, format->Size ); }
size_t UpdateWindowProperty::serialize(Buffer& _dst, size_t _offset) { _pm_checkInit(); if(_offset == 0) _dst.clear(); _offset = WriteInt8(_dst, _offset, _pf_packetId); _offset = WriteInt8(_dst, _offset, _pf_windowId); _offset = WriteInt16(_dst, _offset, _pf_property); _offset = WriteInt16(_dst, _offset, _pf_value); return _offset; }
/********************************************************************** * TABMAPIndexBlock::CommitToFile() * * Commit the current state of the binary block to the file to which * it has been previously attached. * * This method makes sure all values are properly set in the map object * block header and then calls TABRawBinBlock::CommitToFile() to do * the actual writing to disk. * * Returns 0 if succesful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/ int TABMAPIndexBlock::CommitToFile() { int nStatus = 0; if ( m_pabyBuf == NULL ) { CPLError(CE_Failure, CPLE_AssertionFailed, "CommitToFile(): Block has not been initialized yet!"); return -1; } /*----------------------------------------------------------------- * Commit child first *----------------------------------------------------------------*/ if (m_poCurChild) { if (m_poCurChild->CommitToFile() != 0) return -1; } /*----------------------------------------------------------------- * Make sure 4 bytes block header is up to date. *----------------------------------------------------------------*/ GotoByteInBlock(0x000); WriteInt16(TABMAP_INDEX_BLOCK); // Block type code WriteInt16(m_numEntries); nStatus = CPLGetLastErrorNo(); /*----------------------------------------------------------------- * Loop through all entries, writing each of them, and calling * CommitToFile() (recursively) on any child index entries we may * encounter. *----------------------------------------------------------------*/ for(int i=0; nStatus == 0 && i<m_numEntries; i++) { if (nStatus == 0) nStatus = WriteNextEntry(&(m_asEntries[i])); } /*----------------------------------------------------------------- * OK, call the base class to write the block to disk. *----------------------------------------------------------------*/ if (nStatus == 0) nStatus = TABRawBinBlock::CommitToFile(); return nStatus; }
size_t ItemData::serialize(Buffer& _dst, size_t _offset) { _pm_checkInit(); if(_offset == 0) _dst.clear(); _offset = WriteInt8(_dst, _offset, _pf_packetId); _offset = WriteInt16(_dst, _offset, _pf_itemType); _offset = WriteInt16(_dst, _offset, _pf_itemId); _offset = WriteInt16(_dst, _offset, _pf_textLength); _offset = WriteByteArray(_dst, _offset, _pf_text); return _offset; }
static void WriteBitmapInfo( FILE * file, hb_bitmap_info_t * info ) { WriteInt32( file, info->FourCC ); WriteInt32( file, info->BytesCount ); WriteInt32( file, info->Size ); WriteInt32( file, info->Width ); WriteInt32( file, info->Height ); WriteInt16( file, info->Planes ); WriteInt16( file, info->BitCount ); WriteInt32( file, info->Compression ); WriteInt32( file, info->SizeImage ); WriteInt32( file, info->XPelsPerMeter ); WriteInt32( file, info->YPelsPerMeter ); WriteInt32( file, info->ClrUsed ); WriteInt32( file, info->ClrImportant ); }
/********************************************************************** * TABRawBinBlock::CommitAsDeleted() * * Commit current block to file using block type 4 (garbage block) * * Returns 0 if successful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/ int TABRawBinBlock::CommitAsDeleted(GInt32 nNextBlockPtr) { CPLErrorReset(); if ( m_pabyBuf == nullptr ) { CPLError(CE_Failure, CPLE_AssertionFailed, "CommitAsDeleted(): Block has not been initialized yet!"); return -1; } /*----------------------------------------------------------------- * Create deleted block header *----------------------------------------------------------------*/ GotoByteInBlock(0x000); WriteInt16(TABMAP_GARB_BLOCK); // Block type code WriteInt32(nNextBlockPtr); int nStatus = CPLGetLastErrorType() == CE_Failure ? -1 : 0; /*----------------------------------------------------------------- * OK, call the base class to write the block to disk. *----------------------------------------------------------------*/ if (nStatus == 0) { #ifdef DEBUG_VERBOSE CPLDebug("MITAB", "Committing GARBAGE block to offset %d", m_nFileOffset); #endif nStatus = TABRawBinBlock::CommitToFile(); m_nSizeUsed = 0; } return nStatus; }
size_t ClickWindow::serialize(Buffer& _dst, size_t _offset) { _pm_checkInit(); if(_offset == 0) _dst.clear(); _offset = WriteInt8(_dst, _offset, _pf_packetId); _offset = WriteInt8(_dst, _offset, _pf_windowId); _offset = WriteInt16(_dst, _offset, _pf_slot); _offset = WriteInt8(_dst, _offset, _pf_button); _offset = WriteInt16(_dst, _offset, _pf_actionNumber); _offset = WriteInt8(_dst, _offset, _pf_mode); //_offset = WriteSlotData(_dst, _offset, _pf_clickedItem); _offset = _pf_clickedItem.serialize(_dst, _offset); return _offset; }
static HRESULT WriteWavHeader(FILE *fpw, WWMFPcmFormat &format, DWORD dataBytes) { HRESULT hr = E_FAIL; int dataChunkSize = ((dataBytes+1)&(~1)) + 4; HRG(WriteBytes(fpw, "RIFF", 4U)); HRG(WriteInt32(fpw, dataChunkSize + 0x24)); HRG(WriteBytes(fpw, "WAVE", 4U)); HRG(WriteBytes(fpw, "fmt ", 4U)); HRG(WriteInt32(fpw, 16)); // fmt audioFormat size==2 1==int 3==float switch (format.sampleFormat) { case WWMFBitFormatInt: HRG(WriteInt16(fpw, 1)); break; case WWMFBitFormatFloat: HRG(WriteInt16(fpw, 3)); break; default: goto end; } // fmt numChannels size==2 HRG(WriteInt16(fpw, format.nChannels)); // fmt sampleRate size==4 HRG(WriteInt32(fpw, format.sampleRate)); // fmt byteRate size==4 HRG(WriteInt32(fpw, format.BytesPerSec())); // fmt blockAlign size==2 HRG(WriteInt16(fpw, format.FrameBytes())); // fmt bitspersample size==2 HRG(WriteInt16(fpw, format.bits)); HRG(WriteBytes(fpw, "data", 4U)); HRG(WriteInt32(fpw, dataChunkSize)); end: return hr; }
//serializes a FdoDateTime void BinaryWriter::WriteDateTime(FdoDateTime dt) { WriteInt16(dt.year); WriteChar(dt.month); WriteChar(dt.day); WriteChar(dt.hour); WriteChar(dt.minute); WriteSingle(dt.seconds); }
void StreamWriter::WriteASCIIZ(const char* str) { const long len = (long)strlen(str); RDE_ASSERT(len < 32768 && "String too long, cannot write to stream"); WriteInt16(rde::uint16_t(len)); if (len > 0) { Write(str, len); } }
/********************************************************************** * TABMAPToolBlock::CommitToFile() * * Commit the current state of the binary block to the file to which * it has been previously attached. * * This method makes sure all values are properly set in the map object * block header and then calls TABRawBinBlock::CommitToFile() to do * the actual writing to disk. * * Returns 0 if successful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/ int TABMAPToolBlock::CommitToFile() { int nStatus = 0; if ( m_pabyBuf == NULL ) { CPLError(CE_Failure, CPLE_AssertionFailed, "CommitToFile(): Block has not been initialized yet!"); return -1; } /*----------------------------------------------------------------- * Nothing to do here if block has not been modified *----------------------------------------------------------------*/ if (!m_bModified) return 0; /*----------------------------------------------------------------- * Make sure 8 bytes block header is up to date. *----------------------------------------------------------------*/ GotoByteInBlock(0x000); WriteInt16(TABMAP_TOOL_BLOCK); // Block type code CPLAssert(m_nSizeUsed >= MAP_TOOL_HEADER_SIZE && m_nSizeUsed < MAP_TOOL_HEADER_SIZE + 32768); WriteInt16((GInt16)(m_nSizeUsed - MAP_TOOL_HEADER_SIZE)); // num. bytes used WriteInt32(m_nNextToolBlock); nStatus = CPLGetLastErrorNo(); /*----------------------------------------------------------------- * OK, call the base class to write the block to disk. *----------------------------------------------------------------*/ if (nStatus == 0) { #ifdef DEBUG_VERBOSE CPLDebug("MITAB", "Committing TOOL block to offset %d", m_nFileOffset); #endif nStatus = TABRawBinBlock::CommitToFile(); } return nStatus; }
void Packet::WriteData(char* value, int length) { int len = length; //strlen(value)+1; WriteInt16(len); data.resize(data.size() + len); for(int i=0; i!=len; i++) { data[data.size() - len + i] = value[i]; //memcpy(&data[data.size() - strlen(value) + i], &value[i], sizeof(char)); } }
size_t SetSlot::serialize(Buffer& _dst, size_t _offset) { _pm_checkInit(); if(_offset == 0) _dst.clear(); _offset = WriteInt8(_dst, _offset, _pf_packetId); _offset = WriteInt8(_dst, _offset, _pf_windowId); _offset = WriteInt16(_dst, _offset, _pf_slotNum); return _offset; }
static void WriteVprpInfo( FILE * file, hb_avi_vprp_info_t * info ) { WriteInt32( file, info->FourCC ); WriteInt32( file, info->BytesCount ); WriteInt32( file, info->VideoFormatToken ); WriteInt32( file, info->VideoStandard ); WriteInt32( file, info->dwVerticalRefreshRate ); WriteInt32( file, info->dwHTotalInT ); WriteInt32( file, info->dwVTotalInLines ); WriteInt16( file, info->dwFrameAspectRatioDen ); WriteInt16( file, info->dwFrameAspectRatioNum ); WriteInt32( file, info->dwFrameWidthInPixels ); WriteInt32( file, info->dwFrameHeightInLines ); WriteInt32( file, info->nbFieldPerFrame ); WriteInt32( file, info->CompressedBMHeight ); WriteInt32( file, info->CompressedBMWidth ); WriteInt32( file, info->ValidBMHeight ); WriteInt32( file, info->ValidBMWidth ); WriteInt32( file, info->ValidBMXOffset ); WriteInt32( file, info->ValidBMYOffset ); WriteInt32( file, info->VideoXOffsetInT ); WriteInt32( file, info->VideoYValidStartLine ); }
size_t MapChunkBulk::serialize(Buffer& _dst, size_t _offset) { _pm_checkInit(); if(_offset == 0) _dst.clear(); _offset = WriteInt8(_dst, _offset, _pf_packetId); _offset = WriteInt16(_dst, _offset, _pf_chunkColumnCount); _offset = WriteInt32(_dst, _offset, _pf_dataLength); _offset = WriteBool(_dst, _offset, _pf_skyLightSent); _offset = WriteByteArray(_dst, _offset, _pf_chunkData); _offset = WriteByteArray(_dst, _offset, _pf_metaInfo); return _offset; }
static void WriteStreamHeader( FILE * file, hb_avi_stream_header_t * header ) { WriteInt32( file, header->FourCC ); WriteInt32( file, header->BytesCount ); WriteInt32( file, header->Type ); WriteInt32( file, header->Handler ); WriteInt32( file, header->Flags ); WriteInt16( file, header->Priority ); WriteInt16( file, header->Language ); WriteInt32( file, header->InitialFrames ); WriteInt32( file, header->Scale ); WriteInt32( file, header->Rate ); WriteInt32( file, header->Start ); WriteInt32( file, header->Length ); WriteInt32( file, header->SuggestedBufferSize ); WriteInt32( file, header->Quality ); WriteInt32( file, header->SampleSize ); WriteInt16( file, header->Left ); WriteInt16( file, header->Top ); WriteInt16( file, header->Right ); WriteInt16( file, header->Bottom ); }
/********************************************************************** * TABMAPHeaderBlock::CommitToFile() * * Commit the current state of the binary block to the file to which * it has been previously attached. * * This method makes sure all values are properly set in the header * block buffer and then calls TABRawBinBlock::CommitToFile() to do * the actual writing to disk. * * Returns 0 if succesful or -1 if an error happened, in which case * CPLError() will have been called. **********************************************************************/ int TABMAPHeaderBlock::CommitToFile() { int i, nStatus = 0; if ( m_pabyBuf == NULL || m_nBlockSize != HDR_DATA_BLOCK_SIZE ) { CPLError(CE_Failure, CPLE_AssertionFailed, "TABRawBinBlock::CommitToFile(): Block has not been initialized yet!"); return -1; } /*----------------------------------------------------------------- * Reconstruct header to make sure it is in sync with members variables. *----------------------------------------------------------------*/ GotoByteInBlock(0x000); WriteBytes(HDR_OBJ_LEN_ARRAY_SIZE, gabyObjLenArray); m_nMaxObjLenArrayId = HDR_OBJ_LEN_ARRAY_SIZE-1; GotoByteInBlock(0x100); WriteInt32(HDR_MAGIC_COOKIE); WriteInt16(m_nMAPVersionNumber); WriteInt16(HDR_DATA_BLOCK_SIZE); WriteDouble(m_dCoordsys2DistUnits); WriteInt32(m_nXMin); WriteInt32(m_nYMin); WriteInt32(m_nXMax); WriteInt32(m_nYMax); WriteZeros(16); // ??? WriteInt32(m_nFirstIndexBlock); WriteInt32(m_nFirstGarbageBlock); WriteInt32(m_nFirstToolBlock); WriteInt32(m_numPointObjects); WriteInt32(m_numLineObjects); WriteInt32(m_numRegionObjects); WriteInt32(m_numTextObjects); WriteInt32(m_nMaxCoordBufSize); WriteZeros(14); // ??? WriteByte(m_nDistUnitsCode); WriteByte(m_nMaxSpIndexDepth); WriteByte(m_nCoordPrecision); WriteByte(m_nCoordOriginQuadrant); WriteByte(m_nReflectXAxisCoord); WriteByte(m_nMaxObjLenArrayId); // See gabyObjLenArray[] WriteByte(m_numPenDefs); WriteByte(m_numBrushDefs); WriteByte(m_numSymbolDefs); WriteByte(m_numFontDefs); WriteInt16(m_numMapToolBlocks); WriteZeros(3); // ??? WriteByte(m_sProj.nProjId); WriteByte(m_sProj.nEllipsoidId); WriteByte(m_sProj.nUnitsId); WriteDouble(m_XScale); WriteDouble(m_YScale); WriteDouble(m_XDispl); WriteDouble(m_YDispl); for(i=0; i<6; i++) WriteDouble(m_sProj.adProjParams[i]); WriteDouble(m_sProj.dDatumShiftX); WriteDouble(m_sProj.dDatumShiftY); WriteDouble(m_sProj.dDatumShiftZ); for(i=0; i<5; i++) WriteDouble(m_sProj.adDatumParams[i]); /*----------------------------------------------------------------- * OK, call the base class to write the block to disk. *----------------------------------------------------------------*/ if (nStatus == 0) nStatus = TABRawBinBlock::CommitToFile(); return nStatus; }
void Packet::WriteId(int value) { WriteInt16(value); id = value; }
int NetManager::ListenThread(void* np) { NetManager* net = (NetManager*)np; if(listen(net->sListen, SOMAXCONN) == SOCKET_ERROR) { closesocket(net->sListen); return 0; } int recvlen, index; char* pbuf, *psbuf; net->sRemote = accept(net->sListen, 0, 0); while(net->sRemote != SOCKET_ERROR) { recvlen = recv(net->sRemote, net->recv_buf, 4096, 0); if(recvlen == SOCKET_ERROR) { closesocket(net->sRemote); net->sRemote = accept(net->sListen, 0, 0); continue; } //check deck pbuf = net->recv_buf; int ver = ReadInt16(pbuf); if(ver != PROTO_VERSION) { psbuf = net->send_buf; WriteInt8(psbuf, 0x1); WriteInt16(psbuf, PROTO_VERSION); send(net->sRemote, net->send_buf, 3, 0); closesocket(net->sRemote); net->sRemote = accept(net->sListen, 0, 0); continue; } wchar_t cn = ReadInt16(pbuf); int off = 0; while(cn != 0 && off < 19) { mainGame->dInfo.pass[off++] = cn; cn = ReadInt16(pbuf); } mainGame->dInfo.pass[off] = 0; if(wcscmp(mainGame->dInfo.pass, mainGame->ebServerPass->getText())) { psbuf = net->send_buf; WriteInt8(psbuf, 0x3); send(net->sRemote, net->send_buf, 1, 0); closesocket(net->sRemote); net->sRemote = accept(net->sListen, 0, 0); continue; } cn = ReadInt16(pbuf); off = 0; while(cn != 0 && off < 19) { mainGame->dInfo.clientname[off++] = cn; cn = ReadInt16(pbuf); } mainGame->dInfo.clientname[off] = 0; int maincount = ReadInt16(pbuf); int sidecount = ReadInt16(pbuf); mainGame->deckManager.LoadDeck(mainGame->deckManager.deckclient, (int*)pbuf, maincount, sidecount); if(!net->hInfo.no_check_deck && !mainGame->deckManager.CheckLFList(mainGame->deckManager.deckclient, net->hInfo.lfindex)) { psbuf = net->send_buf; WriteInt8(psbuf, 0x2); send(net->sRemote, net->send_buf, 1, 0); closesocket(net->sRemote); net->sRemote = accept(net->sListen, 0, 0); continue; } psbuf = net->send_buf; WriteInt8(psbuf, 0); const wchar_t* ln = mainGame->ebUsername->getText(); int li = 0; while(ln[li] && li < 19) { mainGame->dInfo.hostname[li] = ln[li]; WriteInt16(psbuf, ln[li++]); } mainGame->dInfo.hostname[li] = 0; WriteInt16(psbuf, 0); send(net->sRemote, net->send_buf, 3 + li * 2, 0); mainGame->gMutex.Lock(); mainGame->imgCard->setImage(mainGame->imageManager.tCover); mainGame->wCardImg->setVisible(true); mainGame->wInfos->setVisible(true); mainGame->stName->setText(L""); mainGame->stInfo->setText(L""); mainGame->stDataInfo->setText(L""); mainGame->stText->setText(L""); mainGame->stModeStatus->setText(L""); mainGame->dInfo.engLen = 0; mainGame->dInfo.msgLen = 0; mainGame->dField.Clear(); mainGame->HideElement(mainGame->wModeSelection); mainGame->gMutex.Unlock(); mainGame->WaitFrameSignal(10); closesocket(net->sBHost); net->is_creating_host = false; Thread::NewThread(Game::EngineThread, &mainGame->dInfo); Thread::NewThread(Game::GameThread, &mainGame->dInfo); break; } return 0; }