Skip to content

Commit 37c8439

Browse files
some changes
1 parent 75345af commit 37c8439

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

amqp-lib/src/types/amqp_type.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,31 @@ impl Encoded {
7272

7373
impl From<Encoded> for Vec<u8> {
7474
fn from(value: Encoded) -> Self {
75-
todo!()
75+
let mut res = Vec::new();
76+
match value {
77+
Encoded::Empty(c) => res.push(c),
78+
Encoded::Fixed(c, data) => {
79+
res.push(c);
80+
res.append(data);
81+
}
82+
Encoded::Variable(c, data) => {
83+
res.push(c);
84+
res.append(data);
85+
}
86+
Encoded::Compound(c, count, data) => {
87+
88+
}
89+
}
90+
res
7691
}
7792
}
7893

79-
impl From<Vec<Encoded>> for Vec<u8> {
80-
fn from(value: Vec<Encoded>) -> Self {
94+
95+
impl From<Encoded> for &mut Vec<u8> {
96+
fn from(value: Encoded) -> Self {
97+
match value {
98+
99+
}
81100
todo!()
82101
}
83102
}

amqp-lib/src/types/collection.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ pub struct Array(Vec<AmqpType>);
1212
#[derive(Eq, PartialEq)]
1313
pub struct Map(IndexMap<AmqpType, AmqpType>);
1414

15+
struct EncodedCompound(Vec<Encoded>);
1516
impl Encode for List {
1617
fn encode(&self) -> Encoded {
1718
let encoded: Vec<Encoded> = self.0.iter().map(|x| x.encode()).collect();
1819
let count = encoded.len();
1920
let byte_size = encoded.iter().fold(0, |acc, x| acc + x.data_len());
2021
match (encoded.len(), byte_size) {
2122
(0, _) => 0x45.into(),
22-
(len, size) if len <= 255 && size < 256 => Encoded::new_compound(0xc0, count, encoded.into()),
23-
(_, _) => 0xd0.into(),
23+
(len, size) if len <= 255 && size < 256 => Encoded::new_compound(0xc0, count as u32 as u32, EncodedCompound(encoded).into()),
24+
(_, _) =>Encoded::new_compound(0xd0, count as u32 as u32, EncodedCompound(encoded).into()),
2425
}
2526
}
2627
}
@@ -43,6 +44,16 @@ impl Encode for Array {
4344
}
4445
}
4546

47+
impl From<EncodedCompound> for Vec<u8> {
48+
fn from(value: EncodedCompound) -> Self {
49+
let mut res = Vec::new();
50+
for val in value.0 {
51+
res.append(val.into());
52+
}
53+
res
54+
}
55+
}
56+
4657
impl From<Vec<AmqpType>> for List {
4758
fn from(value: Vec<AmqpType>) -> Self {
4859
List(value)

0 commit comments

Comments
 (0)