size_t Buffer::writeString16(String16 _src, size_t _offset) { if(_offset != npos) _pf_writeOffset = _offset; else _pf_writeOffset = _pf_buffer.size(); writeInt16(_src.size(), _pf_writeOffset); for(int i = 0; i < _src.size(); ++i) writeInt16(_src[i], _offset); return _pf_writeOffset; }
void MessageOut::writeString(const std::string &string, int length) { int stringLength = string.length(); if (length < 0) { // Write the length at the start if not fixed writeInt16(stringLength); length = stringLength; } else if (length < stringLength) { // Make sure the length of the string is no longer than specified stringLength = length; } #ifdef TMWSERV_SUPPORT expand(mPos + length); #else mNetwork->mOutSize += length; #endif // Write the actual string memcpy(mData + mPos, string.c_str(), stringLength); // Pad remaining space with zeros if (length > stringLength) { memset(mData + mPos + stringLength, '\0', length - stringLength); } mPos += length; }
MessageOut::MessageOut(short id): Net::MessageOut(id) { mNetwork = TmwAthena::Network::instance(); mData = mNetwork->mOutBuffer + mNetwork->mOutSize; writeInt16(id); }
void MessageOut::writeString(const std::string &string, int length) { int stringLength = string.length(); if (length < 0) { // Write the length at the start if not fixed writeInt16(stringLength); length = stringLength; } else if (length < stringLength) { // Make sure the length of the string is no longer than specified stringLength = length; } expand(length); // Write the actual string memcpy(mData + mPos, string.data(), stringLength); // Pad remaining space with zeros if (length > stringLength) { memset(mData + mPos + stringLength, '\0', length - stringLength); } mPos += length; }
//-------------------------------------------------------------- void DataStream::writeInt16BE(i16 n) { #ifdef AZURA_LITTLE_ENDIAN _s2((_2*)&n); #endif writeInt16(n); }
void BaseSerializedObj::writeInt16Array(int16_t array[], uint64_t s) { writeUInt64(s); uint64_t i = 0; while ( i!=s ) { writeInt16(array[i]); i++; } }
MessageOut::MessageOut(const int16_t id, const char *const str) : Net::MessageOut(id), mNetwork(EAthena::Network::instance()) { mNetwork->fixSendBuffer(); mData = mNetwork->mOutBuffer + static_cast<size_t>(mNetwork->mOutSize); // +++ can be issue. call to virtual member writeInt16(id, str); }
MessageOut::MessageOut(short id): mData(0), mDataSize(0), mPos(0) { #ifdef EATHENA_SUPPORT mNetwork = Network::instance(); mData = mNetwork->mOutBuffer + mNetwork->mOutSize; #endif writeInt16(id); }
MessageOut::MessageOut(uint16_t id): Net::MessageOut(id) { writeInt16(id); }
void MPEG4Writer::stop() { if (mFile == NULL) { return; } int64_t max_duration = 0; for (List<Track *>::iterator it = mTracks.begin(); it != mTracks.end(); ++it) { (*it)->stop(); int64_t duration = (*it)->getDuration(); if (duration > max_duration) { max_duration = duration; } } // Fix up the size of the 'mdat' chunk. fseek(mFile, mMdatOffset + 8, SEEK_SET); int64_t size = mOffset - mMdatOffset; size = hton64(size); fwrite(&size, 1, 8, mFile); fseek(mFile, mOffset, SEEK_SET); time_t now = time(NULL); beginBox("moov"); beginBox("mvhd"); writeInt32(0); // version=0, flags=0 writeInt32(now); // creation time writeInt32(now); // modification time writeInt32(1000); // timescale writeInt32(max_duration); writeInt32(0x10000); // rate writeInt16(0x100); // volume writeInt16(0); // reserved writeInt32(0); // reserved writeInt32(0); // reserved writeInt32(0x10000); // matrix writeInt32(0); writeInt32(0); writeInt32(0); writeInt32(0x10000); writeInt32(0); writeInt32(0); writeInt32(0); writeInt32(0x40000000); writeInt32(0); // predefined writeInt32(0); // predefined writeInt32(0); // predefined writeInt32(0); // predefined writeInt32(0); // predefined writeInt32(0); // predefined writeInt32(mTracks.size() + 1); // nextTrackID endBox(); // mvhd int32_t id = 1; for (List<Track *>::iterator it = mTracks.begin(); it != mTracks.end(); ++it, ++id) { (*it)->writeTrackHeader(id); } endBox(); // moov CHECK(mBoxes.empty()); fclose(mFile); mFile = NULL; }
void initFileObject(lua_State* L) { luaL_newmetatable(L, meta<File>()); // Duplicate the metatable on the stack. lua_pushvalue(L, -1); // metatable.__index = metatable lua_setfield(L, -2, "__index"); // Put the members into the metatable. const luaL_Reg functions[] = { {"__gc", [](lua_State* L) { return script::wrapped<File>(L, 1)->gc(L); }}, {"__index", [](lua_State* L) { return script::wrapped<File>(L, 1)->index(L); }}, {"__newindex", [](lua_State* L) { return script::wrapped<File>(L, 1)->newindex(L); }}, {"__tostring", [](lua_State* L) { return script::wrapped<File>(L, 1)->tostring(L); }}, {"__pairs", [](lua_State* L) { return script::wrapped<File>(L, 1)->pairs(L); }}, {"close", [](lua_State* L) { auto file = script::ptr<File>(L, 1); file->close(); return 0; }}, {"readUnsigned8", [](lua_State* L) { auto file = script::ptr<File>(L, 1); uint8_t value; if(file->readUnsigned8(value)) { script::push(L, value); return 1; } return 0; }}, {"readUnsigned16", [](lua_State* L) { auto file = script::ptr<File>(L, 1); uint16_t value; if(file->readUnsigned16(value)) { script::push(L, value); return 1; } return 0; }}, {"readUnsigned32", [](lua_State* L) { auto file = script::ptr<File>(L, 1); uint32_t value; if(file->readUnsigned32(value)) { script::push(L, value); return 1; } return 0; }}, {"readInt8", [](lua_State* L) { auto file = script::ptr<File>(L, 1); int8_t value; if(file->readInt8(value)) { script::push(L, value); return 1; } return 0; }}, {"readInt16", [](lua_State* L) { auto file = script::ptr<File>(L, 1); int16_t value; if(file->readInt16(value)) { script::push(L, value); return 1; } return 0; }}, {"readInt32", [](lua_State* L) { auto file = script::ptr<File>(L, 1); int32_t value; if(file->readInt32(value)) { script::push(L, value); return 1; } return 0; }}, {"readFloat", [](lua_State* L) { auto file = script::ptr<File>(L, 1); float value; if(file->readFloat(value)) { script::push(L, value); return 1; } return 0; }}, {"readDouble", [](lua_State* L) { auto file = script::ptr<File>(L, 1); double value; if(file->readDouble(value)) { script::push(L, value); return 1; } return 0; }}, {"readString", [](lua_State* L) { auto file = script::ptr<File>(L, 1); auto blockSize = script::get<int>(L, 2); std::string buffer(blockSize, 0); if(file->readString(buffer)) { lua_pushlstring(L, buffer.data(), buffer.size()); return 1; } return 0; }}, {"readLine", [](lua_State* L) { auto file = script::ptr<File>(L, 1); std::string value; if(file->readLine(value)) { script::push(L, value.c_str()); return 1; } return 0; }}, {"readFully", [](lua_State* L) { auto file = script::ptr<File>(L, 1); // Get current position. auto pos = file->tell(); if(pos == -1) { return 0; } // Length to read = position of end - current. auto length = 0; if(!file->seek(pos, FileSeekMode::End)) { return 0; } length = file->tell() - pos; if(!file->seek(pos, FileSeekMode::Start)) { return 0; } // Read the entire file into a string. std::string buf(length, 0); if(file->readString(buf)) { lua_pushlstring(L, buf.data(), buf.size()); return 1; } return 0; }}, {"writeUnsigned8", [](lua_State* L) { auto file = script::ptr<File>(L, 1); auto value = script::get<int>(L, 2); script::push(L, file->writeUnsigned8(value)); return 1; }}, {"writeUnsigned16", [](lua_State* L) { auto file = script::ptr<File>(L, 1); auto value = script::get<int>(L, 2); script::push(L, file->writeUnsigned16(value)); return 1; }}, {"writeUnsigned32", [](lua_State* L) { auto file = script::ptr<File>(L, 1); auto value = script::get<int>(L, 2); script::push(L, file->writeUnsigned32(value)); return 1; }}, {"writeInt8", [](lua_State* L) { auto file = script::ptr<File>(L, 1); auto value = script::get<int>(L, 2); script::push(L, file->writeInt8(value)); return 1; }}, {"writeInt16", [](lua_State* L) { auto file = script::ptr<File>(L, 1); auto value = script::get<int>(L, 2); script::push(L, file->writeInt16(value)); return 1; }}, {"writeInt32", [](lua_State* L) { auto file = script::ptr<File>(L, 1); auto value = script::get<int>(L, 2); script::push(L, file->writeInt32(value)); return 1; }}, {"writeFloat", [](lua_State* L) { auto file = script::ptr<File>(L, 1); auto value = script::get<double>(L, 2); script::push(L, file->writeFloat((float) value)); return 1; }}, {"writeDouble", [](lua_State* L) { auto file = script::ptr<File>(L, 1); auto value = script::get<double>(L, 2); script::push(L, file->writeDouble(value)); return 1; }}, {"writeString", [](lua_State* L) { auto file = script::ptr<File>(L, 1); size_t length = 0; const char* buffer = luaL_checklstring(L, 2, &length); std::string value(buffer, buffer + length); script::push(L, file->writeString(value)); return 1; }}, {"writeLine", [](lua_State* L) { auto file = script::ptr<File>(L, 1); size_t length = 0; const char* buffer = luaL_checklstring(L, 2, &length); std::string value(buffer, buffer + length); script::push(L, file->writeLine(value)); return 1; }}, {"tell", [](lua_State* L) { auto file = script::ptr<File>(L, 1); script::push(L, int(file->tell())); return 1; }}, {"seek", [](lua_State* L) { auto file = script::ptr<File>(L, 1); auto position = script::get<int>(L, 2); auto mode = FileSeekMode(script::get<int>(L, 3)); script::push(L, file->seek(position, mode)); return 1; }}, {"flush", [](lua_State* L) { auto file = script::ptr<File>(L, 1); file->flush(); return 0; }}, {nullptr, nullptr}, }; luaL_setfuncs(L, functions, 0); lua_pop(L, 1); // Push plum namespace. lua_getglobal(L, "plum"); // plum.File = <function create> script::push(L, "File"); lua_pushcfunction(L, [](lua_State* L) { auto filename = script::get<const char*>(L, 1); auto mode = FileOpenMode(script::get<int>(L, 2)); auto f = new File(filename, mode); // Failure. if(!f->isActive()) { delete f; return 0; } script::push(L, f, LUA_NOREF); return 1; }); lua_settable(L, -3); // Pop plum namespace. lua_pop(L, 1); }
bool dxfWriterAscii::writeInt32(int code, int data) { return writeInt16(code, data); }
//-------------------------------------------------------------- void DataStream::writeUint16(u16 n) { writeInt16((i16)n); }