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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use ;
use ;
/// Decodes JSON data into a Rust struct.
///
/// Deserializes a byte slice into the specified type using Serde and `serde_json`.
/// Supports Juno's extended JSON conventions for IC types such as `Principal`, `u64` (bigint),
/// and `Vec<u8>` (Uint8Array), which are encoded using `@dfinity/utils` compatible markers.
///
/// # Parameters
/// - `data`: A byte slice (`&[u8]`) containing the JSON-encoded data.
///
/// # Returns
/// - `Ok(T)`: Successfully deserialized data of type `T`.
/// - `Err(String)`: An error string if deserialization fails.
///
/// # Example
///
/// ```rust
/// #[derive(Deserialize)]
/// struct MyData {
/// name: String,
/// }
///
/// let data: MyData = decode_json_data(bytes)?;
/// ```
/// Encodes a Rust struct into JSON bytes.
///
/// Serializes the provided data into a byte vector using Serde and `serde_json`.
/// Supports Juno's extended JSON conventions for IC types such as `Principal`, `u64` (bigint),
/// and `Vec<u8>` (Uint8Array), which are encoded using `@dfinity/utils` compatible markers.
///
/// # Parameters
/// - `data`: A reference to the Rust data structure to be serialized.
///
/// # Returns
/// - `Ok(Vec<u8>)`: A byte vector containing the JSON-encoded data.
/// - `Err(String)`: An error string if serialization fails.
///
/// # Example
///
/// ```rust
/// #[derive(Serialize)]
/// struct MyData {
/// name: String,
/// }
///
/// let bytes = encode_json_data(&my_data)?;
/// ```
/// Encodes a Rust struct into a JSON string.
///
/// Serializes the provided data into a `String` using Serde and `serde_json`.
/// Supports Juno's extended JSON conventions for IC types such as `Principal`, `u64` (bigint),
/// and `Vec<u8>` (Uint8Array), which are encoded using `@dfinity/utils` compatible markers.
///
/// # Parameters
/// - `data`: A reference to the Rust data structure to be serialized.
///
/// # Returns
/// - `Ok(String)`: A JSON string containing the serialized data.
/// - `Err(String)`: An error string if serialization fails.
///
/// # Example
///
/// ```rust
/// #[derive(Serialize)]
/// struct MyData {
/// name: String,
/// }
///
/// let json = encode_json_data_to_string(&my_data)?;
/// ```