aboutsummaryrefslogtreecommitdiff
path: root/src/structs/ser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/structs/ser.rs')
-rw-r--r--src/structs/ser.rs67
1 files changed, 35 insertions, 32 deletions
diff --git a/src/structs/ser.rs b/src/structs/ser.rs
index 8aa95a5..6833fb8 100644
--- a/src/structs/ser.rs
+++ b/src/structs/ser.rs
@@ -43,17 +43,17 @@ impl ser::Serializer for &mut ArchiveSerializer {
43 } 43 }
44 44
45 fn serialize_i16(self, v: i16) -> StructResult<()> { 45 fn serialize_i16(self, v: i16) -> StructResult<()> {
46 self.bytes.append(&mut self.settings.byte_order.i16(v)); 46 self.bytes.append(&mut self.settings.byte_order.form_i16(v));
47 Ok(()) 47 Ok(())
48 } 48 }
49 49
50 fn serialize_i32(self, v: i32) -> StructResult<()> { 50 fn serialize_i32(self, v: i32) -> StructResult<()> {
51 self.bytes.append(&mut self.settings.byte_order.i32(v)); 51 self.bytes.append(&mut self.settings.byte_order.form_i32(v));
52 Ok(()) 52 Ok(())
53 } 53 }
54 54
55 fn serialize_i64(self, v: i64) -> StructResult<()> { 55 fn serialize_i64(self, v: i64) -> StructResult<()> {
56 self.bytes.append(&mut self.settings.byte_order.i64(v)); 56 self.bytes.append(&mut self.settings.byte_order.form_i64(v));
57 Ok(()) 57 Ok(())
58 } 58 }
59 59
@@ -63,54 +63,57 @@ impl ser::Serializer for &mut ArchiveSerializer {
63 } 63 }
64 64
65 fn serialize_u16(self, v: u16) -> StructResult<()> { 65 fn serialize_u16(self, v: u16) -> StructResult<()> {
66 self.bytes.append(&mut self.settings.byte_order.u16(v)); 66 self.bytes.append(&mut self.settings.byte_order.form_u16(v));
67 Ok(()) 67 Ok(())
68 } 68 }
69 69
70 fn serialize_u32(self, v: u32) -> StructResult<()> { 70 fn serialize_u32(self, v: u32) -> StructResult<()> {
71 self.bytes.append(&mut self.settings.byte_order.u32(v)); 71 self.bytes.append(&mut self.settings.byte_order.form_u32(v));
72 Ok(()) 72 Ok(())
73 } 73 }
74 74
75 fn serialize_u64(self, v: u64) -> StructResult<()> { 75 fn serialize_u64(self, v: u64) -> StructResult<()> {
76 self.bytes.append(&mut self.settings.byte_order.u64(v)); 76 self.bytes.append(&mut self.settings.byte_order.form_u64(v));
77 Ok(()) 77 Ok(())
78 } 78 }
79 79
80 fn serialize_f32(self, v: f32) -> StructResult<()> { 80 fn serialize_f32(self, v: f32) -> StructResult<()> {
81 self.bytes.append(&mut self.settings.byte_order.f32(v)); 81 self.bytes.append(&mut self.settings.byte_order.form_f32(v));
82 Ok(()) 82 Ok(())
83 } 83 }
84 84
85 fn serialize_f64(self, v: f64) -> StructResult<()> { 85 fn serialize_f64(self, v: f64) -> StructResult<()> {
86 self.bytes.append(&mut self.settings.byte_order.f64(v)); 86 self.bytes.append(&mut self.settings.byte_order.form_f64(v));
87 Ok(()) 87 Ok(())
88 } 88 }
89 89
90 fn serialize_char(self, v: char) -> StructResult<()> { 90 fn serialize_char(self, v: char) -> StructResult<()> {
91 self.bytes.push(v as u8); 91 Err(StructError::SerializationNotSupported { type_name: "char" }.into())
92 Ok(())
93 } 92 }
94 93
95 fn serialize_str(self, v: &str) -> StructResult<()> { 94 fn serialize_str(self, _v: &str) -> StructResult<()> {
96 self.bytes.append(&mut v.as_bytes().to_vec()); 95 Err(StructError::SerializationNotSupported { type_name: "str" }.into())
97 Ok(())
98 } 96 }
99 97
100 fn serialize_bytes(self, v: &[u8]) -> StructResult<()> { 98 fn serialize_bytes(self, _v: &[u8]) -> StructResult<()> {
101 self.bytes.append(&mut v.to_vec()); 99 Err(StructError::SerializationNotSupported { type_name: "bytes" }.into())
102 Ok(())
103 } 100 }
104 101
105 fn serialize_none(self) -> StructResult<()> { 102 fn serialize_none(self) -> StructResult<()> {
106 Ok(()) 103 Err(StructError::SerializationNotSupported {
104 type_name: "optional",
105 }
106 .into())
107 } 107 }
108 108
109 fn serialize_some<T>(self, value: &T) -> StructResult<()> 109 fn serialize_some<T>(self, value: &T) -> StructResult<()>
110 where 110 where
111 T: ?Sized + Serialize, 111 T: ?Sized + Serialize,
112 { 112 {
113 value.serialize(self) 113 Err(StructError::SerializationNotSupported {
114 type_name: "optional",
115 }
116 .into())
114 } 117 }
115 118
116 fn serialize_unit(self) -> StructResult<()> { 119 fn serialize_unit(self) -> StructResult<()> {
@@ -131,7 +134,7 @@ impl ser::Serializer for &mut ArchiveSerializer {
131 &mut self 134 &mut self
132 .settings 135 .settings
133 .variant_index_type 136 .variant_index_type
134 .cast(variant_index, &self.settings.byte_order)?, 137 .cast(variant_index, &self.settings.byte_order),
135 ); 138 );
136 Ok(()) 139 Ok(())
137 } 140 }
@@ -157,13 +160,13 @@ impl ser::Serializer for &mut ArchiveSerializer {
157 &mut self 160 &mut self
158 .settings 161 .settings
159 .variant_index_type 162 .variant_index_type
160 .cast(variant_index, &self.settings.byte_order)?, 163 .cast(variant_index, &self.settings.byte_order),
161 ); 164 );
162 value.serialize(self) 165 value.serialize(self)
163 } 166 }
164 167
165 fn serialize_seq(self, _len: Option<usize>) -> StructResult<Self::SerializeSeq> { 168 fn serialize_seq(self, _len: Option<usize>) -> StructResult<Self::SerializeSeq> {
166 Ok(self) 169 Err(StructError::SerializationNotSupported { type_name: "seq" }.into())
167 } 170 }
168 171
169 fn serialize_tuple(self, _len: usize) -> StructResult<Self::SerializeTuple> { 172 fn serialize_tuple(self, _len: usize) -> StructResult<Self::SerializeTuple> {
@@ -189,13 +192,13 @@ impl ser::Serializer for &mut ArchiveSerializer {
189 &mut self 192 &mut self
190 .settings 193 .settings
191 .variant_index_type 194 .variant_index_type
192 .cast(variant_index, &self.settings.byte_order)?, 195 .cast(variant_index, &self.settings.byte_order),
193 ); 196 );
194 Ok(self) 197 Ok(self)
195 } 198 }
196 199
197 fn serialize_map(self, _len: Option<usize>) -> StructResult<Self::SerializeMap> { 200 fn serialize_map(self, _len: Option<usize>) -> StructResult<Self::SerializeMap> {
198 Ok(self) 201 Err(StructError::SerializationNotSupported { type_name: "map" }.into())
199 } 202 }
200 203
201 fn serialize_struct( 204 fn serialize_struct(
@@ -217,7 +220,7 @@ impl ser::Serializer for &mut ArchiveSerializer {
217 &mut self 220 &mut self
218 .settings 221 .settings
219 .variant_index_type 222 .variant_index_type
220 .cast(variant_index, &self.settings.byte_order)?, 223 .cast(variant_index, &self.settings.byte_order),
221 ); 224 );
222 Ok(self) 225 Ok(self)
223 } 226 }
@@ -227,15 +230,15 @@ impl ser::SerializeSeq for &mut ArchiveSerializer {
227 type Ok = (); 230 type Ok = ();
228 type Error = ArchiveError<StructError>; 231 type Error = ArchiveError<StructError>;
229 232
230 fn serialize_element<T>(&mut self, value: &T) -> StructResult<()> 233 fn serialize_element<T>(&mut self, _value: &T) -> StructResult<()>
231 where 234 where
232 T: ?Sized + Serialize, 235 T: ?Sized + Serialize,
233 { 236 {
234 value.serialize(&mut **self) 237 Err(StructError::SerializationNotSupported { type_name: "seq" }.into())
235 } 238 }
236 239
237 fn end(self) -> StructResult<()> { 240 fn end(self) -> StructResult<()> {
238 Ok(()) 241 Err(StructError::SerializationNotSupported { type_name: "seq" }.into())
239 } 242 }
240} 243}
241 244
@@ -291,22 +294,22 @@ impl ser::SerializeMap for &mut ArchiveSerializer {
291 type Ok = (); 294 type Ok = ();
292 type Error = ArchiveError<StructError>; 295 type Error = ArchiveError<StructError>;
293 296
294 fn serialize_key<T>(&mut self, key: &T) -> StructResult<()> 297 fn serialize_key<T>(&mut self, _key: &T) -> StructResult<()>
295 where 298 where
296 T: ?Sized + Serialize, 299 T: ?Sized + Serialize,
297 { 300 {
298 key.serialize(&mut **self) 301 Err(StructError::SerializationNotSupported { type_name: "map" }.into())
299 } 302 }
300 303
301 fn serialize_value<T>(&mut self, value: &T) -> StructResult<()> 304 fn serialize_value<T>(&mut self, _value: &T) -> StructResult<()>
302 where 305 where
303 T: ?Sized + Serialize, 306 T: ?Sized + Serialize,
304 { 307 {
305 value.serialize(&mut **self) 308 Err(StructError::SerializationNotSupported { type_name: "map" }.into())
306 } 309 }
307 310
308 fn end(self) -> StructResult<()> { 311 fn end(self) -> StructResult<()> {
309 Ok(()) 312 Err(StructError::SerializationNotSupported { type_name: "map" }.into())
310 } 313 }
311} 314}
312 315