cat-dev 0.0.13

A library for interacting with the CAT-DEV hardware units distributed by Nintendo (i.e. a type of Wii-U DevKits).
Documentation
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
//! Protocols for the SATA 'PCFS' Protocol.
//!
//! This top level function is just all of the things that are common across
//! the entire protocol, each packet serializer/deserializer/handler is kept
//! in it's own sub-file.

mod change_mode;
mod change_owner;
mod close_file;
mod close_folder;
mod create_folder;
mod get_info_by_query;
mod open_file;
mod open_folder;
mod ping;
mod read_file;
mod read_folder;
mod remove;
mod rename;
mod rewind_folder;
mod set_file_position;
mod stat_file;
mod write_file;

use crate::{
	errors::{CatBridgeError, FSError, NetworkError, NetworkParseError},
	fsemul::{
		HostFilesystem,
		pcfs::errors::{PcfsApiError, SataProtocolError},
	},
	net::models::{IntoResponse, Response},
};
use bytes::{BufMut, Bytes, BytesMut};
use std::{
	fmt::{Debug, Display, Formatter, Result as FmtResult},
	time::{Duration, SystemTime, UNIX_EPOCH},
};
use valuable::{Fields, NamedField, NamedValues, StructDef, Structable, Valuable, Value, Visit};

pub use crate::fsemul::pcfs::sata::proto::{
	change_mode::*, change_owner::*, close_file::*, close_folder::*, create_folder::*,
	get_info_by_query::*, open_file::*, open_folder::*, ping::*, read_file::*, read_folder::*,
	remove::*, rename::*, rewind_folder::*, set_file_position::*, stat_file::*, write_file::*,
};

/// The Default PCFS Version we claim to be.
pub const DEFAULT_PCFS_VERSION: u32 = 0x0200_0600;

/// The header for all of our SATA PCFS packets.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SataPacketHeader {
	/// The length of the packet after the header.
	packet_data_len: u32,
	/// An "ID" for packets, THIS IS NOT THE PACKET TYPE.
	///
	/// This seemingly more used to correlate requests/responses on the client
	/// side incase it sends multiple packets at once.
	packet_id: u32,
	/// A bitfield of various flags in the header.
	///
	/// These flags depend on the request command.
	flags: u32,
	/// The version of the PCFS protocol to use.
	///
	/// *note: this will be 0 at start, and then be filled in by the first
	/// server response.*
	version: u32,
	/// The timestamp of the host. Yes, they are not ready for the 32 bit
	/// overflow.
	///
	/// For us we actually end up *wrapping* around on our timestamp.
	timestamp_on_host: u32,
	/// The pid opf the running host process.
	pid_on_host: u32,
	// There are techincally 8 bytes of 0x0 that are used for 'padding'
}

impl SataPacketHeader {
	/// Create a new packet header.
	///
	/// Most of the fields here will be set to `0`, or default values. As the
	/// fields are usually not filled out by the client or changable.
	#[must_use]
	pub const fn new(packet_id: u32) -> Self {
		Self {
			packet_data_len: 0,
			packet_id,
			flags: 0,
			version: DEFAULT_PCFS_VERSION,
			timestamp_on_host: 0,
			pid_on_host: 0,
		}
	}

	#[must_use]
	pub const fn data_len(&self) -> u32 {
		self.packet_data_len
	}

	pub const fn set_data_len(&mut self, len: u32) {
		self.packet_data_len = len;
	}

	#[must_use]
	pub const fn id(&self) -> u32 {
		self.packet_id
	}

	pub const fn set_id(&mut self, new_id: u32) {
		self.packet_id = new_id;
	}

	#[must_use]
	pub const fn flags(&self) -> u32 {
		self.flags
	}

	pub const fn set_flags(&mut self, new_flags: u32) {
		self.flags = new_flags;
	}

	#[must_use]
	pub const fn version(&self) -> u32 {
		self.version
	}

	#[must_use]
	pub const fn raw_timestamp_on_host(&self) -> u32 {
		self.timestamp_on_host
	}

	/// A "timestamp on the host".
	///
	/// Because this timestamp is *NOT* 32 bit epoch safe. These timestamps
	/// may be *VERY WRONG* on purpose if it's past the year 2038. Don't come
	/// blame me. Blame nintendo.
	#[must_use]
	pub fn host_timestamp(&self) -> SystemTime {
		UNIX_EPOCH
			.checked_add(Duration::from_secs(u64::from(self.timestamp_on_host)))
			.unwrap_or_else(SystemTime::now)
	}

	#[must_use]
	pub const fn host_pid(&self) -> u32 {
		self.pid_on_host
	}

