Skip to content

Commit 7ab9dd9

Browse files
implemented several encode functions
1 parent c4095b0 commit 7ab9dd9

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

amqp-lib/src/types/amqp_type.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,37 +190,37 @@ impl Encode for Uuid {
190190
impl Encode for u32 {
191191
fn encode(&self) -> Encoded {
192192
match self {
193-
0 => 0x43.into(),
194-
x if x > &0 && x <= &255 => 0x52.into(),
195-
_ => 0x70.into(),
193+
0 => Encoded::new(0x43, None),
194+
x if x > &0 && x <= &255 => Encoded::new(0x52, Some(x.to_be_bytes().to_vec())),
195+
_ => Encoded::new(0x70, Some(self.to_be_bytes().to_vec())),
196196
}
197197
}
198198
}
199199

200200
impl Encode for u64 {
201201
fn encode(&self) -> Encoded {
202202
match self {
203-
0 => 0x44.into(),
204-
x if x > &&0 && x <= &255 => 0x53.into(),
205-
_ => 0x80.into(),
203+
0 => Encoded::new(0x44, None),
204+
x if x > &&0 && x <= &255 => Encoded::new(0x53, Some(x.to_be_bytes().to_vec())),
205+
_ => Encoded::new(0x80, Some(self.to_be_bytes().to_vec()))
206206
}
207207
}
208208
}
209209

210210
impl Encode for i32 {
211211
fn encode(&self) -> Encoded {
212212
match self {
213-
x if x >= &-128 && x <= &127 => 0x54.into(),
214-
_ => 0x71.into(),
213+
x if x >= &-128 && x <= &127 => Encoded::new(0x54, Some(x.to_be_bytes().to_vec())),
214+
_ => Encoded::new(0x71, Some(self.to_be_bytes().to_vec()))
215215
}
216216
}
217217
}
218218

219219
impl Encode for i64 {
220220
fn encode(&self) -> Encoded {
221221
match self {
222-
x if x >= &-128 && x <= &127 => 0x55.into(),
223-
_ => 0x81.into(),
222+
x if x >= &-128 && x <= &127 => Encoded::new(0x55, Some(x.to_be_bytes().to_vec())),
223+
_ => Encoded::new(0x81, Some(self.to_be_bytes().to_vec()))
224224
}
225225
}
226226
}
@@ -231,16 +231,16 @@ impl Encode for String {
231231
x if x >= 0 as usize && x <= 255 as usize => {
232232
Encoded::new(0xa1, Some(self.as_bytes().to_vec()))
233233
}
234-
_ => 0xb1.into(),
234+
_ => Encoded::new(0xb1, Some(self.as_bytes().to_vec()))
235235
}
236236
}
237237
}
238238

239239
impl Encode for Symbol {
240240
fn encode(&self) -> Encoded {
241241
match self.0.len() {
242-
x if x <= 255 => 0xa3.into(),
243-
_ => 0xb1.into(),
242+
x if x <= 255 => Encoded::new(0xa3, Some(self.0.as_bytes().to_vec())),
243+
_ => Encoded::new(0xb1, Some(self.0.as_bytes().to_vec())),
244244
}
245245
}
246246
}

0 commit comments

Comments
 (0)