|
@@ -1,8 +1,9 @@
|
|
|
use binrw::{BinRead, BinWrite};
|
|
|
|
|
|
use crate::{
|
|
|
+ array_of::ArrayOf,
|
|
|
field_of::FieldOf,
|
|
|
- types::{Field, ObjectType, Point, WString, F64, U32, U16},
|
|
|
+ types::{Field, ObjectType, Point, WString, F64, U16, U32},
|
|
|
};
|
|
|
|
|
|
#[derive(BinRead, BinWrite, Debug)]
|
|
@@ -10,17 +11,9 @@ pub enum LineType {
|
|
|
#[brw(magic = 0x0001u64)]
|
|
|
Point(Point),
|
|
|
#[brw(magic = 0x0100u64)]
|
|
|
- Line {
|
|
|
- count: u32,
|
|
|
- #[br(count = count)]
|
|
|
- points: Vec<Point>,
|
|
|
- },
|
|
|
+ Line { points: ArrayOf<Point> },
|
|
|
#[brw(magic = 0x0300u64)]
|
|
|
- Bezier {
|
|
|
- count: u32,
|
|
|
- #[br(count = count)]
|
|
|
- points: Vec<Point>,
|
|
|
- },
|
|
|
+ Bezier { points: ArrayOf<Point> },
|
|
|
}
|
|
|
|
|
|
#[derive(BinRead, BinWrite, Debug)]
|
|
@@ -44,16 +37,13 @@ pub struct ObjBase {
|
|
|
#[derive(BinRead, BinWrite, Debug)]
|
|
|
pub struct Lines {
|
|
|
pub base: ObjBase,
|
|
|
- count: u64,
|
|
|
- #[br(count = count)]
|
|
|
- pub lines: Vec<LineType>,
|
|
|
+ pub lines: ArrayOf<LineType>,
|
|
|
}
|
|
|
|
|
|
#[derive(BinRead, BinWrite, Debug)]
|
|
|
pub struct Rectangle {
|
|
|
pub base: ObjBase,
|
|
|
- #[br(assert(field_count == 8))]
|
|
|
- field_count: u32,
|
|
|
+ #[brw(magic(8u32))] // Number of following fields in struct
|
|
|
pub corner_a: FieldOf<Point>,
|
|
|
pub corner_b: FieldOf<Point>,
|
|
|
pub round_bottom_left: F64,
|
|
@@ -66,8 +56,7 @@ pub struct Rectangle {
|
|
|
#[derive(BinRead, BinWrite, Debug)]
|
|
|
pub struct Circle {
|
|
|
pub base: ObjBase,
|
|
|
- #[br(assert(field_count == 6))]
|
|
|
- field_count: u32,
|
|
|
+ #[brw(magic(6u32))] // Number of following fields in struct
|
|
|
pub origin: FieldOf<Point>,
|
|
|
pub radius: F64,
|
|
|
pub start_angle: F64,
|
|
@@ -78,8 +67,7 @@ pub struct Circle {
|
|
|
#[derive(BinRead, BinWrite, Debug)]
|
|
|
pub struct Ellipse {
|
|
|
pub base: ObjBase,
|
|
|
- #[br(assert(field_count == 8))]
|
|
|
- field_count: u32,
|
|
|
+ #[brw(magic(8u32))] // Number of following fields in struct
|
|
|
pub clockwise: U32,
|
|
|
pub corner_a: FieldOf<Point>,
|
|
|
pub corner_b: FieldOf<Point>,
|
|
@@ -92,8 +80,7 @@ pub struct Ellipse {
|
|
|
#[derive(BinRead, BinWrite, Debug)]
|
|
|
pub struct Polygon {
|
|
|
pub base: ObjBase,
|
|
|
- #[br(assert(field_count == 10))]
|
|
|
- field_count: u32,
|
|
|
+ #[brw(magic(10u32))] // Number of following fields in struct
|
|
|
pub invert_shape: U32,
|
|
|
pub corner_a: FieldOf<Point>,
|
|
|
pub corner_b: FieldOf<Point>,
|
|
@@ -119,4 +106,6 @@ pub enum Object {
|
|
|
Ellipse(Ellipse),
|
|
|
#[brw(magic = 6u32)]
|
|
|
Polygon(Polygon),
|
|
|
+ // #[brw(magic = 32u32)]
|
|
|
+ // Hatch(Hatch),
|
|
|
}
|