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