Tileson  1.3.0
A helpful json parser for Tiled maps
Tools.hpp
Go to the documentation of this file.
1 //
2 // Created by robin on 31.07.2020.
3 //
4 
5 #ifndef TILESON_TOOLS_HPP
6 #define TILESON_TOOLS_HPP
7 
8 #include <cstdint>
9 #include <vector>
10 #include <string_view>
11 namespace tson
12 {
13  class Tools
14  {
15 
16  public:
17  Tools() = delete;
18  ~Tools() = delete;
19  inline static std::vector<uint8_t> Base64DecodedStringToBytes(std::string_view str);
20  inline static std::vector<uint32_t> BytesToUnsignedInts(const std::vector<uint8_t> &bytes);
21  //inline static std::vector<int> BytesToInts(const std::vector<uint8_t> &bytes);
22  };
23 
29  std::vector<uint8_t> Tools::Base64DecodedStringToBytes(std::string_view str)
30  {
31  std::vector<uint8_t> bytes;
32  for(size_t i = 0; i < str.size(); ++i)
33  {
34  uint8_t u8 = static_cast<uint8_t>(str[i]);
35  bytes.push_back(u8);
36  }
37  return bytes;
38  }
39 
45  std::vector<uint32_t> Tools::BytesToUnsignedInts(const std::vector<uint8_t> &bytes)
46  {
47  std::vector<uint32_t> uints;
48  std::vector<uint8_t> toConvert;
49  //uint32_t size8 = (compressed[55] << 24) | (compressed[56] << 16) | (compressed[57] << 8) | compressed[58]; //Should be 66000
50 
51  for(size_t i = 0; i < bytes.size(); ++i)
52  {
53  toConvert.push_back(bytes[i]);
54  if(toConvert.size() == 4)
55  {
56  uint32_t u32 = (toConvert[3] << 24) | (toConvert[2] << 16) | (toConvert[1] << 8) | toConvert[0];
57  uints.push_back(u32);
58  toConvert.clear();
59  }
60  }
61 
62  return uints;
63  }
64 
78  /*std::vector<int> Tools::BytesToInts(const std::vector<uint8_t> &bytes)
79  {
80  std::vector<int> ints;
81  std::vector<uint8_t> toConvert;
82  //uint32_t size8 = (compressed[55] << 24) | (compressed[56] << 16) | (compressed[57] << 8) | compressed[58]; //Should be 66000
83 
84  for(size_t i = 0; i < bytes.size(); ++i)
85  {
86  toConvert.push_back(bytes[i]);
87  if(toConvert.size() == 4)
88  {
89  uint32_t u32 = (toConvert[3] << 24) | (toConvert[2] << 16) | (toConvert[1] << 8) | toConvert[0];
90  ints.push_back(u32);
91  toConvert.clear();
92  }
93  }
94 
95  return ints;
96  }*/
97 }
98 
99 #endif //TILESON_TOOLS_HPP
Definition: Tools.hpp:14
Tools()=delete
static std::vector< uint8_t > Base64DecodedStringToBytes(std::string_view str)
Definition: Tools.hpp:29
static std::vector< uint32_t > BytesToUnsignedInts(const std::vector< uint8_t > &bytes)
Definition: Tools.hpp:45
~Tools()=delete
Definition: Base64.hpp:12