Also make the last portion of a value available (when parsing values partially)

This commit is contained in:
lurchi 2016-08-31 19:44:55 +02:00
parent d12047ee18
commit b3b5757deb
1 changed files with 42 additions and 30 deletions

View File

@ -70,13 +70,11 @@ pub struct PsycParser {
// buffer: &'a [u8] // buffer: &'a [u8]
//} //}
// //
pub struct PsycDictParser<'a> { //pub struct PsycDictParser<'a> {
state: PsycParseDictState, // state: PsycParseDictState,
parsed_key: Option<&'a [u8]>, // parsed_key: Option<&'a [u8]>,
parsed_dict: Vec<(&'a [u8], &'a [u8])>, // cursor: usize
buffer: Option<&'a [u8]>, //}
cursor: usize
}
// //
//// TODO: What data structures does the index parser need? //// TODO: What data structures does the index parser need?
//pub struct PsycIndexParser { //pub struct PsycIndexParser {
@ -112,7 +110,9 @@ pub enum PsycParserResult<'a> {
EntityModifierCont { EntityModifierCont {
value_part: &'a [u8] value_part: &'a [u8]
}, },
EntityModifierEnd, EntityModifierEnd {
value_part: &'a [u8]
},
Body { Body {
name: &'a [u8], name: &'a [u8],
value: &'a [u8] value: &'a [u8]
@ -124,7 +124,9 @@ pub enum PsycParserResult<'a> {
BodyCont { BodyCont {
value_part: &'a [u8] value_part: &'a [u8]
}, },
BodyEnd BodyEnd {
value_part: &'a [u8]
}
} }
//#[derive(Debug, PartialEq)] //#[derive(Debug, PartialEq)]
@ -145,23 +147,25 @@ pub enum PsycParserResult<'a> {
// } // }
//} //}
// //
//#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
//pub enum PsycDictParserResult<'a> { pub enum PsycDictParserResult<'a> {
// Complete, Complete,
// InsufficientData, InsufficientData,
// DictEntry { DictEntry {
// key: &'a [u8], key: &'a [u8],
// value: &'a [u8] value: &'a [u8]
// }, },
// DictEntryStart { DictEntryStart {
// key: &'a [u8], key: &'a [u8],
// value_part: &'a [u8] value_part: &'a [u8]
// }, },
// DictEntryCont { DictEntryCont {
// value_part: &'a [u8] value_part: &'a [u8]
// }, },
// DictEntryEnd DictEntryEnd {
//} value_part: &'a [u8]
}
}
#[repr(C)] #[repr(C)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -279,8 +283,12 @@ impl PsycParser {
Ok(result) Ok(result)
}, },
PsycParseRC::PSYC_PARSE_ENTITY_END => PsycParseRC::PSYC_PARSE_ENTITY_END => {
Ok(PsycParserResult::EntityModifierEnd), let result = PsycParserResult::EntityModifierEnd {
value_part: util::cstring_to_slice(value.data, value.length)
};
Ok(result)
}
PsycParseRC::PSYC_PARSE_BODY => { PsycParseRC::PSYC_PARSE_BODY => {
let result = PsycParserResult::Body { let result = PsycParserResult::Body {
@ -304,8 +312,12 @@ impl PsycParser {
Ok(result) Ok(result)
}, },
PsycParseRC::PSYC_PARSE_BODY_END => PsycParseRC::PSYC_PARSE_BODY_END => {
Ok(PsycParserResult::BodyEnd), let result = PsycParserResult::BodyEnd {
value_part: util::cstring_to_slice(value.data, value.length)
};
Ok(result)
}
_error => Err(mem::transmute(_error)), _error => Err(mem::transmute(_error)),
} }