	/// Non-host packets should have empty fields for timestamp on host, and
	/// pid.
	///
	/// ## Errors
	///
	/// If the non host side of a connection error'd.
	pub fn ensure_not_from_host(&self) -> Result<(), SataProtocolError> {
		if self.pid_on_host != 0 || self.timestamp_on_host != 0 {
			return Err(SataProtocolError::NonHostSetHostOnlyHeaderFields(
				self.timestamp_on_host,
				self.pid_on_host,
			));
		}

		Ok(())
	}
}

impl From<&SataPacketHeader> for Bytes {
	fn from(value: &SataPacketHeader) -> Self {
		let mut buff = BytesMut::with_capacity(0x20);

		buff.put_u32(value.packet_data_len);
		buff.put_u32(value.packet_id);
		buff.put_u32(value.flags);
		buff.put_u32(value.version);
		buff.put_u32(value.timestamp_on_host);
		buff.put_u32(value.pid_on_host);
		buff.extend([0; 8]);

		buff.freeze()
	}
}

impl From<SataPacketHeader> for Bytes {
	fn from(value: SataPacketHeader) -> Self {
		Self::from(&value)
	}
}

impl TryFrom<Bytes> for SataPacketHeader {
	type Error = NetworkParseError;

	fn try_from(value: Bytes) -> Result<Self, Self::Error> {
		if value.len() < 0x20 {
			return Err(NetworkParseError::FieldNotLongEnough(
				"SataPacket",
				"Header",
				0x20,
				value.len(),
				value,
			));
		}
		if value.len() > 0x20 {
			return Err(NetworkParseError::UnexpectedTrailer(
				"SataPacketHeader",
				value.slice(0x20..),
			));
		}

		let packet_data_len = u32::from_be_bytes([value[0], value[1], value[2], value[3]]);
		let packet_id = u32::from_be_bytes([value[4], value[5], value[6], value[7]]);
		let flags = u32::from_be_bytes([value[8], value[9], value[10], value[11]]);
		let version = u32::from_be_bytes([value[12], value[13], value[14], value[15]]);
		let timestamp_on_host = u32::from_be_bytes([value[16], value[17], value[18], value[19]]);
		let pid_on_host = u32::from_be_bytes([value[20], value[21], value[22], value[23]]);

		let should_be_padding = [
			value[24], value[25], value[26], value[27], value[28], value[29], value[30], value[31],
		];
		if should_be_padding != [0x0; 8] {
			return Err(SataProtocolError::HeaderBadPadding(should_be_padding).into());
		}

		Ok(Self {
			packet_data_len,
			packet_id,
			flags,
			version,
			timestamp_on_host,
			pid_on_host,
		})
	}
}

const SATA_PACKET_HEADER_FIELDS: &[NamedField<'static>] = &[
	NamedField::new("data_len"),
	NamedField::new("id"),
	NamedField::new("flags"),
	NamedField::new("version"),
	NamedField::new("host_timestamp"),
	NamedField::new("host_pid"),
];

impl Structable for SataPacketHeader {
	fn definition(&self) -> StructDef<'_> {
		StructDef::new_static("SataPacketHeader", Fields::Named(SATA_PACKET_HEADER_FIELDS))
	}
}

impl Valuable for SataPacketHeader {
	fn as_value(&self) -> Value<'_> {
		Value::Structable(self)
	}

	fn visit(&self, visitor: &mut dyn Visit) {
		visitor.visit_named_fields(&NamedValues::new(
			SATA_PACKET_HEADER_FIELDS,
			&[
				Valuable::as_value(&self.packet_data_len),
				Valuable::as_value(&self.packet_id),
				Valuable::as_value(&self.flags),
				Valuable::as_value(&self.version),
				Valuable::as_value(&self.timestamp_on_host),
				Valuable::as_value(&self.pid_on_host),
			],
		));
	}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SataCommandInfo {
	/// Logged as "user:" in various log messages.
	user: (u32, u32),
	/// Logged as "cap:" in various log messages.
	capabilities: (u32, u32),
	/// The 'command' to run, aka packet id.
	command: u32,
}

impl SataCommandInfo {
	/// Create a new set of command info.
	#[must_use]
	pub const fn new(user: (u32, u32), capabilities: (u32, u32), command: u32) -> Self {
		Self {
			user,
			capabilities,
			command,
		}
	}

	/// Get the user bytes for this command.
	#[must_use]
	pub const fn user(&self) -> (u32, u32) {
		self.user
	}

	/// Set the new user bytes for this command.
	pub const fn set_user(&mut self, new: (u32, u32)) {
		self.user = new;
	}

	/// Get the capabilities for this command.
	///
	/// In log messages the first byte covers capabilities:
	/// 1,2,4,5. While the second byte contains "capability 3" which seems to be
	/// forcing disabling of FFIO/CSR.
	#[must_use]
	pub const fn capabilities(&self) -> (u32, u32) {
		self.capabilities
	}

