cyfs_core/codec/
format.rs1use crate::im::{AddFriendDescContent, FriendOption, FriendOptionDescContent, FriendProperty, FriendPropertyDescContent, MsgDescContent, RemoveFriendDescContent};
2use crate::*;
3use cyfs_base::{ObjectFormat, ObjectFormatAutoWithSerde, FORMAT_FACTORY, format_json};
4use serde_json::Value;
5
6impl ObjectFormatAutoWithSerde for TextDescContent {}
7impl ObjectFormatAutoWithSerde for TextContent {}
8
9impl ObjectFormatAutoWithSerde for AppListDescContent {}
10impl ObjectFormat for AppListContent {
11 fn format_json(&self) -> Value {
12 let mut map = serde_json::Map::new();
13 for (id, status) in &self.source {
14 map.insert(id.object_id().to_string(), status.format_json());
15 }
16 map.into()
17 }
18}
19
20impl ObjectFormatAutoWithSerde for AppLocalListDesc {}
21impl ObjectFormatAutoWithSerde for AppLocalListBody {}
22
23impl ObjectFormatAutoWithSerde for AppLocalStatusDesc {}
24impl ObjectFormatAutoWithSerde for AppLocalStatusBody {}
25
26impl ObjectFormatAutoWithSerde for AppSettingDesc {}
27impl ObjectFormatAutoWithSerde for AppSettingBody {}
28
29impl ObjectFormatAutoWithSerde for AppManagerActionDesc {}
30impl ObjectFormatAutoWithSerde for AppManagerActionBody {}
31
32impl ObjectFormatAutoWithSerde for AppStatusDescContent {}
33impl ObjectFormatAutoWithSerde for AppStatusContent {}
34
35impl ObjectFormatAutoWithSerde for AppCmdDesc {}
36impl ObjectFormatAutoWithSerde for AppCmdBody {}
37
38impl ObjectFormatAutoWithSerde for AppCmdListBody {}
39
40impl ObjectFormatAutoWithSerde for DecAppDescContent {}
41impl ObjectFormatAutoWithSerde for DecAppContent {}
42
43impl ObjectFormatAutoWithSerde for DefaultAppListDescContent {}
44impl ObjectFormatAutoWithSerde for DefaultAppListContent {}
45
46impl ObjectFormatAutoWithSerde for AddFriendDescContent {}
47
48impl ObjectFormatAutoWithSerde for FriendOptionDescContent {}
49impl ObjectFormatAutoWithSerde for FriendPropertyDescContent {}
50
51impl ObjectFormatAutoWithSerde for MsgDescContent {}
52
53impl ObjectFormatAutoWithSerde for RemoveFriendDescContent {}
54
55impl ObjectFormat for NFTListDescContent {
56 fn format_json(&self) -> Value {
57 let mut array = vec![];
58 for nft in &self.nft_list {
59 array.push(nft.format_json())
60 }
61 array.into()
62 }
63}
64
65impl ObjectFormatAutoWithSerde for StorageDescContent {}
66impl ObjectFormat for StorageBodyContent {
67 fn format_json(&self) -> Value {
68 hex::encode(&self.value).into()
69 }
70}
71
72impl ObjectFormatAutoWithSerde for TransContextDescContent {}
73impl ObjectFormatAutoWithSerde for TransContextBodyContent {}
74
75impl ObjectFormatAutoWithSerde for ZoneDescContent {}
76impl ObjectFormatAutoWithSerde for ZoneBodyContent {}
77
78
79pub fn register_core_objects_format() {
80 FORMAT_FACTORY.register(CoreObjectType::Zone, format_json::<Zone>);
81 FORMAT_FACTORY.register(CoreObjectType::Storage, format_json::<Storage>);
82 FORMAT_FACTORY.register(CoreObjectType::Text, format_json::<Text>);
83
84 FORMAT_FACTORY.register(CoreObjectType::FriendProperty, format_json::<FriendProperty>);
85 FORMAT_FACTORY.register(CoreObjectType::FriendOption, format_json::<FriendOption>);
86
87 FORMAT_FACTORY.register(CoreObjectType::TransContext, format_json::<TransContext>);
88 FORMAT_FACTORY.register(CoreObjectType::DecApp, format_json::<DecApp>);
89 FORMAT_FACTORY.register(CoreObjectType::AppStatus, format_json::<AppStatus>);
90 FORMAT_FACTORY.register(CoreObjectType::AppList, format_json::<AppList>);
91 FORMAT_FACTORY.register(CoreObjectType::DefaultAppList, format_json::<DefaultAppList>);
95
96 FORMAT_FACTORY.register(CoreObjectType::AppCmd, format_json::<AppCmd>);
97 FORMAT_FACTORY.register(CoreObjectType::AppLocalStatus, format_json::<AppLocalStatus>);
98 FORMAT_FACTORY.register(CoreObjectType::AppCmdList, format_json::<AppCmdList>);
99 FORMAT_FACTORY.register(CoreObjectType::AppSetting, format_json::<AppSetting>);
100 FORMAT_FACTORY.register(CoreObjectType::AppManagerAction, format_json::<AppManagerAction>);
101 FORMAT_FACTORY.register(CoreObjectType::AppLocalList, format_json::<AppLocalList>);
102
103 FORMAT_FACTORY.register(CoreObjectType::NFTList, format_json::<NFTList>);
104}