TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / common / binary_writer.h
1 /*
2  * Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com>
3  *                    Simon Fels <morphis@gravedo.de>
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 3, as published
7  * by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranties of
11  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12  * PURPOSE.  See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18
19 #ifndef ANBOX_COMMON_BINARY_WRITER_H_
20 #define ANBOX_COMMON_BINARY_WRITER_H_
21
22 #include <cstdint>
23 #include <vector>
24 #include <string>
25
26 namespace anbox {
27 namespace common {
28 class BinaryWriter {
29  public:
30   enum class Order {
31     Big,
32     Little,
33   };
34
35   explicit BinaryWriter(std::vector<std::uint8_t>::iterator begin_,
36                         std::vector<std::uint8_t>::iterator end_);
37
38   void set_byte_order(Order order);
39
40   void write_uint16(std::uint16_t value);
41   void write_uint32(std::uint32_t value);
42   void write_string(const char *s, std::size_t size);
43   void write_string_with_size(const std::string &str);
44   void write_string_with_size(const char *s, std::size_t size);
45
46   std::size_t bytes_written() const;
47
48  private:
49   std::vector<std::uint8_t>::iterator begin_;
50   std::vector<std::uint8_t>::iterator current_;
51   std::vector<std::uint8_t>::iterator end_;
52   Order byte_order_;
53 };
54 } // namespace common
55 } // namespace anbox
56
57 #endif