Use enum_primitve to match against tag codes
This commit is contained in:
parent
32c3765d81
commit
f4e070feda
|
@ -10,5 +10,7 @@ description = "Read and write the Adobe Flash SWF file format."
|
|||
|
||||
[dependencies]
|
||||
byteorder = "*"
|
||||
enum_primitive = "*"
|
||||
flate2 = "*"
|
||||
num = "*"
|
||||
xz2 = { git = "https://github.com/alexcrichton/xz2-rs", rev = "09ce8db2" }
|
|
@ -8,7 +8,9 @@
|
|||
//! writing SWF data.
|
||||
|
||||
extern crate byteorder;
|
||||
#[macro_use] extern crate enum_primitive;
|
||||
extern crate flate2;
|
||||
extern crate num;
|
||||
extern crate xz2;
|
||||
|
||||
mod read;
|
||||
|
|
17
src/read.rs
17
src/read.rs
|
@ -1,6 +1,6 @@
|
|||
// SWF decoding from streams
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use flate2::read::ZlibDecoder;
|
||||
use num::FromPrimitive;
|
||||
use std::io::{Error, ErrorKind, Read, Result};
|
||||
use types::*;
|
||||
use xz2::read::XzDecoder;
|
||||
|
@ -253,17 +253,16 @@ impl<R: Read> Reader<R> {
|
|||
|
||||
let mut tag_reader = Reader::new(self.input.by_ref().take(length as u64), self.version);
|
||||
use tag_codes::TagCode;
|
||||
let tag = match tag_code {
|
||||
x if x == TagCode::End as u16 => return Ok(None),
|
||||
x if x == TagCode::ShowFrame as u16 => Tag::ShowFrame,
|
||||
x if x == TagCode::DefineShape as u16 => try!(tag_reader.read_define_shape(1)),
|
||||
let tag = match TagCode::from_u16(tag_code) {
|
||||
Some(TagCode::End) => return Ok(None),
|
||||
Some(TagCode::ShowFrame) => Tag::ShowFrame,
|
||||
Some(TagCode::DefineShape) => try!(tag_reader.read_define_shape(1)),
|
||||
|
||||
x if x == TagCode::SetBackgroundColor as u16 => {
|
||||
Some(TagCode::SetBackgroundColor) => {
|
||||
Tag::SetBackgroundColor(try!(tag_reader.read_rgb()))
|
||||
}
|
||||
|
||||
// PLACE_OBJECT_2 => unimplemented!(),
|
||||
x if x == TagCode::FileAttributes as u16 => {
|
||||
Some(TagCode::FileAttributes) => {
|
||||
let flags = try!(tag_reader.read_u32());
|
||||
Tag::FileAttributes(FileAttributes {
|
||||
use_direct_blit: (flags & 0b01000000) != 0,
|
||||
|
@ -274,7 +273,7 @@ impl<R: Read> Reader<R> {
|
|||
})
|
||||
}
|
||||
|
||||
x if x == TagCode::DefineSceneAndFrameLabelData as u16 => {
|
||||
Some(TagCode::DefineSceneAndFrameLabelData) => {
|
||||
try!(tag_reader.read_define_scene_and_frame_label_data())
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
enum_from_primitive! {
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug,PartialEq,Clone)]
|
||||
pub enum TagCode {
|
||||
|
@ -84,3 +85,4 @@ pub enum TagCode {
|
|||
|
||||
EnableTelemetry = 93,
|
||||
}
|
||||
}
|
|
@ -64,6 +64,9 @@ pub fn write_swf<W: Write>(swf: &Swf, mut output: W) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
static write_raw_tags: bool = false;
|
||||
|
||||
struct Writer<W: Write> {
|
||||
pub output: W,
|
||||
pub version: u8,
|
||||
|
|
Loading…
Reference in New Issue