Skip to content

Commit b53dc59

Browse files
committed
fix rou serialization
1 parent 0d282ed commit b53dc59

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

p3-rou/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct TradeRouteFile {
77
pub struct TradeRouteStop {
88
pub town_index: u8,
99
pub action: u8,
10-
pub order: [i32; 24],
10+
pub order: [u8; 24],
1111
pub price: [i32; 24],
1212
pub amount: [i32; 24],
1313
}
@@ -29,15 +29,15 @@ impl TradeRouteStop {
2929
output.extend_from_slice(&(0u16).to_le_bytes());
3030
output.extend_from_slice(&self.town_index.to_le_bytes());
3131
output.extend_from_slice(&self.action.to_le_bytes());
32-
output.extend_from_slice(&convert(&self.order));
32+
output.extend_from_slice(&self.order);
3333
output.extend_from_slice(&convert(&self.price));
3434
output.extend_from_slice(&convert(&self.amount));
3535
}
3636
}
3737

3838
// https://stackoverflow.com/a/72631195/1569755
39-
pub fn convert(data: &[i32; 24]) -> [u8; 220] {
40-
let mut res = [0; 220];
39+
pub fn convert(data: &[i32; 24]) -> [u8; 96] {
40+
let mut res = [0; 96];
4141
for i in 0..24 {
4242
res[4 * i..][..4].copy_from_slice(&data[i].to_le_bytes());
4343
}

p3-rou/tests/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use log::LevelFilter;
22
use p3_rou::{decompress::decompress_file, TradeRouteFile, TradeRouteStop};
3-
const DEFAULT_ORDER: [i32; 24] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23];
3+
const DEFAULT_ORDER: [u8; 24] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23];
44
const A_ROU: &[u8; 2 * 220] = &[
55
0x00, 0x00, 0x06, 0x04, 0x03, 0x13, 0x08, 0x02, 0x00, 0x11, 0x05, 0x0c, 0x0d, 0x01, 0x10, 0x0f, 0x12, 0x04, 0x09, 0x06, 0x0b, 0x0a, 0x07, 0x0e, 0x15, 0x17,
66
0x16, 0x14, 0x6e, 0x00, 0x00, 0x00, 0xbd, 0x03, 0x00, 0x00, 0xb8, 0x01, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00,
@@ -36,10 +36,16 @@ fn test_serialize1() {
3636
let rou = TradeRouteFile {
3737
stops: vec![TradeRouteStop {
3838
town_index: 0,
39-
action: 1,
39+
action: 0,
4040
order: DEFAULT_ORDER,
41-
price: [0; 24],
42-
amount: [0; 24],
41+
price: [400; 24],
42+
amount: [2000; 24],
43+
},TradeRouteStop {
44+
town_index: 1,
45+
action: 0,
46+
order: DEFAULT_ORDER,
47+
price: [300; 24],
48+
amount: [2000; 24],
4349
}],
4450
};
4551

0 commit comments

Comments
 (0)