当前位置: 首页>>代码示例>>C++>>正文


C++ DataBuf类代码示例

本文整理汇总了C++中DataBuf的典型用法代码示例。如果您正苦于以下问题:C++ DataBuf类的具体用法?C++ DataBuf怎么用?C++ DataBuf使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DataBuf类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ml

	uint32 BufferPool::getBuffer(void)
	{
		DataBuf* buf = NULL;

		// lock mutex for reset
		MutexLocker ml(&_mutexReset);

		// decrement free buffers counter
		_semFree.wait();

		// get bid from stack
		buf = (DataBuf *) _psFree.pop();

		// check if there are no more free buffers
		if (!buf) {
			fprintf(stderr, "BufferPool: NO MORE FREE BUFFERS...\n");
			return 0;
		}

		// increment used buffers counter
		_semUsed.post();

		// return this bid
		return buf->getBID();
	}
开发者ID:BackupTheBerlios,项目名称:digixound-svn,代码行数:25,代码来源:bufferpool.cpp

示例2: encode

bool encode(DataBuf& buf, const OutBoundRpcMessage& msg) {
    using exec::rpc::RpcHeader;
    using google::protobuf::io::CodedOutputStream;
    // Todo:
    //
    // - let a context manager to allocate a buffer `ByteBuf buf = ctx.alloc().buffer();`
    // - builder pattern
    //
    #ifdef CODER_DEBUG
    std::cerr << "Encoding outbound message " << msg << std::endl;
    #endif

    RpcHeader header;
    header.set_mode(msg.m_mode);
    header.set_coordination_id(msg.m_coord_id);
    header.set_rpc_type(msg.m_rpc_type);

    // calcute the length of the message
    int header_length = header.ByteSize();
    int proto_body_length = msg.m_pbody->ByteSize();
    int full_length = HEADER_TAG_LENGTH + CodedOutputStream::VarintSize32(header_length) + header_length + \
                      PROTOBUF_BODY_TAG_LENGTH + CodedOutputStream::VarintSize32(proto_body_length) + proto_body_length;

    /*
       if(raw_body_length > 0) {
       full_length += (RAW_BODY_TAG_LENGTH + getRawVarintSize(raw_body_length) + raw_body_length);
       }
       */

    buf.resize(full_length + CodedOutputStream::VarintSize32(full_length));

    uint8_t* data = buf.data();

    #ifdef CODER_DEBUG
    std::cerr << "Writing full length " << full_length << std::endl;
    #endif

    data = CodedOutputStream::WriteVarint32ToArray(full_length, data);

    #ifdef CODER_DEBUG
    std::cerr << "Writing header length " << header_length << std::endl;
    #endif

    data = CodedOutputStream::WriteVarint32ToArray(HEADER_TAG, data);
    data = CodedOutputStream::WriteVarint32ToArray(header_length, data);

    data = header.SerializeWithCachedSizesToArray(data);

    // write protobuf body length and body
    #ifdef CODER_DEBUG
    std::cerr << "Writing protobuf body length " << proto_body_length << std::endl;
    #endif

    data = CodedOutputStream::WriteVarint32ToArray(PROTOBUF_BODY_TAG, data);
    data = CodedOutputStream::WriteVarint32ToArray(proto_body_length, data);
    msg.m_pbody->SerializeWithCachedSizesToArray(data);

    // Done! no read to write data body for client
    return true;
}
开发者ID:apache,项目名称:drill,代码行数:60,代码来源:rpcMessage.cpp

