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
//! Serialization and deserialization utilities for Neo N3 smart contracts.
//!
//! This module provides binary serialization using bincode, which is efficient
//! for storage and cross-contract communication.
use ;
use DeserializeOwned;
use Serialize;
/// Serializes a value to bytes using bincode.
///
/// # Type Parameters
/// * `T` - The type to serialize, must implement `Serialize`
///
/// # Arguments
/// * `value` - A reference to the value to serialize
///
/// # Returns
/// * `Ok(Vec<u8>)` - The serialized bytes on success
/// * `Err(NeoError)` - If serialization fails
///
/// # Examples
///
/// ```
/// use neo_devpack::codec::serialize;
///
/// let value = 42i32;
/// let bytes = serialize(&value).unwrap();
/// ```
/// Deserializes bytes to a value using bincode.
///
/// # Type Parameters
/// * `T` - The type to deserialize, must implement `DeserializeOwned`
///
/// # Arguments
/// * `bytes` - The bytes to deserialize from
///
/// # Returns
/// * `Ok(T)` - The deserialized value on success
/// * `Err(NeoError)` - If deserialization fails (e.g., invalid format)
///
/// # Examples
///
/// ```
/// use neo_devpack::codec::{serialize, deserialize};
///
/// let value = 42i32;
/// let bytes = serialize(&value).unwrap();
/// let restored: i32 = deserialize(&bytes).unwrap();
/// assert_eq!(value, restored);
/// ```