	/// Set the capability bytes for this command.
	pub const fn set_capabilities(&mut self, new: (u32, u32)) {
		self.capabilities = new;
	}

	/// Get the actual 'packet id', or command.
	#[must_use]
	pub const fn command(&self) -> u32 {
		self.command
	}

	/// Set the command id for this packet.
	pub const fn set_command(&mut self, new: u32) {
		self.command = new;
	}
}

impl From<&SataCommandInfo> for Bytes {
	fn from(value: &SataCommandInfo) -> Self {
		let mut buff = BytesMut::with_capacity(0x14);
		buff.put_u32(value.user.0);
		buff.put_u32(value.user.1);
		buff.put_u32(value.capabilities.0);
		buff.put_u32(value.capabilities.1);
		buff.put_u32(value.command);
		buff.freeze()
	}
}

impl From<SataCommandInfo> for Bytes {
	fn from(value: SataCommandInfo) -> Self {
		Self::from(&value)
	}
}

impl TryFrom<Bytes> for SataCommandInfo {
	type Error = NetworkParseError;

	fn try_from(value: Bytes) -> Result<Self, Self::Error> {
		if value.len() < 0x14 {
			return Err(NetworkParseError::FieldNotLongEnough(
				"SataPacket",
				"CommandInfo",
				0x14,
				value.len(),
				value,
			));
		}
		if value.len() > 0x14 {
			return Err(NetworkParseError::UnexpectedTrailer(
				"SataPacketCommandInfo",
				value.slice(0x14..),
			));
		}

		let user0 = u32::from_be_bytes([value[0], value[1], value[2], value[3]]);
		let user1 = u32::from_be_bytes([value[4], value[5], value[6], value[7]]);
		let cap0 = u32::from_le_bytes([value[8], value[9], value[10], value[11]]);
		let cap1 = u32::from_le_bytes([value[12], value[13], value[14], value[15]]);
		let cmd = u32::from_be_bytes([value[16], value[17], value[18], value[19]]);

		Ok(Self {
			user: (user0, user1),
			capabilities: (cap0, cap1),
			command: cmd,
		})
	}
}

const SATA_COMMAND_INFO_FIELDS: &[NamedField<'static>] = &[
	NamedField::new("user.0"),
	NamedField::new("user.1"),
	NamedField::new("cap.0"),
	NamedField::new("cap.1"),
	NamedField::new("cap.2"),
	NamedField::new("cap.3"),
	NamedField::new("cap.4"),
	NamedField::new("command"),
];

impl Structable for SataCommandInfo {
	fn definition(&self) -> StructDef<'_> {
		StructDef::new_static("SataCommandInfo", Fields::Named(SATA_COMMAND_INFO_FIELDS))
	}
}

impl Valuable for SataCommandInfo {
	fn as_value(&self) -> Value<'_> {
		Value::Structable(self)
	}

	fn visit(&self, visitor: &mut dyn Visit) {
		visitor.visit_named_fields(&NamedValues::new(
			SATA_COMMAND_INFO_FIELDS,
			&[
				Valuable::as_value(&self.user.0),
				Valuable::as_value(&self.user.1),
				Valuable::as_value(&(self.capabilities.0 & 0xFF)),
				Valuable::as_value(&((self.capabilities.0 >> 8) & 0xFF)),
				Valuable::as_value(&((self.capabilities.1) & 0xFF)),
				Valuable::as_value(&((self.capabilities.0 >> 16) & 0xFF)),
				Valuable::as_value(&((self.capabilities.0 >> 24) & 0xFF)),
				Valuable::as_value(&self.command),
			],
		));
	}
}

impl Display for SataCommandInfo {
	fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult {
		write!(
			fmt,
			"Cmd: {},   user: {} {},  cap: {} {} {} {} {}",
			self.command,
			self.user.0,
			self.user.1,
			self.capabilities.0 & 0xFF,
			(self.capabilities.0 >> 8) & 0xFF,
			self.capabilities.1 & 0xFF,
			(self.capabilities.0 >> 16) & 0xFF,
			(self.capabilities.0 >> 24) & 0xFF,
		)
	}
}

/// Move to a particular location inside of a file.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Valuable)]
pub enum MoveToFileLocation {
	/// Move to the beginning of the file.
	Begin,
	/// Move nowhere.
	Current,
	/// Move to the end of a file.
	End,
}

