Maraiah/maraiah/map/trmg.rs

108 lines
2.4 KiB
Rust
Raw Normal View History

2019-04-01 02:09:01 -07:00
//! `Group` type.
2019-03-01 01:27:14 -08:00
2019-06-13 18:09:07 -07:00
use crate::err::*;
2019-02-16 09:07:28 -08:00
use bitflags::bitflags;
2019-02-08 21:08:53 -08:00
2019-03-04 20:57:25 -08:00
/// Reads an `InterGroup`.
2019-04-01 02:09:01 -07:00
pub fn read(b: &[u8]) -> ResultS<(InterGroup, usize)>
2019-02-08 21:08:53 -08:00
{
2019-02-18 20:06:34 -08:00
read_data! {
2019-03-18 12:31:14 -07:00
endian: BIG, buf: b, size: 12, start: 0, data {
let flags = u16[0] flag GroupFlags;
let ttype = u16[2];
let pdata = u16[4];
let beg = u16[6] usize;
let len = u16[8] usize;
let lines = u16[10];
}
2019-02-18 20:06:34 -08:00
}
2019-03-04 06:00:03 -08:00
let ttype = match ttype {
0 => GroupType::Logon(pdata),
1 => GroupType::Unfinished,
2 => GroupType::Success,
3 => GroupType::Failure,
4 => GroupType::Info,
5 => GroupType::End,
6 => GroupType::TeleInter(pdata),
7 => GroupType::TeleIntra(pdata),
8 => GroupType::Checkpoint(pdata),
9 => GroupType::Sound(pdata),
10 => GroupType::Movie(pdata),
11 => GroupType::Track(pdata),
12 => GroupType::Pict(pdata),
13 => GroupType::Logoff(pdata),
14 => GroupType::Camera(pdata),
15 => GroupType::Static(pdata),
16 => GroupType::Tag(pdata),
n => return Err(ReprError::new(n).into()),
};
2019-02-08 21:08:53 -08:00
2019-03-04 20:57:25 -08:00
Ok((InterGroup{flags, ttype, lines, beg, len}, 12))
2019-02-08 21:08:53 -08:00
}
2019-03-04 20:57:25 -08:00
impl Default for GroupType
{
fn default() -> Self {GroupType::Unfinished}
}
2019-04-01 02:09:01 -07:00
/// Interim structure.
2019-03-13 07:53:30 -07:00
#[derive(Debug, Eq, PartialEq)]
2019-04-01 02:09:01 -07:00
pub struct InterGroup
2019-02-08 21:08:53 -08:00
{
2019-04-01 02:09:01 -07:00
pub flags: GroupFlags,
pub ttype: GroupType,
pub lines: u16,
pub beg: usize,
pub len: usize,
2019-02-08 21:08:53 -08:00
}
2019-03-01 01:27:14 -08:00
/// A terminal command grouping.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
2019-03-13 07:53:30 -07:00
#[derive(Debug, Eq, PartialEq)]
2019-02-08 21:08:53 -08:00
pub struct Group
{
2019-03-04 04:28:04 -08:00
pub flags: GroupFlags,
pub ttype: GroupType,
pub lines: u16,
pub text: String,
2019-02-08 21:08:53 -08:00
}
2019-03-04 06:00:03 -08:00
/// The command of a `Group`.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
2019-03-13 07:53:30 -07:00
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2019-03-04 06:00:03 -08:00
pub enum GroupType
{
Logon(u16),
Unfinished,
Success,
Failure,
Info,
End,
TeleInter(u16),
TeleIntra(u16),
Checkpoint(u16),
Sound(u16),
Movie(u16),
Track(u16),
Pict(u16),
Logoff(u16),
Camera(u16),
Static(u16),
Tag(u16),
}
2019-02-16 09:07:28 -08:00
bitflags! {
2019-03-01 01:27:14 -08:00
/// Flags for `Group`.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
2019-02-16 09:07:28 -08:00
pub struct GroupFlags: u16
{
2019-03-09 14:03:20 -08:00
/// Draws the picture on the right.
2019-03-07 00:12:00 -08:00
const DRAW_ON_RIGHT = 1;
2019-03-09 14:03:20 -08:00
/// Draws the picture in the center.
2019-03-07 00:12:00 -08:00
const DRAW_CENTER = 1 << 1;
2019-02-16 09:07:28 -08:00
}
}
2019-02-08 21:08:53 -08:00
// EOF