File: byte_string_chars_format.md

package info (click to toggle)
jsoncons 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,584 kB
  • sloc: cpp: 136,382; sh: 33; makefile: 5
file content (55 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download
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
48
49
50
51
52
53
54
55
### jsoncons::byte_string_chars_format

```cpp
#include <jsoncons/json_options.hpp>

enum class byte_string_chars_format : uint8_t {base16, base64, base64url};
```

Specifies byte string formatting. 

### Examples

#### Byte string formatting

```cpp
#include <jsoncons/json.hpp>

using namespace jsoncons;

int main()
{
    std::vector<uint8_t> bytes = {'H','e','l','l','o'};

    json j(byte_string(bytes.data(),bytes.size()));

    // default
    std::cout << "(1) "<< j << "\n\n";

    // base16
    auto options2 = json_options{}
        .byte_string_format(byte_string_chars_format::base16);
    std::cout << "(2) "<< print(j, options2) << "\n\n";

    // base64
    auto options3 = json_options{}
        .byte_string_format(byte_string_chars_format::base64);
    std::cout << "(3) "<< print(j, options3) << "\n\n";

    // base64url
    auto options4 = json_options{}
        .byte_string_format(byte_string_chars_format::base64url);
    std::cout << "(4) "<< print(j, options4) << "\n\n";
}
```
Output:
```
(1) "SGVsbG8"

(2) "48656C6C6F"

(3) "SGVsbG8="

(4) "SGVsbG8"
```