pub enum BdecodeNode {
Dict(Dict),
List(List),
Str(Str),
Int(Int),
End(End),
}Expand description
用于存放解析后的数据
Variants§
Implementations§
Source§impl BdecodeNode
impl BdecodeNode
pub fn new( token_idx: u32, tokens: Arc<Vec<BdecodeToken>>, buffer: Arc<Vec<u8>>, ) -> BdecodeNode
pub fn as_int(&self) -> Result<i64, BdecodeError>
pub fn as_str(&self) -> Cow<'_, [u8]>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Examples found in repository?
examples/decode.rs (line 12)
3fn main() {
4 let buf = "d 2:k1 2:v1 2:k2 l i1e i2e e 3:k03 i3e 2:k4 d 2:k5 i5e 2:k6 i6e e e".replace(" ", "");
5
6 let root_node = BdecodeNode::parse_buffer(buf.into()).unwrap();
7 println!("{}", root_node.to_json());
8
9 let k2_node = root_node.dict_find(b"k2").unwrap();
10 println!("{}", k2_node.to_json());
11
12 for i in 0..k2_node.len() {
13 let val = k2_node.list_item_as_int(i).unwrap();
14 println!("item_{} = {}", i, val)
15 }
16}pub fn list_item(&self, index: usize) -> BdecodeNode
Sourcepub fn list_item_as_int(&self, index: usize) -> Result<i64, BdecodeError>
pub fn list_item_as_int(&self, index: usize) -> Result<i64, BdecodeError>
Examples found in repository?
examples/decode.rs (line 13)
3fn main() {
4 let buf = "d 2:k1 2:v1 2:k2 l i1e i2e e 3:k03 i3e 2:k4 d 2:k5 i5e 2:k6 i6e e e".replace(" ", "");
5
6 let root_node = BdecodeNode::parse_buffer(buf.into()).unwrap();
7 println!("{}", root_node.to_json());
8
9 let k2_node = root_node.dict_find(b"k2").unwrap();
10 println!("{}", k2_node.to_json());
11
12 for i in 0..k2_node.len() {
13 let val = k2_node.list_item_as_int(i).unwrap();
14 println!("item_{} = {}", i, val)
15 }
16}pub fn list_item_as_str(&self, index: usize) -> Cow<'_, [u8]>
pub fn dict_item(&self, index: usize) -> (BdecodeNode, BdecodeNode)
Sourcepub fn dict_find(&self, key: &[u8]) -> Option<BdecodeNode>
pub fn dict_find(&self, key: &[u8]) -> Option<BdecodeNode>
Examples found in repository?
examples/decode.rs (line 9)
3fn main() {
4 let buf = "d 2:k1 2:v1 2:k2 l i1e i2e e 3:k03 i3e 2:k4 d 2:k5 i5e 2:k6 i6e e e".replace(" ", "");
5
6 let root_node = BdecodeNode::parse_buffer(buf.into()).unwrap();
7 println!("{}", root_node.to_json());
8
9 let k2_node = root_node.dict_find(b"k2").unwrap();
10 println!("{}", k2_node.to_json());
11
12 for i in 0..k2_node.len() {
13 let val = k2_node.list_item_as_int(i).unwrap();
14 println!("item_{} = {}", i, val)
15 }
16}pub fn dict_find_as_str(&self, key: &[u8]) -> Option<Cow<'_, [u8]>>
pub fn dict_find_as_int(&self, key: &[u8]) -> Option<i64>
pub fn dict_find_as_list(&self, key: &[u8]) -> Option<Vec<BdecodeNode>>
pub fn dict_find_as_dict( &self, key: &[u8], ) -> Option<HashMap<Cow<'_, [u8]>, BdecodeNode>>
pub fn parse( buffer: Vec<u8>, depth_limit: Option<usize>, token_limit: Option<i32>, ) -> Result<Self, BdecodeError>
Sourcepub fn parse_buffer(buffer: Vec<u8>) -> Result<Self, BdecodeError>
pub fn parse_buffer(buffer: Vec<u8>) -> Result<Self, BdecodeError>
Examples found in repository?
examples/decode.rs (line 6)
3fn main() {
4 let buf = "d 2:k1 2:v1 2:k2 l i1e i2e e 3:k03 i3e 2:k4 d 2:k5 i5e 2:k6 i6e e e".replace(" ", "");
5
6 let root_node = BdecodeNode::parse_buffer(buf.into()).unwrap();
7 println!("{}", root_node.to_json());
8
9 let k2_node = root_node.dict_find(b"k2").unwrap();
10 println!("{}", k2_node.to_json());
11
12 for i in 0..k2_node.len() {
13 let val = k2_node.list_item_as_int(i).unwrap();
14 println!("item_{} = {}", i, val)
15 }
16}Sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
Examples found in repository?
examples/decode.rs (line 7)
3fn main() {
4 let buf = "d 2:k1 2:v1 2:k2 l i1e i2e e 3:k03 i3e 2:k4 d 2:k5 i5e 2:k6 i6e e e".replace(" ", "");
5
6 let root_node = BdecodeNode::parse_buffer(buf.into()).unwrap();
7 println!("{}", root_node.to_json());
8
9 let k2_node = root_node.dict_find(b"k2").unwrap();
10 println!("{}", k2_node.to_json());
11
12 for i in 0..k2_node.len() {
13 let val = k2_node.list_item_as_int(i).unwrap();
14 println!("item_{} = {}", i, val)
15 }
16}Trait Implementations§
Source§impl Clone for BdecodeNode
impl Clone for BdecodeNode
Source§fn clone(&self) -> BdecodeNode
fn clone(&self) -> BdecodeNode
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for BdecodeNode
impl RefUnwindSafe for BdecodeNode
impl Send for BdecodeNode
impl Sync for BdecodeNode
impl Unpin for BdecodeNode
impl UnwindSafe for BdecodeNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more