impl MoveToFileLocation {
	/// Actually seek around a particular file descriptor on a host filesystem.
	///
	/// ## Errors
	///
	/// If we do end up calling seek file, and the host filesystem seek files
	/// throws an error.
	pub async fn do_move(
		&self,
		host_fs: &HostFilesystem,
		handle: i32,
		stream_id: Option<u64>,
	) -> Result<(), FSError> {
		match *self {
			MoveToFileLocation::Begin => {
				host_fs.seek_file(handle, true, stream_id).await?;
			}
			MoveToFileLocation::Current => {
				// Luckily to move to current, we don't need to move at all.
			}
			MoveToFileLocation::End => {
				host_fs.seek_file(handle, false, stream_id).await?;
			}
		}

		Ok(())
	}
}

impl From<&MoveToFileLocation> for u32 {
	fn from(value: &MoveToFileLocation) -> u32 {
		match *value {
			MoveToFileLocation::Begin => 0,
			MoveToFileLocation::Current => 1,
			MoveToFileLocation::End => 2,
		}
	}
}

impl From<MoveToFileLocation> for u32 {
	fn from(value: MoveToFileLocation) -> u32 {
		Self::from(&value)
	}
}

impl TryFrom<u32> for MoveToFileLocation {
	type Error = SataProtocolError;

	fn try_from(value: u32) -> Result<Self, Self::Error> {
		match value {
			0 => Ok(Self::Begin),
			1 => Ok(Self::Current),
			2 => Ok(Self::End),
			val => Err(SataProtocolError::UnknownFileLocation(val)),
		}
	}
}

impl Display for MoveToFileLocation {
	fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult {
		match self {
			Self::Begin => write!(fmt, "Begin"),
			Self::Current => write!(fmt, "Nowhere"),
			Self::End => write!(fmt, "End"),
		}
	}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Valuable)]
#[repr(transparent)]
pub struct SataCapabilitiesFlags(pub u32);

bitflags::bitflags! {
	impl SataCapabilitiesFlags: u32 {
		const FAST_FILE_IO_SUPPORTED = 0b0000_0010;
		const COMBINED_SEND_RECV_SUPPORTED = 0b0000_0100;
	}
}

/// A wrapper type that attachs headers, and more to a request.
#[derive(Clone, Debug)]
pub struct SataRequest<InnerTy: Debug> {
	/// The header of the packet to send.
	header: SataPacketHeader,
	/// The command information to send to the server.
	command_info: SataCommandInfo,
	/// The body of the request.
	body: InnerTy,
}

impl<InnerTy: Debug> SataRequest<InnerTy> {
	/// Construct a new sata request.
	#[must_use]
	pub const fn new(
		header: SataPacketHeader,
		command_info: SataCommandInfo,
		body: InnerTy,
	) -> Self {
		Self {
			header,
			command_info,
			body,
		}
	}

	#[must_use]
	pub const fn header(&self) -> &SataPacketHeader {
		&self.header
	}

	#[must_use]
	pub const fn header_mut(&mut self) -> &mut SataPacketHeader {
		&mut self.header
	}

	#[must_use]
	pub const fn command_info(&self) -> &SataCommandInfo {
		&self.command_info
	}

	#[must_use]
	pub const fn command_info_mut(&mut self) -> &mut SataCommandInfo {
		&mut self.command_info
	}

	#[must_use]
	pub const fn body(&self) -> &InnerTy {
		&self.body
	}

	#[must_use]
	pub const fn body_mut(&mut self) -> &mut InnerTy {
		&mut self.body
	}

	#[must_use]
	pub fn into_parts(self) -> (SataPacketHeader, SataCommandInfo, InnerTy) {
		(self.header, self.command_info, self.body)
	}

	/// Parse a sata request with an 'opaque' body, which means unparsed.
	///
	/// This is useful in several situations where we don't know the type of body
	/// yet, so we keep it opaque.
	///
	/// ## Errors
	///
	/// If the packet header, or command info cannot be parsed.
	pub fn parse_opaque(mut body: Bytes) -> Result<SataRequest<Bytes>, NetworkParseError> {
		if body.len() < 0x34 {
			return Err(NetworkParseError::NotEnoughData(
				"SataRequest",
				0x34,
				body.len(),
				body,
			));
		}

		let header = SataPacketHeader::try_from(body.split_to(0x20))?;
		let ci = SataCommandInfo::try_from(body.split_to(0x14))?;

		Ok(SataRequest {
			header,
			command_info: ci,
			body,
		})
	}
}

impl<ErrorTy, InnerTy: Debug> TryFrom<Bytes> for SataRequest<InnerTy>
where
	InnerTy: TryFrom<Bytes, Error = ErrorTy>,
	ErrorTy: Into<NetworkParseError>,
{
	type Error = NetworkParseError;

	fn try_from(value: Bytes) -> Result<Self, Self::Error> {
		let (header, ci, bytes) = Self::parse_opaque(value)?.into_parts();
		let body = InnerTy::try_from(bytes).map_err(Into::into)?;

		Ok(Self {
			header,
			command_info: ci,
			body,
		})
	}
}

