pub struct BufferedReader<'a> { /* private fields */ }Implementations§
Source§impl<'a> BufferedReader<'a>
impl<'a> BufferedReader<'a>
Sourcepub fn new(data: &'a [u8]) -> Self
pub fn new(data: &'a [u8]) -> Self
Examples found in repository?
More examples
examples/instructions.rs (line 9)
7fn main() {
8 let input = include_bytes!("./testdata/org/example/Simple.class");
9 let mut buffer = BufferedReader::new(input);
10 let mut constant_pool = ConstantPool::new();
11 let cf = read_classfile(&mut buffer, &mut constant_pool).unwrap();
12
13 println!("Class: {}", constant_pool.text_of(cf.this_class).unwrap());
14 // print all methods and their instructions
15 cf.methods.iter().for_each(|method| {
16 let attr = method
17 .attributes
18 .iter()
19 .find(|attr| matches!(attr, Attribute::Code(_)));
20 println!("Name: {}()", method.name);
21
22 let code = if let Attribute::Code(code) = attr.unwrap() {
23 code
24 } else {
25 panic!("Code attribute not found");
26 };
27
28 // create a new buffer that contains just the code and nothing else...
29 let mut code_reader = BufferedReader::new(&code.code);
30 while !code_reader.has_remaining_data() {
31 let opcode = code_reader.take::<u8>().unwrap();
32 let instr =
33 parse_instruction(opcode, &mut code_reader).expect("instruction should be parsed");
34 println!(" 0x{opcode:02x}: {}", instr);
35 }
36 println!();
37 });
38}examples/printelements.rs (line 7)
5fn main() {
6 let input = include_bytes!("./testdata/org/example/Simple.class");
7 let mut buffer = BufferedReader::new(input);
8 let mut cp = ConstantPool::new();
9 let cf = read_classfile(&mut buffer, &mut cp).unwrap();
10
11 println!("Class name: {}", cp.text_of(cf.this_class).unwrap());
12
13 cf.fields.iter().for_each(|field| {
14 println!("Field {} - {}", field.name, field.descriptor);
15 });
16
17 // cf.methods.iter().for_each(|method| {
18 // let parameters: Vec<Descriptor> = method
19 // .descriptor
20 // .clone()
21 // .into_iter()
22 // .filter(|desc| desc.kind == DescriptorKind::Parameter)
23 // .collect();
24 // let return_ty: Descriptor = method
25 // .descriptor
26 // .clone()
27 // .into_iter()
28 // .find(|desc| desc.kind == DescriptorKind::Return)
29 // .unwrap_or(Descriptor {
30 // kind: DescriptorKind::Return,
31 // ty: FieldType::Base(BaseType::Void),
32 // });
33 //
34 // println!(
35 // "{} {}({})",
36 // return_ty,
37 // method.name,
38 // parameters
39 // .iter()
40 // .map(|p| p.ty.to_string())
41 // .collect::<Vec<String>>()
42 // .join(", ")
43 // );
44 // });
45}Sourcepub fn take<T>(&mut self) -> Result<T, BytecodeError>where
T: FromBytes,
pub fn take<T>(&mut self) -> Result<T, BytecodeError>where
T: FromBytes,
Examples found in repository?
examples/instructions.rs (line 31)
7fn main() {
8 let input = include_bytes!("./testdata/org/example/Simple.class");
9 let mut buffer = BufferedReader::new(input);
10 let mut constant_pool = ConstantPool::new();
11 let cf = read_classfile(&mut buffer, &mut constant_pool).unwrap();
12
13 println!("Class: {}", constant_pool.text_of(cf.this_class).unwrap());
14 // print all methods and their instructions
15 cf.methods.iter().for_each(|method| {
16 let attr = method
17 .attributes
18 .iter()
19 .find(|attr| matches!(attr, Attribute::Code(_)));
20 println!("Name: {}()", method.name);
21
22 let code = if let Attribute::Code(code) = attr.unwrap() {
23 code
24 } else {
25 panic!("Code attribute not found");
26 };
27
28 // create a new buffer that contains just the code and nothing else...
29 let mut code_reader = BufferedReader::new(&code.code);
30 while !code_reader.has_remaining_data() {
31 let opcode = code_reader.take::<u8>().unwrap();
32 let instr =
33 parse_instruction(opcode, &mut code_reader).expect("instruction should be parsed");
34 println!(" 0x{opcode:02x}: {}", instr);
35 }
36 println!();
37 });
38}pub fn peek_bytes<T>(&self) -> Result<T, BytecodeError>where
T: FromBytes,
pub fn take_bytes(&mut self, length: usize) -> Result<&'a [u8], BytecodeError>
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns the size of BufferedReader’s data in bytes.
Sourcepub fn position(&self) -> usize
pub fn position(&self) -> usize
Returns the current position of BufferedReader in bytes.
Sourcepub fn has_remaining_data(&self) -> bool
pub fn has_remaining_data(&self) -> bool
Indicates whether the reader has remaining data to be read.
Examples found in repository?
examples/instructions.rs (line 30)
7fn main() {
8 let input = include_bytes!("./testdata/org/example/Simple.class");
9 let mut buffer = BufferedReader::new(input);
10 let mut constant_pool = ConstantPool::new();
11 let cf = read_classfile(&mut buffer, &mut constant_pool).unwrap();
12
13 println!("Class: {}", constant_pool.text_of(cf.this_class).unwrap());
14 // print all methods and their instructions
15 cf.methods.iter().for_each(|method| {
16 let attr = method
17 .attributes
18 .iter()
19 .find(|attr| matches!(attr, Attribute::Code(_)));
20 println!("Name: {}()", method.name);
21
22 let code = if let Attribute::Code(code) = attr.unwrap() {
23 code
24 } else {
25 panic!("Code attribute not found");
26 };
27
28 // create a new buffer that contains just the code and nothing else...
29 let mut code_reader = BufferedReader::new(&code.code);
30 while !code_reader.has_remaining_data() {
31 let opcode = code_reader.take::<u8>().unwrap();
32 let instr =
33 parse_instruction(opcode, &mut code_reader).expect("instruction should be parsed");
34 println!(" 0x{opcode:02x}: {}", instr);
35 }
36 println!();
37 });
38}Trait Implementations§
Source§impl<'a> Clone for BufferedReader<'a>
impl<'a> Clone for BufferedReader<'a>
Source§fn clone(&self) -> BufferedReader<'a>
fn clone(&self) -> BufferedReader<'a>
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<'a> Freeze for BufferedReader<'a>
impl<'a> RefUnwindSafe for BufferedReader<'a>
impl<'a> Send for BufferedReader<'a>
impl<'a> Sync for BufferedReader<'a>
impl<'a> Unpin for BufferedReader<'a>
impl<'a> UnwindSafe for BufferedReader<'a>
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