header.rs 706 B

12345678910111213141516171819202122232425262728293031
  1. #[derive(Clone, Copy, Debug)]
  2. #[repr(C)]
  3. pub struct Tag {
  4. pub typ: u32,
  5. pub size: u32,
  6. // tag specific fields
  7. }
  8. #[derive(Clone, Debug)]
  9. pub struct TagIter {
  10. pub current: *const Tag,
  11. }
  12. impl Iterator for TagIter {
  13. type Item = &'static Tag;
  14. fn next(&mut self) -> Option<&'static Tag> {
  15. match unsafe{&*self.current} {
  16. &Tag{typ:0, size:8} => None, // end tag
  17. tag => {
  18. // go to next tag
  19. let mut tag_addr = self.current as usize;
  20. tag_addr += ((tag.size + 7) & !7) as usize; //align at 8 byte
  21. self.current = tag_addr as *const _;
  22. Some(tag)
  23. },
  24. }
  25. }
  26. }