impl<InnerTy: Debug> From<SataRequest<InnerTy>> for Bytes
where
	InnerTy: Into<Bytes>,
{
	fn from(value: SataRequest<InnerTy>) -> Self {
		let body = value.body.into();
		let mut packet = BytesMut::with_capacity(0x34 + body.len());
		packet.extend(Bytes::from(&value.header));
		packet.extend(Bytes::from(&value.command_info));
		packet.extend(body);
		packet.freeze()
	}
}

const SATA_REQUEST_FIELDS: &[NamedField<'static>] = &[
	NamedField::new("header"),
	NamedField::new("command_info"),
	NamedField::new("body"),
];

impl<InnerTy: Debug> Structable for SataRequest<InnerTy> {
	fn definition(&self) -> StructDef<'_> {
		StructDef::new_static("SataRequest", Fields::Named(SATA_REQUEST_FIELDS))
	}
}

impl<InnerTy: Debug> Valuable for SataRequest<InnerTy> {
	fn as_value(&self) -> Value<'_> {
		Value::Structable(self)
	}

	fn visit(&self, visitor: &mut dyn Visit) {
		visitor.visit_named_fields(&NamedValues::new(
			SATA_REQUEST_FIELDS,
			&[
				Valuable::as_value(&self.header),
				Valuable::as_value(&self.command_info),
				Valuable::as_value(&format!("{:?}", self.body)),
			],
		));
	}
}

/// A wrapper type that just attaches headers, and more to a response.
#[derive(Debug)]
pub struct SataResponse<InnerTy: Debug> {
	/// The header of the packet.
	header: SataPacketHeader,
	/// Flags to return in the header.
	flags: u32,
	/// The process id to report.
	pid: u32,
	/// Whether or not to force a '0' as our version.
	force_zero_version: bool,
	/// The body of the rsponse.
	body: InnerTy,
}

impl<InnerTy: Debug> SataResponse<InnerTy> {
	/// Construct a new sata response.
	#[must_use]
	pub const fn new(pid: u32, header: SataPacketHeader, body: InnerTy) -> Self {
		Self {
			header,
			flags: 0,
			pid,
			body,
			force_zero_version: false,
		}
	}

	#[must_use]
	pub const fn new_force_zero_version(pid: u32, header: SataPacketHeader, body: InnerTy) -> Self {
		Self {
			header,
			flags: 0,
			pid,
			body,
			force_zero_version: true,
		}
	}

	#[must_use]
	pub const fn new_with_flags(
		pid: u32,
		header: SataPacketHeader,
		flags: u32,
		body: InnerTy,
	) -> Self {
		Self {
			header,
			flags,
			pid,
			body,
			force_zero_version: false,
		}
	}

	#[must_use]
	pub const fn from_existing(header: SataPacketHeader, body: InnerTy) -> Self {
		let flags = header.flags();
		let host_pid = header.host_pid();

		Self {
			header,
			flags,
			pid: host_pid,
			body,
			force_zero_version: false,
		}
	}

	#[must_use]
	pub const fn header(&self) -> &SataPacketHeader {
		&self.header
	}

	#[must_use]
	pub const fn body(&self) -> &InnerTy {
		&self.body
	}

	#[must_use]
	pub fn take_body(self) -> InnerTy {
		self.body
	}

	#[must_use]
	pub fn to_parts(self) -> (SataPacketHeader, InnerTy) {
		(self.header, self.body)
	}

	/// Parse a sata response with an 'opaque' body, which means unparsed.
	///
	/// This is useful in several situations where we don't know the type of body
	/// yet, so we keep it opaque.
	///
	/// ## Errors
	///
	/// If the packet header cannot be parsed.
	pub fn parse_opaque(mut body: Bytes) -> Result<SataResponse<Bytes>, NetworkParseError> {
		if body.len() < 0x20 {
			return Err(NetworkParseError::NotEnoughData(
				"SataResponse",
				0x20,
				body.len(),
				body,
			));
		}

		let header = SataPacketHeader::try_from(body.split_to(0x20))?;

		Ok(SataResponse::from_existing(header, body))
	}
}

impl<ErrorTy: Into<NetworkError>, InnerTy: Debug> TryFrom<Bytes> for SataResponse<InnerTy>
where
	InnerTy: TryFrom<Bytes, Error = ErrorTy>,
{
	type Error = NetworkError;

	fn try_from(mut value: Bytes) -> Result<Self, Self::Error> {
		if value.len() < 0x20 {
			return Err(
				NetworkParseError::NotEnoughData("SataResponse", 0x20, value.len(), value).into(),
			);
		}

		let real_body = value.split_off(0x20_usize);
		let header = SataPacketHeader::try_from(value)?;
		let flags = header.flags();
		let pid = header.host_pid();
		let body = InnerTy::try_from(real_body).map_err(Into::into)?;

		Ok(Self {
			header,
			flags,
			pid,
			body,
			force_zero_version: false,
		})
	}
}

