aboutsummaryrefslogtreecommitdiff
path: root/src/primitive/stringlist.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/primitive/stringlist.rs')
-rw-r--r--src/primitive/stringlist.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/primitive/stringlist.rs b/src/primitive/stringlist.rs
new file mode 100644
index 0000000..e5d1a44
--- /dev/null
+++ b/src/primitive/stringlist.rs
@@ -0,0 +1,49 @@
+extern crate byteorder;
+
+use std::convert::TryInto;
+use std::result::Result;
+use std::vec::Vec;
+
+use failure::Error;
+
+use log::trace;
+
+use crate::{Deserialize, Serialize};
+
+/// StringList are represented as a Vec of Strings
+///
+/// StringLists are serialized as an i32 of the amount of elements and then each element as a String
+pub type StringList = Vec<String>;
+
+impl Serialize for StringList {
+ fn serialize(&self) -> Result<Vec<u8>, Error> {
+ let len: i32 = self.len().try_into()?;
+ let mut res: Vec<u8> = Vec::new();
+
+ res.extend(len.to_be_bytes().iter());
+ for x in self {
+ res.extend(x.serialize()?);
+ }
+
+ return Ok(res);
+ }
+}
+
+impl Deserialize for StringList {
+ fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ let (_, len) = i32::parse(&b[0..4])?;
+ trace!(target: "primitive::StringList", "Parsing with length: {:?}, from bytes: {:x?}", len, &b[0..4]);
+ let mut res: StringList = StringList::new();
+
+ let mut pos = 4;
+ if len > 0 {
+ for _ in 0..len {
+ let (lpos, val) = String::parse(&b[pos..])?;
+ pos += lpos;
+ res.push(val);
+ }
+ }
+
+ return Ok((pos, res));
+ }
+}
=1'>R0flcopt3r/catinator-pet-commandMax Audron-5/+5 2021-06-05feat: adds pet command.R0flcopt3r-0/+90 When petting the cat it will reply with some random action. 2021-06-05feat: send actionR0flcopt3r-1/+9 2021-06-05release version 1.1.0Max Audron-2/+2 2021-06-05document proc macrosMax Audron-4/+97 2021-06-05add intensifyMax Audron-3/+27 2021-06-05add privmsg macroMax Audron-2/+40 2021-06-05fix jb remote urlsMax Audron-4/+4 2021-06-05remove egress gateway configMax Audron-10/+0 2021-06-05update tanka dependenciesMax Audron-8/+8 2021-06-05fix init container nameMax Audron-1/+1 2021-06-05fix tanka dependency pathMax Audron-8/+8 2021-06-05switch to https url for tanka util libMax Audron-2/+2 2021-06-05bump version to 1.0.2Max Audron-2/+2 2021-06-05add tanka ci configurationMax Audron-1/+1 2021-06-05ready tanka deploy for CIMax Audron-32/+69 2021-06-05remove tanka vendoringMax Audron-27651/+0 2021-05-26Release 1.0.1Max Audron-3/+3 2021-05-26fix log breaking once buffer fullMax Audron-2/+33 the log_msg function was poping the newest message and replacing it with the newest message, it should be poping the oldest messages. 2021-05-16add deployment stuffMax Audron-6/+27786 2021-05-15add container buildMax Audron-2/+35