semtech-udp 0.12.0

Semtech UDP provides serialization and deserialization of packets complying with the Semtech UDP protocol
Documentation
use crate::{Down, Up};
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
    #[error("io error")]
    Io(#[from] std::io::Error),
    #[error("json serialization error")]
    JsonSerialize(#[from] serde_json::error::Error),
    #[error("packet parse error")]
    Parse(#[from] ParseError),
}

#[derive(Error, Debug)]
pub enum ParseError {
    #[error("invalid packet length: {0}. Requires at least {1} bytes")]
    InvalidPacketLength(usize, usize),
    #[error("invalid GWMP version: {0}")]
    InvalidProtocolVersion(u8),
    #[error("invalid GWMP frame identifier: {0}")]
    InvalidIdentifier(u8),
    #[error("utf8 error")]
    Utf8(#[from] std::str::Utf8Error),
    #[error("invalid Json string for {identifier} frame: {json_str}. JsonError: {json_error}")]
    InvalidJson {
        identifier: crate::Identifier,
        json_str: String,
        json_error: serde_json::Error,
    },
    #[error("Received downlink when expecting uplinks only")]
    UnexpectedDownlink(Down),
    #[error("Received uplink when expecting downlinks only")]
    UnexpectedUplink(Box<Up>),
}