impl<InnerTy: Debug> TryFrom<SataResponse<InnerTy>> for Bytes
where
	InnerTy: Into<Bytes>,
{
	type Error = PcfsApiError;

	fn try_from(value: SataResponse<InnerTy>) -> Result<Self, Self::Error> {
		let body_as_bytes = value.body.into();
		let mut new_buff = BytesMut::with_capacity(0x20 + body_as_bytes.len());

		new_buff.put_u32(
			u32::try_from(body_as_bytes.len())
				.map_err(|_| PcfsApiError::PacketTooLargeForSata(body_as_bytes.len()))?,
		);
		new_buff.put_u32(value.header.id());
		new_buff.put_u32(value.flags);
		if value.force_zero_version {
			new_buff.put_u32(0);
		} else {
			new_buff.put_u32(if value.header.version() != 0 {
				value.header.version()
			} else {
				DEFAULT_PCFS_VERSION
			});
		}
		// Calculate epoch, and wrap around...
		new_buff.put_u32(
			u32::try_from(
				SystemTime::now()
					.duration_since(SystemTime::UNIX_EPOCH)
					.unwrap_or(Duration::from_secs(0))
					.as_secs()
					.rem_euclid(u64::from(u32::MAX)),
			)
			.unwrap_or(u32::MAX),
		);
		// Put our PID, and appropriate padding.
		new_buff.put_u32(value.pid);
		new_buff.extend([0; 8]);
		// Now we can finally add our body!
		new_buff.extend(body_as_bytes);

		Ok(new_buff.freeze())
	}
}

impl<InnerTy: Debug> IntoResponse for SataResponse<InnerTy>
where
	InnerTy: Into<Bytes>,
{
	fn to_response(self) -> Result<Response, CatBridgeError> {
		Ok(Response::new_with_body(self.try_into()?))
	}
}

const SATA_RESPONSE_FIELDS: &[NamedField<'static>] = &[
	NamedField::new("header"),
	NamedField::new("pid"),
	NamedField::new("flags"),
	NamedField::new("body"),
];

impl<InnerTy: Debug> Structable for SataResponse<InnerTy> {
	fn definition(&self) -> StructDef<'_> {
		StructDef::new_static("SataResponse", Fields::Named(SATA_RESPONSE_FIELDS))
	}
}

impl<InnerTy: Debug> Valuable for SataResponse<InnerTy> {
	fn as_value(&self) -> Value<'_> {
		Value::Structable(self)
	}

	fn visit(&self, visitor: &mut dyn Visit) {
		visitor.visit_named_fields(&NamedValues::new(
			SATA_RESPONSE_FIELDS,
			&[
				Valuable::as_value(&self.header),
				Valuable::as_value(&self.pid),
				Valuable::as_value(&self.flags),
				Valuable::as_value(&format!("{:?}", self.body)),
			],
		));
	}
}

/// A result code that is serializable, and abstracts away just returning a
/// single result code.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Valuable)]
#[repr(transparent)]
pub struct SataResultCode(pub u32);

impl SataResultCode {
	#[must_use]
	pub const fn success() -> Self {
		Self(0)
	}

	#[must_use]
	pub const fn error(code: u32) -> Self {
		Self(code)
	}
}

impl From<&SataResultCode> for Bytes {
	fn from(value: &SataResultCode) -> Self {
		let mut buff = BytesMut::with_capacity(4);
		buff.put_u32(value.0);
		buff.freeze()
	}
}

impl From<SataResultCode> for Bytes {
	fn from(value: SataResultCode) -> Self {
		Self::from(&value)
	}
}

impl TryFrom<Bytes> for SataResultCode {
	type Error = NetworkParseError;

	fn try_from(value: Bytes) -> Result<Self, Self::Error> {
		if value.len() < 0x4 {
			return Err(NetworkParseError::FieldNotLongEnough(
				"SataPacket",
				"ResultCode",
				0x4,
				value.len(),
				value,
			));
		}
		if value.len() > 0x4 {
			return Err(NetworkParseError::UnexpectedTrailer(
				"SataResultCode",
				value.slice(0x4..),
			));
		}

		let rc = u32::from_be_bytes([value[0], value[1], value[2], value[3]]);

		Ok(Self(rc))
	}
}

impl Display for SataResultCode {
	fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult {
		if self.0 == 0 {
			write!(fmt, "Success")
		} else {
			write!(fmt, "Failure ({:02x})", self.0)
		}
	}
}

