| 140 | } |
| 141 | |
| 142 | std::shared_ptr<Map> json::from_binary(const ubyte* src, size_t size) { |
| 143 | if (size < 2) { |
| 144 | throw std::runtime_error("bytes length is less than 2"); |
| 145 | } |
| 146 | if (src[0] == gzip::MAGIC[0] && src[1] == gzip::MAGIC[1]) { |
| 147 | // reading compressed document |
| 148 | auto data = gzip::decompress(src, size); |
| 149 | return from_binary(data.data(), data.size()); |
| 150 | } else { |
| 151 | ByteReader reader(src, size); |
| 152 | Value value = value_from_binary(reader); |
| 153 | |
| 154 | if (auto map = std::get_if<Map_sptr>(&value)) { |
| 155 | return *map; |
| 156 | } else { |
| 157 | throw std::runtime_error("root value is not an object"); |
| 158 | } |
| 159 | } |
| 160 | } |
nothing calls this directly
no test coverage detected