示例3: byteOrder

    void TiffImage::writeMetadata()
    {
#ifdef DEBUG
        std::cerr << "Writing TIFF file " << io_->path() << "\n";
#endif
        // Read existing image
        ByteOrder bo = byteOrder();
        DataBuf buf;
        if (io_->open() == 0) {
            IoCloser closer(*io_);
            // Ensure that this is the correct image type
            if (isTiffType(*io_, false)) {
                // Read the image into a memory buffer
                buf.alloc(io_->size());
                io_->read(buf.pData_, buf.size_);
                if (io_->error() || io_->eof()) {
                    buf.reset();
                }
                TiffHeader tiffHeader;
                if (0 == tiffHeader.read(buf.pData_, 8)) {
                    bo = tiffHeader.byteOrder();
                }
            }
        }
        if (bo == invalidByteOrder) {
            bo = littleEndian;
        }
        setByteOrder(bo);
        Blob blob;
        WriteMethod wm = TiffParser::encode(blob,
                                            buf.pData_,
                                            buf.size_,
                                            bo,
                                            exifData_,
                                            iptcData_,
                                            xmpData_);
        // Write updated or new buffer to file
        BasicIo::AutoPtr tempIo(io_->temporary()); // may throw
        assert(tempIo.get() != 0);
        if (wm == wmNonIntrusive) {
            // Buffer may be modified but size is unchanged, write buffer back
            tempIo->write(buf.pData_, buf.size_);
        }
        else {
            // Size of the buffer changed, write from blob
            tempIo->write(&blob[0], static_cast<long>(blob.size()));
        }
        io_->close();
        io_->transfer(*tempIo); // may throw

    } // TiffImage::writeMetadata
开发者ID:,项目名称:,代码行数:51,代码来源:

示例4: use

	DataBuf* BufferPool::use(uint32 bid)
	{
		DataBuf* buf = NULL;

		// lock mutex for reset
		MutexLocker ml(&_mutexReset);

		if (bid < _bcount) {
			buf = _bufs[bid];
			buf->setInUse(true);
		}

		// ok
		return buf;
	}
开发者ID:BackupTheBerlios,项目名称:digixound-svn,代码行数:15,代码来源:bufferpool.cpp

示例5:

 PreviewImage::PreviewImage(const PreviewProperties& properties, DataBuf data)
     : properties_(properties)
 {
     pData_ = data.pData_;
     size_ = data.size_;
     data.release();
 }
开发者ID:,项目名称:,代码行数:7,代码来源:

示例6: zlibUncompress

    void PngChunk::zlibUncompress(const byte*  compressedText, 
                                  unsigned int compressedTextSize, 
                                  DataBuf&     arr)
    {
        uLongf uncompressedLen = compressedTextSize * 2; // just a starting point
        int zlibResult;

        do
        {
            arr.alloc(uncompressedLen);
            zlibResult = uncompress((Bytef*)arr.pData_, &uncompressedLen,
                                    compressedText, compressedTextSize);

            if (zlibResult == Z_OK)
            {
                // then it is all OK
                arr.alloc(uncompressedLen);
            }
            else if (zlibResult == Z_BUF_ERROR)
            {
                // the uncompressedArray needs to be larger
#ifdef DEBUG
                std::cerr << "Exiv2::PngChunk::parsePngChunk: doubling size for decompression.\n";
#endif
                uncompressedLen *= 2;

                // DoS protection. can't be bigger than 64k
                if ( uncompressedLen > 131072 )
                    break;
            }
            else
            {
                // something bad happened
                throw Error(14);
            }
        }
        while (zlibResult == Z_BUF_ERROR);

        if (zlibResult != Z_OK)
            throw Error(14);

    } // PngChunk::zlibUncompress
开发者ID:,项目名称:,代码行数:42,代码来源:

示例7: nikonCrypt

    DataBuf nikonCrypt(uint16_t tag, const byte* pData, uint32_t size, TiffComponent* const pRoot)
    {
        DataBuf buf;

        if (size < 4) return buf;
        const NikonArrayIdx* nci = find(nikonArrayIdx, NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size));
        if (nci == 0 || nci->start_ == NA || size <= nci->start_) return buf;

        // Find Exif.Nikon3.ShutterCount
        TiffFinder finder(0x00a7, nikon3Id);
        pRoot->accept(finder);
        TiffEntryBase* te = dynamic_cast<TiffEntryBase*>(finder.result());
        if (!te || !te->pValue() || te->pValue()->count() == 0) return buf;
        uint32_t count = static_cast<uint32_t>(te->pValue()->toLong());

        // Find Exif.Nikon3.SerialNumber
        finder.init(0x001d, nikon3Id);
        pRoot->accept(finder);
        te = dynamic_cast<TiffEntryBase*>(finder.result());
        if (!te || !te->pValue() || te->pValue()->count() == 0) return buf;
        bool ok(false);
        uint32_t serial = stringTo<uint32_t>(te->pValue()->toString(), ok);
        if (!ok) {
            std::string model = getExifModel(pRoot);
            if (model.empty()) return buf;
            if (model.find("D50") != std::string::npos) {
                serial = 0x22;
            }
            else {
                serial = 0x60;
            }
        }
        buf.alloc(size);
        memcpy(buf.pData_, pData, buf.size_);
        ncrypt(buf.pData_ + nci->start_, buf.size_ - nci->start_, count, serial);
        return buf;
    }
