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> {
|
pub struct PsycModifier<'a> {
|
||||||
name: &'a str,
|
name: &'a [u8],
|
||||||
value: &'a [u8],
|
value: &'a [u8],
|
||||||
operator: PsycOperator,
|
operator: PsycOperator,
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ pub struct PsycPacket<'a> {
|
||||||
entity_modifiers: &'a [PsycModifier<'a>],
|
entity_modifiers: &'a [PsycModifier<'a>],
|
||||||
raw_routing_modifiers: Vec<RawPsycModifier>,
|
raw_routing_modifiers: Vec<RawPsycModifier>,
|
||||||
raw_entity_modifiers: Vec<RawPsycModifier>,
|
raw_entity_modifiers: Vec<RawPsycModifier>,
|
||||||
method: &'a str,
|
method: &'a [u8],
|
||||||
body: &'a [u8]
|
body: &'a [u8]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,25 +98,25 @@ impl PsycList {
|
||||||
|
|
||||||
impl<'a> PsycModifier<'a> {
|
impl<'a> PsycModifier<'a> {
|
||||||
/// construct a PsycModifier
|
/// 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}
|
PsycModifier {name: name, value: value, operator: operator}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// construct a PsycModifier with string value (comfort function)
|
/// construct a PsycModifier with string value (comfort function)
|
||||||
pub fn with_string_value(operator: PsycOperator,
|
pub fn with_string_value(operator: PsycOperator,
|
||||||
name: &'a str,
|
name: &'a [u8],
|
||||||
value: &'a str)
|
value: &'a [u8])
|
||||||
-> Self {
|
-> Self {
|
||||||
PsycModifier {
|
PsycModifier {
|
||||||
name: name,
|
name: name,
|
||||||
value: value.as_bytes(),
|
value: value,
|
||||||
operator: operator
|
operator: operator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// construct a PsycModifier with list value
|
/// construct a PsycModifier with list value
|
||||||
pub fn with_list_value(operator: PsycOperator,
|
pub fn with_list_value(operator: PsycOperator,
|
||||||
name: &'a str,
|
name: &'a [u8],
|
||||||
value: &'a PsycList)
|
value: &'a PsycList)
|
||||||
-> Self {
|
-> Self {
|
||||||
PsycModifier {
|
PsycModifier {
|
||||||
|
@ -131,7 +131,7 @@ impl<'a> PsycPacket<'a> {
|
||||||
///
|
///
|
||||||
pub fn new(routing_modifiers: &'a [PsycModifier],
|
pub fn new(routing_modifiers: &'a [PsycModifier],
|
||||||
entity_modifiers: &'a [PsycModifier],
|
entity_modifiers: &'a [PsycModifier],
|
||||||
method: &'a str,
|
method: &'a [u8],
|
||||||
data: &'a [u8],
|
data: &'a [u8],
|
||||||
state_operator: PsycStateOp)
|
state_operator: PsycStateOp)
|
||||||
-> Self {
|
-> Self {
|
||||||
|
@ -193,7 +193,7 @@ impl<'a> PsycPacket<'a> {
|
||||||
entity_modifiers: &[],
|
entity_modifiers: &[],
|
||||||
raw_routing_modifiers: raw_routing_modifiers,
|
raw_routing_modifiers: raw_routing_modifiers,
|
||||||
raw_entity_modifiers: vec![],
|
raw_entity_modifiers: vec![],
|
||||||
method: "",
|
method: b"",
|
||||||
body: content
|
body: content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,10 +227,10 @@ impl<'a> PsycPacket<'a> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let context = self.routing_modifiers.iter().find(|&r| r.name == "_context");
|
let context = self.routing_modifiers.iter().find(|&r| r.name == b"_context");
|
||||||
let source = self.routing_modifiers.iter().find(|&r| r.name == "_source");
|
let source = self.routing_modifiers.iter().find(|&r| r.name == b"_source");
|
||||||
let target = self.routing_modifiers.iter().find(|&r| r.name == "_target");
|
let target = self.routing_modifiers.iter().find(|&r| r.name == b"_target");
|
||||||
let counter = self.routing_modifiers.iter().find(|&r| r.name == "_counter");
|
let counter = self.routing_modifiers.iter().find(|&r| r.name == b"_counter");
|
||||||
|
|
||||||
PacketId {
|
PacketId {
|
||||||
context: get_value(context),
|
context: get_value(context),
|
||||||
|
|
|
@ -5,16 +5,16 @@ use psyc::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_render() {
|
fn test_create_render() {
|
||||||
let r1 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
let r1 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||||
"_target",
|
b"_target",
|
||||||
"psyc://ve.symlynx.com/@blog".as_bytes());
|
b"psyc://ve.symlynx.com/@blog");
|
||||||
|
|
||||||
let r2 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
let r2 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||||
"_tag",
|
b"_tag",
|
||||||
"666666".as_bytes());
|
b"666666");
|
||||||
|
|
||||||
let e1 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
let e1 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||||
"_nick",
|
b"_nick",
|
||||||
"lurchi".as_bytes());
|
b"lurchi");
|
||||||
|
|
||||||
let routing_modifiers = vec![r1, r2];
|
let routing_modifiers = vec![r1, r2];
|
||||||
let entity_modifiers = vec![e1];
|
let entity_modifiers = vec![e1];
|
||||||
|
@ -22,7 +22,7 @@ fn test_create_render() {
|
||||||
|
|
||||||
let packet = PsycPacket::new(&routing_modifiers,
|
let packet = PsycPacket::new(&routing_modifiers,
|
||||||
&entity_modifiers,
|
&entity_modifiers,
|
||||||
"_request_context_enter",
|
b"_request_context_enter",
|
||||||
&data,
|
&data,
|
||||||
PsycStateOp::PSYC_STATE_NOOP);
|
PsycStateOp::PSYC_STATE_NOOP);
|
||||||
|
|
||||||
|
@ -36,13 +36,13 @@ fn test_create_render() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_list() {
|
fn test_list() {
|
||||||
let r1 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
let r1 = PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||||
"_target",
|
b"_target",
|
||||||
"psyc://ve.symlynx.com/@blog".as_bytes());
|
b"psyc://ve.symlynx.com/@blog");
|
||||||
|
|
||||||
let list = PsycList::from_strings(&["str1", "str2", "str3"]);
|
let list = PsycList::from_strings(&["str1", "str2", "str3"]);
|
||||||
|
|
||||||
let e1 = PsycModifier::with_list_value(PsycOperator::PSYC_OPERATOR_SET,
|
let e1 = PsycModifier::with_list_value(PsycOperator::PSYC_OPERATOR_SET,
|
||||||
"_list_test",
|
b"_list_test",
|
||||||
&list);
|
&list);
|
||||||
|
|
||||||
let routing_modifiers = vec![r1];
|
let routing_modifiers = vec![r1];
|
||||||
|
@ -51,7 +51,7 @@ fn test_list() {
|
||||||
|
|
||||||
let packet = PsycPacket::new(&routing_modifiers,
|
let packet = PsycPacket::new(&routing_modifiers,
|
||||||
&entity_modifiers,
|
&entity_modifiers,
|
||||||
"",
|
b"",
|
||||||
&data,
|
&data,
|
||||||
PsycStateOp::PSYC_STATE_NOOP);
|
PsycStateOp::PSYC_STATE_NOOP);
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,13 @@ use psyc::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_packet_id() {
|
fn test_packet_id() {
|
||||||
let routing_modifiers = vec![PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
let routing_modifiers = vec![PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||||
"_source",
|
b"_source",
|
||||||
b"psyc://ve.symlynx.com/~alice"),
|
b"psyc://ve.symlynx.com/~alice"),
|
||||||
PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||||
"_target",
|
b"_target",
|
||||||
b"psyc://ve.symlynx.com/~bob"),
|
b"psyc://ve.symlynx.com/~bob"),
|
||||||
PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
PsycModifier::new(PsycOperator::PSYC_OPERATOR_SET,
|
||||||
"_counter",
|
b"_counter",
|
||||||
b"42")];
|
b"42")];
|
||||||
|
|
||||||
let entity_modifiers = vec![];
|
let entity_modifiers = vec![];
|
||||||
|
@ -20,7 +20,7 @@ fn test_packet_id() {
|
||||||
|
|
||||||
let packet = PsycPacket::new(&routing_modifiers,
|
let packet = PsycPacket::new(&routing_modifiers,
|
||||||
&entity_modifiers,
|
&entity_modifiers,
|
||||||
"",
|
b"",
|
||||||
&data,
|
&data,
|
||||||
PsycStateOp::PSYC_STATE_NOOP);
|
PsycStateOp::PSYC_STATE_NOOP);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue