1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use std::ops::Deref;

// TODO
// Using something instead of `Vec`
#[derive(PartialEq, Clone, Debug)]
pub struct Arguments(pub Vec<Argument>);

impl Deref for Arguments {
    type Target = Vec<Argument>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}



#[derive(PartialEq, Clone, Debug)]
pub enum Argument {
    Octet(u8),
    Short(u16),
    Long(u32),
    LongLong(u64),
    Bits(u8),
    ShortString(ShortString),
    LongString(LongString),
    Timestamp(Timestamp),
    FieldTable(FieldTable),
    FieldArray(FieldArray),
}


#[derive(Eq, PartialEq, Clone, Debug)]
pub struct ShortString(pub String);

impl Deref for ShortString {
    type Target = String;
    fn deref(&self) -> &String {
        &self.0
    }
}


#[derive(Eq, PartialEq, Clone, Debug)]
pub struct LongString(pub String);

impl Deref for LongString {
    type Target = String;
    fn deref(&self) -> &String {
        &self.0
    }
}



#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Timestamp(pub u64);



#[derive(PartialEq, Clone, Debug)]
pub struct FieldTable(pub Vec<(String, FieldArgument)>);

impl Deref for FieldTable {
    type Target = Vec<(String, FieldArgument)>;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}


#[derive(PartialEq, Clone, Debug)]
pub enum FieldArgument {
    Boolean(bool),
    SignedOctet(i8),
    UnsignedOctet(u8),
    SignedShort(i16),
    UnsignedShort(u16),
    SignedLong(i32),
    UnsignedLong(u32),
    SignedLongLong(i64),
    UnsignedLongLong(u64),
    Float(f32),
    Double(f64),
    Decimal(i64), // See https://www.rabbitmq.com/amqp-0-9-1-errata.html. I dont know `scale long-unit`.
    ShortString(ShortString),
    LongString(LongString),
    // Array(), // I can not find any definition of this field.
    Timestamp(u64),
    NestedTable(FieldTable),
    Void,
    ByteArray(Vec<u8>), // How can we treat it
}


#[derive(PartialEq, Clone, Debug)]
pub struct FieldArray(pub Vec<FieldArgument>);

impl Deref for FieldArray {
    type Target = Vec<FieldArgument>;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}



/// `ArgumentSymbol` is used when specify argument type that you decode byte array into
pub enum ArgumentDecodingInfo {
    Octet,
    Short,
    Long,
    LongLong,
    Bits,
    ShortString,
    LongString,
    Timestamp,
    FieldTable,
    FieldArray,
}