/// A file descriptor from a sata endpoint that optionally includes a single
/// result code in back.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Valuable)]
pub struct SataFileDescriptorResult {
	/// The file descriptor or error code...
	///
	/// `Ok()` is the file descriptor, which implies success.
	/// `Err()` is an error code, which sets a file descriptor as an error.
	file_descriptor: Result<i32, u32>,
}

impl SataFileDescriptorResult {
	/// A successful file descriptor, with a 0 error code.
	#[must_use]
	pub const fn success(fd: i32) -> Self {
		Self {
			file_descriptor: Ok(fd),
		}
	}

	/// A file descriptor result that returned an error code.
	#[must_use]
	pub const fn error(error_code: u32) -> Self {
		Self {
			file_descriptor: Err(error_code),
		}
	}

	/// The resulting file descriptor.
	///
	/// ## Errors
	///
	/// If there was an error code.
	pub const fn result(&self) -> Result<i32, u32> {
		self.file_descriptor
	}
}

impl From<&SataFileDescriptorResult> for Bytes {
	fn from(value: &SataFileDescriptorResult) -> Self {
		let mut response = BytesMut::with_capacity(8);

		match value.file_descriptor {
			Ok(fd) => {
				response.put_u32(0);
				response.put_i32(fd);
			}
			Err(code) => {
				response.put_u32(code);
				response.put_i32(i32::from_be_bytes([0xFF, 0xFF, 0xFF, 0xFF]));
			}
		}

		response.freeze()
	}
}

impl From<SataFileDescriptorResult> for Bytes {
	fn from(value: SataFileDescriptorResult) -> Self {
		Self::from(&value)
	}
}

impl TryFrom<Bytes> for SataFileDescriptorResult {
	type Error = NetworkParseError;

	fn try_from(value: Bytes) -> Result<Self, Self::Error> {
		if value.len() < 0x8 {
			return Err(NetworkParseError::FieldNotLongEnough(
				"SataPacket",
				"FileDescriptorResult",
				0x8,
				value.len(),
				value,
			));
		}
		if value.len() > 0x8 {
			return Err(NetworkParseError::UnexpectedTrailer(
				"SataFileDescriptorResult",
				value.slice(0x8..),
			));
		}

		let rc = u32::from_be_bytes([value[0], value[1], value[2], value[3]]);
		let fd = i32::from_be_bytes([value[4], value[5], value[6], value[7]]);

		if rc == 0 {
			Ok(Self::success(fd))
		} else {
			Ok(Self::error(rc))
		}
	}
}

impl Display for SataFileDescriptorResult {
	fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult {
		match self.file_descriptor {
			Ok(fd) => write!(fmt, "Success ({fd})"),
			Err(rc) => write!(fmt, "Failure ({rc:02x})"),
		}
	}
}

#[cfg(test)]
mod unit_tests {
	use super::*;

	#[test]
	pub fn move_to_file_location_conversions() {
		for mtfl in vec![
			MoveToFileLocation::Begin,
			MoveToFileLocation::Current,
			MoveToFileLocation::End,
		] {
			assert_eq!(
				mtfl,
				MoveToFileLocation::try_from(u32::from(mtfl))
					.expect("MTFL turned into u32 could not be parsed"),
				"MoveToFileLocation wasn't the same after being converted back n forth!",
			);
		}
	}

	fn parse_sata_request<
		ErrorTy: Into<NetworkParseError>,
		BodyTy: Debug + TryFrom<Bytes, Error = ErrorTy>,
	>(
		body: Bytes,
	) -> (SataPacketHeader, SataCommandInfo, BodyTy) {
		SataRequest::try_from(body)
			.expect("Failed to parse sata request!")
			.into_parts()
	}

	#[test]
	pub fn decode_real_ping_packet() {
		let (header, command_info, _body) =
			parse_sata_request::<_, SataPingPacketBody>(Bytes::from(vec![
				0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x40, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00,
				0x51, 0xAD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14,
			]));

		assert_eq!(header.data_len(), 0x14);
		assert_eq!(header.id(), 0);
		assert_eq!(
			header.flags(),
			(SataCapabilitiesFlags::FAST_FILE_IO_SUPPORTED
				| SataCapabilitiesFlags::COMBINED_SEND_RECV_SUPPORTED)
				.0
		);
		assert_eq!(header.host_pid(), 0);
		assert_eq!(header.raw_timestamp_on_host(), 0);
		// This ping packet was the first packet, so no version was set yet.
		assert_eq!(header.version(), 0);
		assert_eq!(command_info.command(), 0x14);
	}

