File: RawBufferWriter.hpp

package info (click to toggle)
r-bioc-alabaster.base 1.6.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,652 kB
  • sloc: cpp: 11,377; sh: 29; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 977 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef BYTEME_RAW_BUFFER_WRITER_HPP
#define BYTEME_RAW_BUFFER_WRITER_HPP

#include "Writer.hpp"
#include <vector>

/**
 * @file RawBufferWriter.hpp
 *
 * @brief Write bytes to a raw buffer without any extra transformations.
 */

namespace byteme {

/**
 * @brief Write bytes to a raw buffer.
 *
 * This class will append bytes to an internal instance of a `std::vector` without any further transformations.
 * Not much else to say here.
 */
class RawBufferWriter : public Writer {
public:
    /**
     * @param n Initial size of the output buffer to reserve.
     */
    RawBufferWriter(size_t n = 0) {
        output.reserve(n);
    }

    using Writer::write;

    void write(const unsigned char* buffer, size_t n) {
        output.insert(output.end(), buffer, buffer + n);
    }

    void finish() {}

    /**
     * Contents of the output buffer.
     * This should only be accessed after `finish()` is called.
     */
    std::vector<unsigned char> output;
};

}

#endif