예제 #1
0
    inline void media_attributes::attribute_set<>(const std::string& attribute_name, const std::string& value)
    {
        auto buffer = attribute_blob_get(attribute_name);

        if (buffer)
        {
            if (buffer.length_get() == value.size() &&
                !memcmp(buffer.data(), static_cast<void*>(const_cast<char*>(value.c_str())), value.size()))
            {
                return;
            }
        }

        if (!buffer || buffer.length_get() != value.size())
        {
            buffer = io::memory_buffer(value.size());
        }

        memcpy(buffer.data(), value.c_str(), value.size());

        attribute_blob_set(attribute_name, buffer);
    }
예제 #2
0
        void attribute_set(const std::string& attribute_name, const T& value)
        {
            auto buffer = attribute_blob_get(attribute_name);

            if (buffer)
            {
                if (buffer.length_get() == sizeof(T) &&
                    !memcmp(buffer.data(), static_cast<void*>(const_cast<T*>(std::addressof(value))), sizeof(T)))
                {
                    return;
                }
            }

            if (!buffer || buffer.length_get() != sizeof(T))
            {
                buffer = io::memory_buffer(sizeof(T));
            }

            memcpy(buffer.data(), std::addressof(value), sizeof(T));

            attribute_blob_set(attribute_name, buffer);
        }
예제 #3
0
        void write(uint8_t* source, size_t position, size_t size)
        {
            if (size > length_get() + position)
            {
                throw std::runtime_error("destination buffer size larger than buffer length");
            }

            if (source == nullptr)
            {
                throw std::runtime_error("invalid source pointer");
            }

            memcpy(_buffer.data() + position, source, size);
        }
예제 #4
0
        void read(uint8_t* destination, size_t position, size_t size)
        {
            if (size > length_get() + position)
            {
                throw std::runtime_error("destination buffer size larger than buffer length");
            }

            if (destination == nullptr)
            {
                throw std::runtime_error("invalid destination pointer");
            }

            memcpy(destination, _buffer.data() + position, size);
        }