	#[test]
	pub fn decode_real_query_info_packet() {
		let (_header, command_info, body) =
			parse_sata_request::<_, SataGetInfoByQueryPacketBody>(Bytes::from(vec![
				0x00, 0x00, 0x02, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x02, 0x00,
				0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
				0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x2f, 0x25, 0x53, 0x4c,
				0x43, 0x5f, 0x45, 0x4d, 0x55, 0x5f, 0x44, 0x49, 0x52, 0x2f, 0x73, 0x79, 0x73, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
			]));

		assert_eq!(command_info.command(), 0x10);
		assert_eq!(body.query_type(), SataQueryType::FileDetails);
		assert_eq!(body.path(), "/%SLC_EMU_DIR/sys");
	}

	#[test]
	pub fn decode_real_change_mode_packet() {
		let (_header, command_info, body) =
			parse_sata_request::<_, SataChangeModePacketBody>(Bytes::from(vec![
				0x00, 0x00, 0x02, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
				0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
				0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x2f, 0x25, 0x53, 0x4c,
				0x43, 0x5f, 0x45, 0x4d, 0x55, 0x5f, 0x44, 0x49, 0x52, 0x2f, 0x73, 0x79, 0x73, 0x2f,
				0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			]));

		assert_eq!(command_info.command(), 0x13);
		assert_eq!(body.path(), "/%SLC_EMU_DIR/sys/config");
		assert!(!body.will_set_write_mode());
	}

	#[test]
	pub fn decode_open_file_packet() {
		let (_header, command_info, body) =
			parse_sata_request::<_, SataOpenFilePacketBody>(Bytes::from(vec![
				0x00, 0x00, 0x02, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
				0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
				0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x72, 0x00, 0x53, 0x4c,
				0x43, 0x5f, 0x45, 0x4d, 0x55, 0x5f, 0x44, 0x49, 0x52, 0x2f, 0x73, 0x79, 0x2f, 0x25,
				0x53, 0x4c, 0x43, 0x5f, 0x45, 0x4d, 0x55, 0x5f, 0x44, 0x49, 0x52, 0x2f, 0x73, 0x79,
				0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x73, 0x79, 0x73, 0x74, 0x65,
				0x6d, 0x2e, 0x78, 0x6d, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			]));

		assert_eq!(command_info.command(), 0x5);
		assert_eq!(body.mode(), "r");
		assert_eq!(body.path(), "/%SLC_EMU_DIR/sys/config/system.xml");
	}

	#[test]
	pub fn decode_read_file_packet() {
		let (_header, command_info, body) =
			parse_sata_request::<_, SataReadFilePacketBody>(Bytes::from(vec![
				0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
				0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
				0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01,
				0x00, 0x00, 0x05, 0x1b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00,
			]));

		assert_eq!(command_info.command(), 0x6);
		assert_eq!(body.block_count(), 1);
		assert_eq!(body.block_size(), 0x51B);
		assert_eq!(body.file_descriptor(), 2);
		assert_eq!(body.move_to_pointer(), MoveToFileLocation::Begin);
		assert_eq!(body.should_move(), false);
	}

	#[test]
	pub fn decode_close_file_packet() {
		let (_header, command_info, body) =
			parse_sata_request::<_, SataCloseFilePacketBody>(Bytes::from(vec![
				0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
				0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
				0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x02,
			]));

		assert_eq!(command_info.command(), 0xD);
		assert_eq!(body.file_descriptor(), 2);
	}

	#[test]
	pub fn decode_open_folder_packet() {
		let (_header, command_info, body) =
			parse_sata_request::<_, SataOpenFolderPacketBody>(Bytes::from(vec![
				0x00, 0x00, 0x02, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
				0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
				0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2f, 0x25, 0x4d, 0x4c,
				0x43, 0x5f, 0x45, 0x4d, 0x55, 0x5f, 0x44, 0x49, 0x52, 0x2f, 0x75, 0x73, 0x72, 0x2f,
				0x74, 0x6d, 0x70, 0x00, 0x70, 0x2e, 0x78, 0x6d, 0x6c, 0x00, 0x52, 0x2f, 0x73, 0x79,
				0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x73, 0x79, 0x73, 0x74, 0x65,
				0x6d, 0x2e, 0x78, 0x6d, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00,
			]));

		assert_eq!(command_info.command(), 0x1);
		assert_eq!(body.path(), "/%MLC_EMU_DIR/usr/tmp");
	}

	#[test]
	pub fn decode_read_folder_packet() {
		let (_header, command_info, body) =
			parse_sata_request::<_, SataReadFolderPacketBody>(Bytes::from(vec![
				0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
				0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
				0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
			]));

		assert_eq!(command_info.command(), 0x2);
		assert_eq!(body.file_descriptor(), 1);
	}

	#[test]
	pub fn decode_close_folder_packet() {
		let (_header, command_info, body) =
			parse_sata_request::<_, SataCloseFolderPacketBody>(Bytes::from(vec![
				0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
				0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
				0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01,
			]));

		assert_eq!(command_info.command(), 0x04);
		assert_eq!(body.file_descriptor(), 1);
	}
}