silk_rs/
error.rs

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
use thiserror::Error;

#[derive(Error, Debug)]
pub enum SilkError {
    #[error("Invalid")]
    Invalid,
    #[error("EncInputInvalidNoOfSamples")]
    EncInputInvalidNoOfSamples,
    #[error("EncFsNotSupported")]
    EncFsNotSupported,
    #[error("EncPacketSizeNotSupported")]
    EncPacketSizeNotSupported,
    #[error("EncPayloadBufTooShort")]
    EncPayloadBufTooShort,
    #[error("EncInvalidLossRate")]
    EncInvalidLossRate,
    #[error("EncInvalidComplexitySetting")]
    EncInvalidComplexitySetting,
    #[error("EncInvalidInbandFecSetting")]
    EncInvalidInbandFecSetting,
    #[error("EncInvalidDtxSetting")]
    EncInvalidDtxSetting,
    #[error("EncInternalError")]
    EncInternalError,
    #[error("DecInvalidSamplingFrequency")]
    DecInvalidSamplingFrequency,
    #[error("DecPayloadTooLarge")]
    DecPayloadTooLarge,
    #[error("DecPayloadError")]
    DecPayloadError,
    #[error("OTHER {0}")]
    Other(i32),
}

impl From<i32> for SilkError {
    fn from(code: i32) -> Self {
        match code {
            -1 => Self::EncInputInvalidNoOfSamples,
            -2 => Self::EncFsNotSupported,
            -3 => Self::EncPacketSizeNotSupported,
            -4 => Self::EncPayloadBufTooShort,
            -5 => Self::EncInvalidLossRate,
            -6 => Self::EncInvalidComplexitySetting,
            -7 => Self::EncInvalidInbandFecSetting,
            -8 => Self::EncInvalidDtxSetting,
            -9 => Self::EncInternalError,
            -10 => Self::DecInvalidSamplingFrequency,
            -11 => Self::DecPayloadTooLarge,
            -12 => Self::DecPayloadError,
            _ => Self::Other(code),
        }
    }
}