! @brief reads a UBJSON string This function is either called after reading the 'S' byte explicitly indicating a string, or in case of an object key where the 'S' byte can be left out. @param[out] result created string @param[in] get_char whether a new character should be retrieved from the input (true, default) or whether the last read
| 10215 | @return whether string creation completed |
| 10216 | */ |
| 10217 | bool get_ubjson_string(string_t& result, const bool get_char = true) |
| 10218 | { |
| 10219 | if (get_char) |
| 10220 | { |
| 10221 | get(); // TODO(niels): may we ignore N here? |
| 10222 | } |
| 10223 | |
| 10224 | if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "value"))) |
| 10225 | { |
| 10226 | return false; |
| 10227 | } |
| 10228 | |
| 10229 | switch (current) |
| 10230 | { |
| 10231 | case 'U': |
| 10232 | { |
| 10233 | std::uint8_t len{}; |
| 10234 | return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result); |
| 10235 | } |
| 10236 | |
| 10237 | case 'i': |
| 10238 | { |
| 10239 | std::int8_t len{}; |
| 10240 | return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result); |
| 10241 | } |
| 10242 | |
| 10243 | case 'I': |
| 10244 | { |
| 10245 | std::int16_t len{}; |
| 10246 | return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result); |
| 10247 | } |
| 10248 | |
| 10249 | case 'l': |
| 10250 | { |
| 10251 | std::int32_t len{}; |
| 10252 | return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result); |
| 10253 | } |
| 10254 | |
| 10255 | case 'L': |
| 10256 | { |
| 10257 | std::int64_t len{}; |
| 10258 | return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result); |
| 10259 | } |
| 10260 | |
| 10261 | default: |
| 10262 | auto last_token = get_token_string(); |
| 10263 | return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token, "string"), BasicJsonType())); |
| 10264 | } |
| 10265 | } |
| 10266 | |
| 10267 | /*! |
| 10268 | @param[out] result determined size |
nothing calls this directly
no test coverage detected