Пример #1
0
    ///////////////////////////////////////////////////////////////////////////////
    /// Reads the copy operation state from a buffer
    ///
    /// \param [in] const BYTEVECTOR& lambdaBuffer - the buffer to read from
    /// \param [in,out] PULONG pLambdaBufPos - the position in the buffer to read from
    /// \return std::unique_ptr<CCopyOperation> - the deserialised copy operation,
    ///			or nullptr if lambdaBuffer did not contain a CCopyOperation at
    ///			position *pLambdaBufPos
    ///////////////////////////////////////////////////////////////////////////////
    std::unique_ptr<CCopyOperation> CCopyOperation::TryDeserialise(const CDataBuffer& copyFromBuffer, IDataReader& lambdaReader)
    {
        // check the type of the operation
        if (lambdaReader.PeekByte() != COPY_OPERATION_TYPE)
        {
            // not a copy op
            return nullptr;
        }
        lambdaReader.ReadByte();
        
        // get length
        ULONG nNumBytesToCopy = lambdaReader.ReadULONG();

        // get dictionary buffer offset to copy from
        ULONG nOffset = lambdaReader.ReadULONG();

        std::unique_ptr<CCopyOperation> pCopyOp(
            new CCopyOperation(
                copyFromBuffer,
                CDataBuffer(copyFromBuffer.Buffer() + nOffset, nNumBytesToCopy)
            )
        );
        
#ifdef DEBUG_OUTPUT
        std::cout << "<CopyOp><Offset>" << nOffset << "</Offset><Length>" << nNumBytesToCopy << "</Length></CopyOp>" << std::endl;
#endif
        return pCopyOp;
    }