mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
remove dictionary parsing/rendering for now
This commit is contained in:
parent
f892d406f4
commit
d5768a3040
5 changed files with 0 additions and 451 deletions
|
@ -18,14 +18,11 @@ extern "C" {
|
|||
|
||||
fn psyc_elem_length_check(value: *const PsycString, end: c_char) -> PsycElemFlag;
|
||||
fn psyc_elem_length(elem: *const PsycElem) -> usize;
|
||||
fn psyc_dict_key_length(elem: *const PsycDictKey) -> usize;
|
||||
fn psyc_list_length_set(list: *mut RawPsycList) -> usize;
|
||||
fn psyc_dict_length_set(dict: *mut RawPsycDict) -> usize;
|
||||
fn psyc_modifier_length(m: *const RawPsycModifier) -> usize;
|
||||
fn psyc_packet_length_check(p: *const RawPsycPacket) -> PsycPacketFlag;
|
||||
fn psyc_packet_length_set(p: *mut RawPsycPacket) -> usize;
|
||||
fn psyc_list_init(list: *mut RawPsycList, elems: *const PsycElem, num_elems: usize);
|
||||
fn psyc_dict_init(dict: *mut RawPsycDict, elems: *const PsycDictElem, num_elems: usize);
|
||||
fn psyc_packet_init(packet: *mut RawPsycPacket,
|
||||
routing: *const RawPsycModifier,
|
||||
routinglen: usize,
|
||||
|
@ -62,19 +59,13 @@ extern "C" {
|
|||
fn psyc_render(packet: *const RawPsycPacket, buffer: *mut c_char, buflen: usize) -> PsycRenderRC;
|
||||
fn psyc_render_modifier(modifier: *const RawPsycModifier, buffer: *mut c_char) -> usize;
|
||||
fn psyc_render_elem(elem: *const PsycElem, buffer: *mut c_char, buflen: usize) -> PsycRenderRC;
|
||||
fn psyc_render_dict_key(elem: *const PsycDictKey, buffer: *mut c_char, buflen: usize) -> PsycRenderRC;
|
||||
fn psyc_render_list(list: *const RawPsycList, buffer: *mut c_char, buflen: usize) -> PsycRenderRC;
|
||||
fn psyc_render_dict(dict: *const RawPsycDict, buffer: *mut c_char, buflen: usize) -> PsycRenderRC;
|
||||
}
|
||||
|
||||
pub struct PsycList {
|
||||
rendered_list: Vec<u8>
|
||||
}
|
||||
|
||||
pub struct PsycDict {
|
||||
rendered_dict: Vec<u8>
|
||||
}
|
||||
|
||||
pub struct PsycModifier<'a> {
|
||||
name: &'a str,
|
||||
value: &'a [u8],
|
||||
|
@ -128,39 +119,6 @@ impl PsycList {
|
|||
}
|
||||
}
|
||||
|
||||
impl PsycDict {
|
||||
/// Construct a PsycDict from a list of key value pairs
|
||||
pub fn new(dict: &[(&[u8], &[u8])]) -> Self {
|
||||
let mut psyc_dict: RawPsycDict;
|
||||
let elements: Vec<PsycDictElem>;
|
||||
let mut buffer: Vec<u8>;
|
||||
unsafe {
|
||||
psyc_dict = mem::uninitialized();
|
||||
let psyc_dict_ptr = &mut psyc_dict as *mut RawPsycDict;
|
||||
elements = dict.iter().map(|e| make_psyc_dict_elem(e)).collect();
|
||||
let elements_ptr = elements.as_ptr() as *const PsycDictElem;
|
||||
psyc_dict_init(psyc_dict_ptr, elements_ptr, dict.len());
|
||||
buffer = Vec::with_capacity(psyc_dict.length);
|
||||
buffer.set_len(psyc_dict.length);
|
||||
let buffer_ptr = buffer.as_ptr() as *mut c_char;
|
||||
let _ = psyc_render_dict(psyc_dict_ptr, buffer_ptr, psyc_dict.length);
|
||||
}
|
||||
PsycDict{
|
||||
rendered_dict: buffer
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a PsycDict from a list of key / value string pairs (comfort
|
||||
/// function)
|
||||
pub fn from_strings(dict: &[(&str, &str)]) -> Self {
|
||||
let kv_list_slices: Vec<(&[u8], &[u8])> = dict.iter().map(|e| {
|
||||
let &(k, v) = e;
|
||||
(k.as_bytes(), v.as_bytes())
|
||||
}).collect();
|
||||
Self::new(&kv_list_slices)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PsycModifier<'a> {
|
||||
/// construct a PsycModifier
|
||||
pub fn new(operator: PsycOperator, name: &'a str, value: &'a [u8]) -> Self {
|
||||
|
@ -190,20 +148,6 @@ impl<'a> PsycModifier<'a> {
|
|||
operator: operator
|
||||
}
|
||||
}
|
||||
|
||||
/// construct a PsycModifier with a dictionary value (comfort function)
|
||||
pub fn with_dict_value(operator: PsycOperator,
|
||||
name: &'a str,
|
||||
value: &'a PsycDict)
|
||||
-> Self {
|
||||
PsycModifier {
|
||||
name: name,
|
||||
value: &value.rendered_dict,
|
||||
operator: operator
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
impl<'a> PsycPacket<'a> {
|
||||
|
@ -327,21 +271,3 @@ unsafe fn make_psyc_elem(list_element: &[u8]) -> PsycElem {
|
|||
flag: PsycElemFlag::PSYC_ELEM_CHECK_LENGTH
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn make_psyc_dict_elem(dict_element: &(&[u8], &[u8])) -> PsycDictElem {
|
||||
let &(key, value) = dict_element;
|
||||
let key_ptr = key.as_ptr() as *const c_char;
|
||||
let psyc_dict_elem_value = make_psyc_elem(value);
|
||||
let psyc_dict_elem_key = PsycDictKey {
|
||||
value: PsycString {
|
||||
length: key.len(),
|
||||
data: key_ptr
|
||||
},
|
||||
length: 0,
|
||||
flag: PsycElemFlag::PSYC_ELEM_CHECK_LENGTH
|
||||
};
|
||||
PsycDictElem {
|
||||
value: psyc_dict_elem_value,
|
||||
key: psyc_dict_elem_key
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,35 +61,6 @@ pub enum PsycPacketId {
|
|||
PSYC_PACKET_ID_ELEMS = 5,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct PsycElem {
|
||||
pub elem_type: PsycString,
|
||||
pub value: PsycString,
|
||||
pub length: usize,
|
||||
pub flag: PsycElemFlag
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct PsycDictKey {
|
||||
pub value: PsycString,
|
||||
pub length: usize,
|
||||
pub flag: PsycElemFlag
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct PsycDictElem {
|
||||
pub value: PsycElem,
|
||||
pub key: PsycDictKey
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct RawPsycDict {
|
||||
dict_type: PsycString,
|
||||
elems: *const PsycDictElem,
|
||||
num_elems: usize,
|
||||
pub length: usize
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct RawPsycList {
|
||||
list_type: PsycString,
|
||||
|
|
|
@ -9,20 +9,8 @@ extern "C" {
|
|||
fn psyc_parse_buffer_set(state: *mut PsycParseState, buffer: *const c_char, length: usize);
|
||||
fn psyc_parse_list_state_init(state: *mut PsycParseListState);
|
||||
fn psyc_parse_list_buffer_set(state: *mut PsycParseListState, buffer: *const c_char, length: usize);
|
||||
fn psyc_parse_dict_state_init(state: *mut PsycParseDictState);
|
||||
fn psyc_parse_dict_buffer_set(state: *mut PsycParseDictState, buffer: *const c_char, length: usize);
|
||||
fn psyc_parse_index_state_init(state: *mut PsycParseIndexState);
|
||||
fn psyc_parse_index_buffer_set(state: *mut PsycParseIndexState, buffer: *const c_char, length: usize);
|
||||
fn psyc_parse_update_state_init(state: *mut PsycParseUpdateState);
|
||||
fn psyc_parse_update_buffer_set(state: *mut PsycParseUpdateState, buffer: *const c_char, length: usize);
|
||||
fn psyc_parse_content_length(state: *mut PsycParseState) -> usize;
|
||||
fn psyc_parse_content_length_found(state: *mut PsycParseState) -> bool;
|
||||
fn psyc_parse_value_length(state: *mut PsycParseState) -> usize;
|
||||
fn psyc_parse_value_length_found(state: *mut PsycParseState) -> bool;
|
||||
fn psyc_parse_cursor(state: *const PsycParseState) -> usize;
|
||||
fn psyc_parse_buffer_length(state: *const PsycParseState) -> usize;
|
||||
fn psyc_parse_remaining_length(state: *const PsycParseState) -> usize;
|
||||
fn psyc_parse_remaining_buffer(state: *const PsycParseState) -> *const c_char;
|
||||
fn psyc_parse(state: *mut PsycParseState,
|
||||
oper: *mut c_char,
|
||||
name: *mut PsycString,
|
||||
|
@ -33,31 +21,6 @@ extern "C" {
|
|||
list_type: *mut PsycString,
|
||||
elem: *mut PsycString)
|
||||
-> PsycParseListRC;
|
||||
|
||||
fn psyc_parse_dict(state: *mut PsycParseDictState,
|
||||
dict_type: *mut PsycString,
|
||||
elem: *mut PsycString)
|
||||
-> PsycParseDictRC;
|
||||
|
||||
fn psyc_parse_index(state: *mut PsycParseIndexState,
|
||||
idx: *mut PsycString)
|
||||
-> PsycParseIndexRC;
|
||||
|
||||
fn psyc_parse_update(state: *mut PsycParseUpdateState,
|
||||
oper: *mut c_char,
|
||||
value: *mut PsycString)
|
||||
-> PsycParseUpdateRC;
|
||||
|
||||
fn psyc_parse_uint(value: *const c_char, len: usize, n: *mut u64) -> usize;
|
||||
fn psyc_parse_list_index(value: *const c_char, len: usize, n: *mut i64) -> usize;
|
||||
fn psyc_is_oper(g: c_char) -> bool;
|
||||
fn psyc_is_numeric(c: c_char) -> bool;
|
||||
fn psyc_is_alpha(c: c_char) -> bool;
|
||||
fn psyc_is_alpha_numeric(c: c_char) -> bool;
|
||||
fn psyc_is_kw_char(c: c_char) -> bool;
|
||||
fn psyc_is_name_char(c: c_char) -> bool;
|
||||
fn psyc_is_host_char(c: c_char) -> bool;
|
||||
fn psyc_parse_keyword(data: *const c_char, len: usize) -> usize;
|
||||
}
|
||||
|
||||
pub struct PsycParser {
|
||||
|
@ -68,22 +31,6 @@ pub struct PsycListParser {
|
|||
state: PsycParseListState
|
||||
}
|
||||
|
||||
//pub struct PsycDictParser<'b> {
|
||||
// state: PsycParseDictState,
|
||||
// parsed_key: Option<&'b [u8]>,
|
||||
// cursor: usize
|
||||
//}
|
||||
//
|
||||
//// TODO: What data structures does the index parser need?
|
||||
//pub struct PsycIndexParser {
|
||||
// state: PsycParseIndexState
|
||||
//}
|
||||
//
|
||||
//// TODO: what data structures does the update parser need?
|
||||
//pub struct PsycUpdateParser {
|
||||
// state: PsycParseUpdateState
|
||||
//}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum PsycParserResult<'a> {
|
||||
StateSync,
|
||||
|
@ -145,26 +92,6 @@ pub enum PsycListParserResult<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
//#[derive(Debug, PartialEq)]
|
||||
//pub enum PsycDictParserResult<'a> {
|
||||
// Complete,
|
||||
// InsufficientData,
|
||||
// DictEntry {
|
||||
// key: &'a [u8],
|
||||
// value: &'a [u8]
|
||||
// },
|
||||
// DictEntryStart {
|
||||
// key: &'a [u8],
|
||||
// value_part: &'a [u8]
|
||||
// },
|
||||
// DictEntryCont {
|
||||
// value_part: &'a [u8]
|
||||
// },
|
||||
// DictEntryEnd {
|
||||
// value_part: &'a [u8]
|
||||
// }
|
||||
//}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum PsycParserError {
|
||||
|
@ -191,21 +118,6 @@ pub enum PsycListParserError {
|
|||
GenericError = PsycParseListRC::PSYC_PARSE_LIST_ERROR as _,
|
||||
}
|
||||
|
||||
//#[repr(C)]
|
||||
//#[derive(Debug, PartialEq)]
|
||||
//pub enum PsycDictParserError {
|
||||
// InvalidValue = PsycParseDictRC::PSYC_PARSE_DICT_ERROR_VALUE as _,
|
||||
// InvalidValueLength = PsycParseDictRC::PSYC_PARSE_DICT_ERROR_VALUE_LENGTH as _,
|
||||
// InvalidValueType = PsycParseDictRC::PSYC_PARSE_DICT_ERROR_VALUE_TYPE as _,
|
||||
// InvalidValueStart = PsycParseDictRC::PSYC_PARSE_DICT_ERROR_VALUE_START as _,
|
||||
// InvalidKey = PsycParseDictRC::PSYC_PARSE_DICT_ERROR_KEY as _,
|
||||
// InvalidKeyLength = PsycParseDictRC::PSYC_PARSE_DICT_ERROR_KEY_LENGTH as _,
|
||||
// InvalidKeyStart = PsycParseDictRC::PSYC_PARSE_DICT_ERROR_KEY_START as _,
|
||||
// InvalidKeyType = PsycParseDictRC::PSYC_PARSE_DICT_ERROR_TYPE as _,
|
||||
// GenericError = PsycParseDictRC::PSYC_PARSE_DICT_ERROR as _,
|
||||
// NoBuffer
|
||||
//}
|
||||
|
||||
impl PsycParser {
|
||||
/// Create a PsycParser
|
||||
pub fn new() -> Self {
|
||||
|
@ -430,143 +342,6 @@ impl Parser for PsycListParser {
|
|||
}
|
||||
}
|
||||
|
||||
//impl<'b> PsycDictParser<'b> {
|
||||
// /// Create a PsycDictParser
|
||||
// pub fn new() -> Self {
|
||||
// let mut state: PsycParseDictState;
|
||||
// unsafe {
|
||||
// state = mem::uninitialized();
|
||||
// let state_ptr = &mut state as *mut PsycParseDictState;
|
||||
// psyc_parse_dict_state_init(state_ptr)
|
||||
// }
|
||||
// PsycDictParser {
|
||||
// state: state,
|
||||
// parsed_key: None,
|
||||
// cursor: 0
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /// Parse the buffer previously set by set_buffer. Call repeatedly until the
|
||||
// /// result is PsycDictParserResult::Complete or a PsycDictParserError
|
||||
// pub fn parse<'a>(&mut self, buffer: &'a [u8])
|
||||
// -> Result<PsycDictParserResult<'a>, PsycDictParserError> {
|
||||
// let state_ptr = &mut self.state as *mut PsycParseDictState;
|
||||
// let buffer_ptr = buffer.as_ptr() as *const c_char;
|
||||
// let mut list_type: PsycString;
|
||||
// let mut element: PsycString;
|
||||
// unsafe {
|
||||
// if buffer_ptr != self.state.buffer.data ||
|
||||
// buffer.len() != self.state.buffer.length {
|
||||
// psyc_parse_dict_buffer_set(state_ptr, buffer_ptr, buffer.len())
|
||||
// }
|
||||
// list_type = mem::uninitialized();
|
||||
// element = mem::uninitialized();
|
||||
// let list_type_ptr = &mut list_type as *mut PsycString;
|
||||
// let element_ptr = &mut element as *mut PsycString;
|
||||
// loop {
|
||||
// let parse_result = psyc_parse_dict(state_ptr, list_type_ptr, element_ptr);
|
||||
// println!("parse_result: {:?}", parse_result);
|
||||
// println!("cursor: {}", self.state.cursor);
|
||||
// self.cursor = self.state.cursor;
|
||||
// match parse_result {
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_END =>
|
||||
// return Ok(PsycDictParserResult::Complete),
|
||||
//
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_INSUFFICIENT =>
|
||||
// return Ok(PsycDictParserResult::InsufficientData),
|
||||
//
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_KEY => {
|
||||
// let key = util::cstring_to_slice(element.data, element.length);
|
||||
// self.parsed_key = Some(key)
|
||||
// },
|
||||
//
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_KEY_START => {
|
||||
// self.cursor = element.data as usize -
|
||||
// buffer_ptr as usize;
|
||||
// return Ok(PsycDictParserResult::InsufficientData)
|
||||
// },
|
||||
//
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_KEY_CONT => {
|
||||
// return Ok(PsycDictParserResult::InsufficientData)
|
||||
// },
|
||||
//
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_KEY_END => {
|
||||
// let end_index = self.cursor + element.length;
|
||||
// let key = &buffer[self.cursor .. end_index];
|
||||
// self.parsed_key = Some(key)
|
||||
// },
|
||||
//
|
||||
// //PsycParseDictRC::PSYC_PARSE_DICT_VALUE => {
|
||||
// // let result = PsycDictParserResult::DictEntry {
|
||||
// // key: self.parsed_key.unwrap(),
|
||||
// // value: util::cstring_to_slice(element.data, element.length)
|
||||
// // };
|
||||
// // return Ok(result)
|
||||
// //},
|
||||
//
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_VALUE |
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_VALUE_LAST => {
|
||||
// //let result: PsycDictParserResult;
|
||||
// //// FIXME: workaround
|
||||
// //if ! self.finished {
|
||||
// // result = PsycDictParserResult::DictEntry {
|
||||
// // key: self.parsed_key.unwrap(),
|
||||
// // value: util::cstring_to_slice(element.data, element.length)
|
||||
// // };
|
||||
// // self.finished = true
|
||||
// //} else {
|
||||
// // result = PsycDictParserResult::Complete;
|
||||
// //}
|
||||
// let result = PsycDictParserResult::DictEntry {
|
||||
// key: self.parsed_key.unwrap(),
|
||||
// value: util::cstring_to_slice(element.data, element.length)
|
||||
// };
|
||||
// return Ok(result)
|
||||
// },
|
||||
//
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_VALUE_START => {
|
||||
// let result = PsycDictParserResult::DictEntryStart {
|
||||
// key: self.parsed_key.unwrap(),
|
||||
// value_part: util::cstring_to_slice(element.data, element.length)
|
||||
// };
|
||||
// return Ok(result)
|
||||
// },
|
||||
//
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_VALUE_CONT => {
|
||||
// let result = PsycDictParserResult::DictEntryCont {
|
||||
// value_part: util::cstring_to_slice(element.data, element.length)
|
||||
// };
|
||||
// return Ok(result)
|
||||
// },
|
||||
//
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_VALUE_END => {
|
||||
// let result = PsycDictParserResult::DictEntryEnd {
|
||||
// value_part: util::cstring_to_slice(element.data, element.length)
|
||||
// };
|
||||
// return Ok(result)
|
||||
// },
|
||||
//
|
||||
// PsycParseDictRC::PSYC_PARSE_DICT_TYPE => (),
|
||||
//
|
||||
// _error => {
|
||||
// return Err(mem::transmute(_error))
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//impl<'a, 'b> Parser<'a> for PsycDictParser<'b> {
|
||||
// fn unparsed_position(&self) -> usize {
|
||||
// self.cursor
|
||||
// }
|
||||
//
|
||||
// fn unparsed_length(&self) -> usize {
|
||||
// self.state.buffer.length - self.cursor
|
||||
// }
|
||||
//}
|
||||
|
||||
pub trait Parser {
|
||||
/// copies the remaining unparsed bytes to the beginning of the given buffer.
|
||||
/// Returns the number of copied bytes. Must be called when parse() returned
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
extern crate psyc;
|
||||
use psyc::parser::*;
|
||||
|
||||
//#[test]
|
||||
//fn test_parse() {
|
||||
// let test_data = "{foo1} bar1{foo2} bar2".to_string().into_bytes();
|
||||
//
|
||||
// let expected1 = PsycDictParserResult::DictEntry{
|
||||
// key: b"foo1",
|
||||
// value: b"bar1"
|
||||
// };
|
||||
//
|
||||
// let expected2 = PsycDictParserResult::DictEntry{
|
||||
// key: b"foo2",
|
||||
// value: b"bar2"
|
||||
// };
|
||||
//
|
||||
// let expected3 = PsycDictParserResult::Complete;
|
||||
//
|
||||
// let mut parser = PsycDictParser::new();
|
||||
//
|
||||
// parser.set_buffer(&test_data);
|
||||
//
|
||||
// assert_eq!(parser.parse().unwrap(), expected1);
|
||||
// assert_eq!(parser.parse().unwrap(), expected2);
|
||||
// assert_eq!(parser.parse().unwrap(), expected3);
|
||||
//}
|
||||
//
|
||||
//#[test]
|
||||
//fn test_empty() {
|
||||
// let test_data = "".to_string().into_bytes();
|
||||
//
|
||||
// let mut parser = PsycDictParser::new();
|
||||
//
|
||||
// parser.set_buffer(&test_data);
|
||||
//
|
||||
// assert_eq!(parser.parse().unwrap(), PsycDictParserResult::Complete);
|
||||
//}
|
||||
//
|
||||
//#[test]
|
||||
//fn test_incomplete() {
|
||||
// let test_data1 = "{foo1}4 bar".to_string().into_bytes();
|
||||
// let test_data2 = "1{foo2} bar2".to_string().into_bytes();
|
||||
//
|
||||
// let expected = vec![PsycDictParserResult::DictEntryStart {
|
||||
// key: b"foo1",
|
||||
// value_part: b"bar"
|
||||
// },
|
||||
// PsycDictParserResult::DictEntryEnd {
|
||||
// value_part: b"1"
|
||||
// },
|
||||
// PsycDictParserResult::DictEntry {
|
||||
// key: b"foo2",
|
||||
// value: b"bar2"
|
||||
// }];
|
||||
//
|
||||
// let mut parser = PsycDictParser::new();
|
||||
//
|
||||
// parser.set_buffer(&test_data1);
|
||||
// assert_eq!(parser.parse().unwrap(), expected[0]);
|
||||
//
|
||||
// parser.set_buffer(&test_data2);
|
||||
// assert_eq!(parser.parse().unwrap(), expected[1]);
|
||||
//
|
||||
// assert_eq!(parser.parse().unwrap(), expected[2]);
|
||||
//}
|
||||
//
|
||||
////#[test]
|
||||
////fn test_insufficient() {
|
||||
//// let mut test_data1 = "{4 foo".to_string().into_bytes();
|
||||
//// let mut test_data2 = "1} bar1".to_string().into_bytes();
|
||||
//// let mut test_data3 = "{4 foo1} bar1".to_string().into_bytes();
|
||||
////
|
||||
//// let expected = vec![PsycDictParserResult::InsufficientData,
|
||||
//// PsycDictParserResult::DictEntry {
|
||||
//// key: b"foo1",
|
||||
//// value: b"bar1"
|
||||
//// }];
|
||||
////
|
||||
//// let mut parser = PsycDictParser::new();
|
||||
////
|
||||
//// parser.set_buffer(&test_data1);
|
||||
//// assert_eq!(parser.parse().unwrap(), expected[0]);
|
||||
////
|
||||
//// //let unparsed_length = parser.copy_unparsed_into_buffer(&mut test_data1);
|
||||
//// //test_data1.resize(unparsed_length, 0);
|
||||
//// //test_data1.append(&mut test_data2);
|
||||
//// parser.set_buffer(&test_data3);
|
||||
//// assert_eq!(parser.parse().unwrap(), expected[1]);
|
||||
////}
|
|
@ -62,36 +62,3 @@ fn test_list() {
|
|||
|
||||
assert_eq!(rendered_packet, Ok(expected));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dict() {
|
||||
let r1 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||
"_target",
|
||||
"psyc://ve.symlynx.com/@blog".as_bytes());
|
||||
|
||||
let dict = PsycDict::from_strings(&[("key1", "value1"),
|
||||
("key2", "value2"),
|
||||
("key3", "value3")]);
|
||||
|
||||
let e1 = PsycModifier::with_dict_value(PsycOperator::PSYC_OPERATOR_SET,
|
||||
"_dict_test",
|
||||
&dict);
|
||||
|
||||
let routing_modifiers = vec![r1];
|
||||
let entity_modifiers = vec![e1];
|
||||
let data = vec![];
|
||||
|
||||
let packet = PsycPacket::new(&routing_modifiers,
|
||||
&entity_modifiers,
|
||||
"",
|
||||
&data,
|
||||
PsycStateOp::PSYC_STATE_NOOP);
|
||||
|
||||
let expected = ":_target\tpsyc://ve.symlynx.com/@blog\n58\n:_dict_test 42\t{ key1} value1{ key2} value2{ key3} value3\n|\n".as_bytes().to_vec();
|
||||
|
||||
let rendered_packet = packet.render();
|
||||
|
||||
//println!("rendered: {}", String::from_utf8(rendered_packet.unwrap()).unwrap());
|
||||
|
||||
assert_eq!(rendered_packet, Ok(expected));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue