basic_field.rs 846 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #![allow(dead_code)]
  2. use binrw::{BinRead, BinWrite};
  3. use crate::{array_of::ArrayOf, field_of::FieldOf};
  4. /// Generic field with structure of length + data
  5. pub type Field = ArrayOf<u8>;
  6. pub type U32 = FieldOf<u32>;
  7. pub type U16 = FieldOf<u16>;
  8. pub type Double = FieldOf<f64>;
  9. pub type Color = FieldOf<Rgba>;
  10. pub type WString = ArrayOf<u16>;
  11. impl From<&WString> for String {
  12. fn from(value: &WString) -> Self {
  13. String::from_utf16_lossy(value)
  14. }
  15. }
  16. impl From<String> for WString {
  17. fn from(value: String) -> Self {
  18. let value: Vec<u16> = value.encode_utf16().collect();
  19. Self { value }
  20. }
  21. }
  22. #[derive(BinRead, BinWrite, PartialEq, Debug)]
  23. pub struct Rgba {
  24. red: u8,
  25. green: u8,
  26. blue: u8,
  27. alpha: u8,
  28. }
  29. #[derive(BinRead, BinWrite, PartialEq, Debug)]
  30. pub struct Point {
  31. x: f64,
  32. y: f64,
  33. }