gdb/
msg.rs

1/*
2 * This file is part of rust-gdb.
3 *
4 * rust-gdb is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * rust-gdb is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rust-gdb.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18use std::str;
19
20#[derive(Debug)]
21pub struct Message {
22    pub token: Option<String>,
23    pub class: MessageClass,
24    pub content: Vec<Variable>,
25}
26
27#[derive(Debug, PartialEq)]
28pub enum MessageClass {
29    Done,
30    Running,
31    Connected,
32    Error,
33    Exit,
34}
35
36#[derive(Debug)]
37pub struct Variable {
38    pub name: VarName,
39    pub value: Value
40}
41
42#[derive(Debug)]
43pub enum Value {
44    String(Constant),
45    VariableList(Vec<Variable>),
46    ValueList(Vec<Value>),
47}
48
49pub type VarName = String;
50pub type Constant = String;
51
52impl str::FromStr for MessageClass {
53    type Err = String;
54    fn from_str(s: &str) -> Result<Self, Self::Err> {
55        match s {
56            "done" => Ok(MessageClass::Done),
57            "running" => Ok(MessageClass::Running),
58            "connected" => Ok(MessageClass::Connected),
59            "error" => Ok(MessageClass::Error),
60            "exit" => Ok(MessageClass::Exit),
61            _ => Err("unrecognized result class".to_string()),
62        }
63    }
64}