开发者ID:,项目名称:,代码行数:37,代码来源:

示例8: Error

    void JpegBase::doWriteMetadata(BasicIo& outIo)
    {
        if (!io_->isopen()) throw Error(20);
        if (!outIo.isopen()) throw Error(21);

        // Ensure that this is the correct image type
        if (!isThisType(*io_, true)) {
            if (io_->error() || io_->eof()) throw Error(20);
            throw Error(22);
        }

        const long bufMinSize = 16;
        long bufRead = 0;
        DataBuf buf(bufMinSize);
        const long seek = io_->tell();
        int count = 0;
        int search = 0;
        int insertPos = 0;
        int skipApp1Exif = -1;
        int skipApp13Ps3 = -1;
        int skipCom = -1;
        DataBuf psData;

        // Write image header
        if (writeHeader(outIo)) throw Error(21);

        // Read section marker
        int marker = advanceToMarker();
        if (marker < 0) throw Error(22);

        // First find segments of interest. Normally app0 is first and we want
        // to insert after it. But if app0 comes after com, app1 and app13 then
        // don't bother.
        while (marker != sos_ && marker != eoi_ && search < 3) {
            // Read size and signature (ok if this hits EOF)
            bufRead = io_->read(buf.pData_, bufMinSize);
            if (io_->error()) throw Error(20);
            uint16_t size = getUShort(buf.pData_, bigEndian);

            if (marker == app0_) {
                if (size < 2) throw Error(22);
                insertPos = count + 1;
                if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(22);
            }
            else if (marker == app1_ && memcmp(buf.pData_ + 2, exifId_, 6) == 0) {
                if (size < 8) throw Error(22);
                skipApp1Exif = count;
                ++search;
                if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(22);
            }
            else if (marker == app13_ && memcmp(buf.pData_ + 2, Photoshop::ps3Id_, 14) == 0) {
                if (size < 16) throw Error(22);
                skipApp13Ps3 = count;
                ++search;
                // needed if bufMinSize!=16: io_->seek(16-bufRead, BasicIo::cur);
                psData.alloc(size - 16);
                // Load PS data now to allow reinsertion at any point
                io_->read(psData.pData_, psData.size_);
                if (io_->error() || io_->eof()) throw Error(20);
            }
            else if (marker == com_ && skipCom == -1) {
                if (size < 2) throw Error(22);
                // Jpegs can have multiple comments, but for now only handle
                // the first one (most jpegs only have one anyway).
                skipCom = count;
                ++search;
                if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(22);
            }
            else {
                if (size < 2) throw Error(22);
                if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(22);
            }
            marker = advanceToMarker();
            if (marker < 0) throw Error(22);
            ++count;
        }

        if (exifData_.count() > 0) ++search;
        if (iptcData_.count() > 0) ++search;
        if (!comment_.empty()) ++search;

        io_->seek(seek, BasicIo::beg);
        count = 0;
        marker = advanceToMarker();
        if (marker < 0) throw Error(22);

        // To simplify this a bit, new segments are inserts at either the start
        // or right after app0. This is standard in most jpegs, but has the
        // potential to change segment ordering (which is allowed).
        // Segments are erased if there is no assigned metadata.
        while (marker != sos_ && search > 0) {
            // Read size and signature (ok if this hits EOF)
            bufRead = io_->read(buf.pData_, bufMinSize);
            if (io_->error()) throw Error(20);
            // Careful, this can be a meaningless number for empty
            // images with only an eoi_ marker
            uint16_t size = getUShort(buf.pData_, bigEndian);

            if (insertPos == count) {
                byte tmpBuf[18];
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例9: lastMode

    void FileIo::transfer(BasicIo& src)
    {
        const bool wasOpen = (p_->fp_ != 0);
        const std::string lastMode(p_->openMode_);

        FileIo *fileIo = dynamic_cast<FileIo*>(&src);
        if (fileIo) {
            // Optimization if src is another instance of FileIo
            fileIo->close();
            // Check if the file can be written to, if it already exists
            if (open("a+b") != 0) {
                // Remove the (temporary) file
#ifdef EXV_UNICODE_PATH
                if (fileIo->p_->wpMode_ == Impl::wpUnicode) {
                    ::_wremove(fileIo->wpath().c_str());
                }
                else
#endif
                {
                    ::remove(fileIo->path().c_str());
                }
#ifdef EXV_UNICODE_PATH
                if (p_->wpMode_ == Impl::wpUnicode) {
                    throw WError(10, wpath(), "a+b", strError().c_str());
                }
                else
#endif
                {
                    throw Error(10, path(), "a+b", strError());
                }
            }
            close();

            bool statOk = true;
            mode_t origStMode = 0;
            std::string spf;
            char* pf = 0;
#ifdef EXV_UNICODE_PATH
            std::wstring wspf;
            wchar_t* wpf = 0;
            if (p_->wpMode_ == Impl::wpUnicode) {
                wspf = wpath();
                wpf = const_cast<wchar_t*>(wspf.c_str());
            }
            else
#endif
            {
                spf = path();
                pf = const_cast<char*>(spf.c_str());
            }

            // Get the permissions of the file, or linked-to file, on platforms which have lstat
#ifdef EXV_HAVE_LSTAT

# ifdef EXV_UNICODE_PATH
#  error EXV_UNICODE_PATH and EXV_HAVE_LSTAT are not compatible. Stop.
# endif
            struct stat buf1;
            if (::lstat(pf, &buf1) == -1) {
                statOk = false;
#ifndef SUPPRESS_WARNINGS
                EXV_WARNING << Error(2, pf, strError(), "::lstat") << "\n";
#endif
            }
            origStMode = buf1.st_mode;
            DataBuf lbuf; // So that the allocated memory is freed. Must have same scope as pf
            // In case path() is a symlink, get the path of the linked-to file
            if (statOk && S_ISLNK(buf1.st_mode)) {
                lbuf.alloc(buf1.st_size + 1);
                memset(lbuf.pData_, 0x0, lbuf.size_);
                pf = reinterpret_cast<char*>(lbuf.pData_);
                if (::readlink(path().c_str(), pf, lbuf.size_ - 1) == -1) {
                    throw Error(2, path(), strError(), "readlink");
                }
                // We need the permissions of the file, not the symlink
                if (::stat(pf, &buf1) == -1) {
                    statOk = false;
#ifndef SUPPRESS_WARNINGS
                    EXV_WARNING << Error(2, pf, strError(), "::stat") << "\n";
#endif
                }
                origStMode = buf1.st_mode;
            }
#else // EXV_HAVE_LSTAT
            Impl::StructStat buf1;
            if (p_->stat(buf1) == -1) {
                statOk = false;
            }
            origStMode = buf1.st_mode;
#endif // !EXV_HAVE_LSTAT

            // MSVCRT rename that does not overwrite existing files
#ifdef EXV_UNICODE_PATH
            if (p_->wpMode_ == Impl::wpUnicode) {
                if (fileExists(wpf) && ::_wremove(wpf) != 0) {
                    throw WError(2, wpf, strError().c_str(), "::_wremove");
                }
                if (::_wrename(fileIo->wpath().c_str(), wpf) == -1) {
                    throw WError(17, fileIo->wpath(), wpf, strError().c_str());
                }
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例10: while

    DataBuf PngChunk::readRawProfile(const DataBuf& text)
    {
        DataBuf                 info;
        register long           i;
        register unsigned char *dp;
        const char             *sp;
        unsigned int            nibbles;
        long                    length;
        unsigned char           unhex[103]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
                                            0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
                                            0,0,0,0,0,0,0,0,0,1, 2,3,4,5,6,7,8,9,0,0,
                                            0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
                                            0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,10,11,12,
                                            13,14,15};

        sp = (char*)text.pData_+1;

        // Look for newline

        while (*sp != '\n')
            sp++;

        // Look for length

        while (*sp == '\0' || *sp == ' ' || *sp == '\n')
            sp++;

        length = (long) atol(sp);

        while (*sp != ' ' && *sp != '\n')
            sp++;

        // Allocate space

        if (length == 0)
        {
#ifdef DEBUG
            std::cerr << "Exiv2::PngChunk::readRawProfile: Unable To Copy Raw Profile: invalid profile length\n";
#endif
            return DataBuf();
        }

        info.alloc(length);

        if (info.size_ != length)
        {
#ifdef DEBUG
            std::cerr << "Exiv2::PngChunk::readRawProfile: Unable To Copy Raw Profile: cannot allocate memory\n";
#endif
            return DataBuf();
        }

        // Copy profile, skipping white space and column 1 "=" signs

        dp      = (unsigned char*)info.pData_;
        nibbles = length * 2;

        for (i = 0; i < (long) nibbles; i++)
        {
            while (*sp < '0' || (*sp > '9' && *sp < 'a') || *sp > 'f')
            {
                if (*sp == '\0')
                {
#ifdef DEBUG
                    std::cerr << "Exiv2::PngChunk::readRawProfile: Unable To Copy Raw Profile: ran out of data\n";
#endif
                    return DataBuf();
                }

                sp++;
            }

            if (i%2 == 0)
                *dp = (unsigned char) (16*unhex[(int) *sp++]);
            else
                (*dp++) += unhex[(int) *sp++];
        }

        return info;

    } // PngChunk::readRawProfile
开发者ID:,项目名称:,代码行数:81,代码来源:

示例11:

 DataBuf::DataBuf(DataBuf& rhs)
     : pData_(rhs.pData_), size_(rhs.size_)
 {
     rhs.release();
 }
开发者ID:obklar,项目名称:exiv2,代码行数:5,代码来源:types.cpp

示例12: runFile

	int32 Interp::runFile(char* filename, uint32 linesz, void* context)
	{
		DataBuf dbLine;
		FILE* fin = NULL;

		char* param_string = NULL;
		char* token = NULL;
		char* line = NULL;

		uint32 current_line = 1;
		int32 ret = 0, out = 0, k = 0;

		ret = dbLine.init(linesz);
		if (ret == FAILURE)
			return FAILURE;

		dbLine.set(0);
		dbLine.setCount(0);
		dbLine.setLimit(2 * 1024 * 1024);

		line = dbLine.toString();

		fin = fopen(filename, "r");
		if (!fin)
			return FAILURE;

		while (1) {
			/* get a line */
			out = Utils::getDelim(line, linesz, '\n', fin);
			if (out < 0)
				break;

			/* remove '\n' and blanks */
			while (--out && isspace(toascii(line[out])))
				line[out] = 0;

			/* remove blanks */
			k = (int32) strlen(line);
			while (k && isspace(toascii(*line))) {
				k--; line++;
			}

			/* remove empty lines and comments */
			if (line[0] == '#' || line[0] == '\0') {
				current_line++; continue;
			}

			/* execute instruction */
			param_string = line;
			token = Utils::getToken(&param_string, " \t");
			if (token) {
				ret = run(token, param_string, context);
				switch (ret) {
				case BADCOMMAND:
				case PARAMPARSINGERROR:
				case WRONGPARAMCOUNT:
				case PERMISSIONDENIED:
					sysHandler(token, current_line, ret, context);
					return FAILURE;
				default:
					usrHandler(token, current_line, ret, context);
				}

				current_line++;
			} else {
				current_line++;
				continue;
			}
		}

		fclose(fin);
		return SUCCESS;
	}
开发者ID:BackupTheBerlios,项目名称:digixound-svn,代码行数:73,代码来源:interp.cpp


注:本文中的DataBuf类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。