modified: src/lib.rs
modified: src/xml.rs
This commit is contained in:
parent
58b462f5c2
commit
272a9d3cb3
15
src/lib.rs
15
src/lib.rs
@ -222,7 +222,7 @@ enum ChunkState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_bytes(data: &[u8]) -> XDatabase {
|
pub fn parse_bytes(data: &[u8]) -> XDatabase {
|
||||||
let mut xdb = XDatabase{data: None, children: Vec::new()};
|
let mut xdb = XDatabase{data: None, header: None, children: Vec::new()};
|
||||||
let mut state = ChunkState::Header;
|
let mut state = ChunkState::Header;
|
||||||
let mut chunk_header: Option<ChunkHeader> = None;
|
let mut chunk_header: Option<ChunkHeader> = None;
|
||||||
let mut last_type: u32 = 0;
|
let mut last_type: u32 = 0;
|
||||||
@ -250,7 +250,7 @@ pub fn parse_bytes(data: &[u8]) -> XDatabase {
|
|||||||
u = usize::try_from(header.end_of_chunk).unwrap() - 12;
|
u = usize::try_from(header.end_of_chunk).unwrap() - 12;
|
||||||
let ds: DataSet = bincode::deserialize(&data[i..i+u]).unwrap();
|
let ds: DataSet = bincode::deserialize(&data[i..i+u]).unwrap();
|
||||||
info!("val: {:?}", ds);
|
info!("val: {:?}", ds);
|
||||||
xdb.children.push(XDataSet { data: ds.clone(), child: match ds.data_type {
|
xdb.children.push(XDataSet { header: header, data: ds.clone(), child: match ds.data_type {
|
||||||
3 => XSomeList::Playlists(Vec::new()), // Playlist List
|
3 => XSomeList::Playlists(Vec::new()), // Playlist List
|
||||||
4 => XSomeList::AlbumList(Vec::new()), // Album List
|
4 => XSomeList::AlbumList(Vec::new()), // Album List
|
||||||
_ => XSomeList::TrackList(Vec::new()) // 1 Track List
|
_ => XSomeList::TrackList(Vec::new()) // 1 Track List
|
||||||
@ -266,7 +266,7 @@ pub fn parse_bytes(data: &[u8]) -> XDatabase {
|
|||||||
let ai: AlbumItem = bincode::deserialize(&data[i..i+u]).unwrap();
|
let ai: AlbumItem = bincode::deserialize(&data[i..i+u]).unwrap();
|
||||||
info!("val: {:?}", ai);
|
info!("val: {:?}", ai);
|
||||||
if let XSomeList::AlbumList(albums) = &mut xdb.find_dataset(4).child {
|
if let XSomeList::AlbumList(albums) = &mut xdb.find_dataset(4).child {
|
||||||
albums.push(XAlbumItem {data: ai,args: Vec::new()});
|
albums.push(XAlbumItem {header: header, data: ai,args: Vec::new()});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ChunkType::TrackList => {
|
ChunkType::TrackList => {
|
||||||
@ -279,7 +279,7 @@ pub fn parse_bytes(data: &[u8]) -> XDatabase {
|
|||||||
let ti: TrackItem = bincode::deserialize(&data[i..i+u]).unwrap();
|
let ti: TrackItem = bincode::deserialize(&data[i..i+u]).unwrap();
|
||||||
info!("val: {:?}", ti);
|
info!("val: {:?}", ti);
|
||||||
if let XSomeList::TrackList(tracks) = &mut xdb.find_dataset(1).child {
|
if let XSomeList::TrackList(tracks) = &mut xdb.find_dataset(1).child {
|
||||||
tracks.push(XTrackItem {data: ti,args: Vec::new()});
|
tracks.push(XTrackItem {header: header, data: ti,args: Vec::new()});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ChunkType::StringTypes => {
|
ChunkType::StringTypes => {
|
||||||
@ -355,7 +355,7 @@ pub fn parse_bytes(data: &[u8]) -> XDatabase {
|
|||||||
let playlist: Playlist = bincode::deserialize(&data[i..i+u]).unwrap();
|
let playlist: Playlist = bincode::deserialize(&data[i..i+u]).unwrap();
|
||||||
info!("playlist: {:?}", playlist);
|
info!("playlist: {:?}", playlist);
|
||||||
if let XSomeList::Playlists(playlists) = &mut xdb.find_dataset(3).child {
|
if let XSomeList::Playlists(playlists) = &mut xdb.find_dataset(3).child {
|
||||||
playlists.push(XPlaylist {data: playlist,args: Vec::new()});
|
playlists.push(XPlaylist {header: header, data: playlist,args: Vec::new()});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => { u = 1; }
|
_ => { u = 1; }
|
||||||
@ -399,14 +399,17 @@ fn x_args_to_bytes(args: &Vec<XArgument>) -> Vec<u8> {
|
|||||||
|
|
||||||
fn to_bytes(xdb: XDatabase) -> Vec<u8> {
|
fn to_bytes(xdb: XDatabase) -> Vec<u8> {
|
||||||
let mut bytes: Vec<u8> = Vec::new();
|
let mut bytes: Vec<u8> = Vec::new();
|
||||||
|
bytes = [bytes, bincode::serialize(&xdb.header.unwrap()).unwrap()].concat();
|
||||||
bytes = [bytes, bincode::serialize(&xdb.data.unwrap()).unwrap()].concat();
|
bytes = [bytes, bincode::serialize(&xdb.data.unwrap()).unwrap()].concat();
|
||||||
for i in 0..xdb.children.len() {
|
for i in 0..xdb.children.len() {
|
||||||
let data_set = xdb.children.get(i).unwrap();
|
let data_set = xdb.children.get(i).unwrap();
|
||||||
|
bytes = [bytes, bincode::serialize(&data_set.header).unwrap()].concat();
|
||||||
bytes = [bytes, bincode::serialize(&data_set.data).unwrap()].concat();
|
bytes = [bytes, bincode::serialize(&data_set.data).unwrap()].concat();
|
||||||
match &data_set.child {
|
match &data_set.child {
|
||||||
XSomeList::Playlists(playlists) => {
|
XSomeList::Playlists(playlists) => {
|
||||||
for u in 0..playlists.len() {
|
for u in 0..playlists.len() {
|
||||||
let playlist = playlists.get(u).unwrap();
|
let playlist = playlists.get(u).unwrap();
|
||||||
|
bytes = [bytes, bincode::serialize(&playlist.header).unwrap()].concat();
|
||||||
bytes = [bytes, bincode::serialize(&playlist.data).unwrap()].concat();
|
bytes = [bytes, bincode::serialize(&playlist.data).unwrap()].concat();
|
||||||
bytes = [bytes, x_args_to_bytes(&playlist.args)].concat();
|
bytes = [bytes, x_args_to_bytes(&playlist.args)].concat();
|
||||||
}
|
}
|
||||||
@ -414,6 +417,7 @@ fn to_bytes(xdb: XDatabase) -> Vec<u8> {
|
|||||||
XSomeList::AlbumList(albums) => {
|
XSomeList::AlbumList(albums) => {
|
||||||
for u in 0..albums.len() {
|
for u in 0..albums.len() {
|
||||||
let album = albums.get(u).unwrap();
|
let album = albums.get(u).unwrap();
|
||||||
|
bytes = [bytes, bincode::serialize(&album.header).unwrap()].concat();
|
||||||
bytes = [bytes, bincode::serialize(&album.data).unwrap()].concat();
|
bytes = [bytes, bincode::serialize(&album.data).unwrap()].concat();
|
||||||
bytes = [bytes, x_args_to_bytes(&album.args)].concat();
|
bytes = [bytes, x_args_to_bytes(&album.args)].concat();
|
||||||
}
|
}
|
||||||
@ -421,6 +425,7 @@ fn to_bytes(xdb: XDatabase) -> Vec<u8> {
|
|||||||
XSomeList::TrackList(tracks) => {
|
XSomeList::TrackList(tracks) => {
|
||||||
for u in 0..tracks.len() {
|
for u in 0..tracks.len() {
|
||||||
let track = tracks.get(u).unwrap();
|
let track = tracks.get(u).unwrap();
|
||||||
|
bytes = [bytes, bincode::serialize(&track.header).unwrap()].concat();
|
||||||
bytes = [bytes, bincode::serialize(&track.data).unwrap()].concat();
|
bytes = [bytes, bincode::serialize(&track.data).unwrap()].concat();
|
||||||
bytes = [bytes, x_args_to_bytes(&track.args)].concat();
|
bytes = [bytes, x_args_to_bytes(&track.args)].concat();
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,35 @@
|
|||||||
|
|
||||||
#[derive(Debug, serde::Serialize)]
|
#[derive(Debug, serde::Serialize)]
|
||||||
pub struct XDatabase {
|
pub struct XDatabase {
|
||||||
|
pub header: Option<crate::ChunkHeader>,
|
||||||
pub data: Option<crate::Database>,
|
pub data: Option<crate::Database>,
|
||||||
pub children: Vec<XDataSet>
|
pub children: Vec<XDataSet>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Serialize)]
|
#[derive(Debug, serde::Serialize)]
|
||||||
pub struct XDataSet {
|
pub struct XDataSet {
|
||||||
|
pub header: crate::ChunkHeader,
|
||||||
pub data: crate::DataSet,
|
pub data: crate::DataSet,
|
||||||
pub child: XSomeList
|
pub child: XSomeList
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Serialize)]
|
#[derive(Debug, serde::Serialize)]
|
||||||
pub struct XTrackItem {
|
pub struct XTrackItem {
|
||||||
|
pub header: crate::ChunkHeader,
|
||||||
pub data: crate::TrackItem,
|
pub data: crate::TrackItem,
|
||||||
pub args: Vec<XArgument>
|
pub args: Vec<XArgument>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Serialize)]
|
#[derive(Debug, serde::Serialize)]
|
||||||
pub struct XAlbumItem {
|
pub struct XAlbumItem {
|
||||||
|
pub header: crate::ChunkHeader,
|
||||||
pub data: crate::AlbumItem,
|
pub data: crate::AlbumItem,
|
||||||
pub args: Vec<XArgument>
|
pub args: Vec<XArgument>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Serialize)]
|
#[derive(Debug, serde::Serialize)]
|
||||||
pub struct XPlaylist {
|
pub struct XPlaylist {
|
||||||
|
pub header: crate::ChunkHeader,
|
||||||
pub data: crate::Playlist,
|
pub data: crate::Playlist,
|
||||||
pub args: Vec<XArgument>
|
pub args: Vec<XArgument>
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user