mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
switch modifier names and PSYC methods from str to [u8]
This commit is contained in:
parent
6bdcd1273b
commit
4d0d0bb9b6
3 changed files with 28 additions and 28 deletions
|
@ -55,7 +55,7 @@ pub struct PsycList {
|
|||
}
|
||||
|
||||
pub struct PsycModifier<'a> {
|
||||
name: &'a str,
|
||||
name: &'a [u8],
|
||||
value: &'a [u8],
|
||||
operator: PsycOperator,
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ pub struct PsycPacket<'a> {
|
|||
entity_modifiers: &'a [PsycModifier<'a>],
|
||||
raw_routing_modifiers: Vec<RawPsycModifier>,
|
||||
raw_entity_modifiers: Vec<RawPsycModifier>,
|
||||
method: &'a str,
|
||||
method: &'a [u8],
|
||||
body: &'a [u8]
|
||||
}
|
||||
|
||||
|
@ -98,25 +98,25 @@ impl PsycList {
|
|||
|
||||
impl<'a> PsycModifier<'a> {
|
||||
/// construct a PsycModifier
|
||||
pub fn new(operator: PsycOperator, name: &'a str, value: &'a [u8]) -> Self {
|
||||
pub fn new(operator: PsycOperator, name: &'a [u8], value: &'a [u8]) -> Self {
|
||||
PsycModifier {name: name, value: value, operator: operator}
|
||||
}
|
||||
|
||||
/// construct a PsycModifier with string value (comfort function)
|
||||
pub fn with_string_value(operator: PsycOperator,
|
||||
name: &'a str,
|
||||
value: &'a str)
|
||||
name: &'a [u8],
|
||||
value: &'a [u8])
|
||||
-> Self {
|
||||
PsycModifier {
|
||||
name: name,
|
||||
value: value.as_bytes(),
|
||||
value: value,
|
||||
operator: operator
|
||||
}
|
||||
}
|
||||
|
||||
/// construct a PsycModifier with list value
|
||||
pub fn with_list_value(operator: PsycOperator,
|
||||
name: &'a str,
|
||||
name: &'a [u8],
|
||||
value: &'a PsycList)
|
||||
-> Self {
|
||||
PsycModifier {
|
||||
|
@ -131,7 +131,7 @@ impl<'a> PsycPacket<'a> {
|
|||
///
|
||||
pub fn new(routing_modifiers: &'a [PsycModifier],
|
||||
entity_modifiers: &'a [PsycModifier],
|
||||
method: &'a str,
|
||||
method: &'a [u8],
|
||||
data: &'a [u8],
|
||||
state_operator: PsycStateOp)
|
||||
-> Self {
|
||||
|
@ -193,7 +193,7 @@ impl<'a> PsycPacket<'a> {
|
|||
entity_modifiers: &[],
|
||||
raw_routing_modifiers: raw_routing_modifiers,
|
||||
raw_entity_modifiers: vec![],
|
||||
method: "",
|
||||
method: b"",
|
||||
body: content
|
||||
}
|
||||
}
|
||||
|
@ -227,10 +227,10 @@ impl<'a> PsycPacket<'a> {
|
|||
}
|
||||
};
|
||||
|
||||
let context = self.routing_modifiers.iter().find(|&r| r.name == "_context");
|
||||
let source = self.routing_modifiers.iter().find(|&r| r.name == "_source");
|
||||
let target = self.routing_modifiers.iter().find(|&r| r.name == "_target");
|
||||
let counter = self.routing_modifiers.iter().find(|&r| r.name == "_counter");
|
||||
let context = self.routing_modifiers.iter().find(|&r| r.name == b"_context");
|
||||
let source = self.routing_modifiers.iter().find(|&r| r.name == b"_source");
|
||||
let target = self.routing_modifiers.iter().find(|&r| r.name == b"_target");
|
||||
let counter = self.routing_modifiers.iter().find(|&r| r.name == b"_counter");
|
||||
|
||||
PacketId {
|
||||
context: get_value(context),
|
||||
|
|
|
@ -5,16 +5,16 @@ use psyc::*;
|
|||
#[test]
|
||||
fn test_create_render() {
|
||||
let r1 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||
"_target",
|
||||
"psyc://ve.symlynx.com/@blog".as_bytes());
|
||||
b"_target",
|
||||
b"psyc://ve.symlynx.com/@blog");
|
||||
|
||||
let r2 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||
"_tag",
|
||||
"666666".as_bytes());
|
||||
b"_tag",
|
||||
b"666666");
|
||||
|
||||
let e1 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||
"_nick",
|
||||
"lurchi".as_bytes());
|
||||
b"_nick",
|
||||
b"lurchi");
|
||||
|
||||
let routing_modifiers = vec![r1, r2];
|
||||
let entity_modifiers = vec![e1];
|
||||
|
@ -22,7 +22,7 @@ fn test_create_render() {
|
|||
|
||||
let packet = PsycPacket::new(&routing_modifiers,
|
||||
&entity_modifiers,
|
||||
"_request_context_enter",
|
||||
b"_request_context_enter",
|
||||
&data,
|
||||
PsycStateOp::PSYC_STATE_NOOP);
|
||||
|
||||
|
@ -36,13 +36,13 @@ fn test_create_render() {
|
|||
#[test]
|
||||
fn test_list() {
|
||||
let r1 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||
"_target",
|
||||
"psyc://ve.symlynx.com/@blog".as_bytes());
|
||||
b"_target",
|
||||
b"psyc://ve.symlynx.com/@blog");
|
||||
|
||||
let list = PsycList::from_strings(&["str1", "str2", "str3"]);
|
||||
|
||||
let e1 = PsycModifier::with_list_value(PsycOperator::PSYC_OPERATOR_SET,
|
||||
"_list_test",
|
||||
b"_list_test",
|
||||
&list);
|
||||
|
||||
let routing_modifiers = vec![r1];
|
||||
|
@ -51,7 +51,7 @@ fn test_list() {
|
|||
|
||||
let packet = PsycPacket::new(&routing_modifiers,
|
||||
&entity_modifiers,
|
||||
"",
|
||||
b"",
|
||||
&data,
|
||||
PsycStateOp::PSYC_STATE_NOOP);
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@ use psyc::*;
|
|||
#[test]
|
||||
fn test_packet_id() {
|
||||
let routing_modifiers = vec![PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||
"_source",
|
||||
b"_source",
|
||||
b"psyc://ve.symlynx.com/~alice"),
|
||||
PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||
"_target",
|
||||
b"_target",
|
||||
b"psyc://ve.symlynx.com/~bob"),
|
||||
PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||
"_counter",
|
||||
b"_counter",
|
||||
b"42")];
|
||||
|
||||
let entity_modifiers = vec![];
|
||||
|
@ -20,7 +20,7 @@ fn test_packet_id() {
|
|||
|
||||
let packet = PsycPacket::new(&routing_modifiers,
|
||||
&entity_modifiers,
|
||||
"",
|
||||
b"",
|
||||
&data,
|
||||
PsycStateOp::PSYC_STATE_NOOP);
|
||||
|
||||
|
|
Loading…
Reference in a new issue