| 67 | } |
| 68 | |
| 69 | fn decode<T: WireDecode>(payload: &[u8]) -> Result<T, IggyError> { |
| 70 | use iggy_binary_protocol::error::WireError; |
| 71 | |
| 72 | let (val, consumed) = T::decode(payload).map_err(|e| { |
| 73 | warn!("wire decode error: {e}"); |
| 74 | match e { |
| 75 | WireError::PayloadTooLarge { .. } => IggyError::InvalidSizeBytes, |
| 76 | WireError::Validation(_) => IggyError::InvalidFormat, |
| 77 | _ => IggyError::InvalidCommand, |
| 78 | } |
| 79 | })?; |
| 80 | if consumed != payload.len() { |
| 81 | warn!( |
| 82 | "wire decode: {} trailing bytes (consumed {consumed}, payload {})", |
| 83 | payload.len() - consumed, |
| 84 | payload.len() |
| 85 | ); |
| 86 | } |
| 87 | Ok(val) |
| 88 | } |
| 89 | |
| 90 | /// Convert a `WireIdentifier` to the domain `Identifier`. |
| 91 | pub fn wire_id_to_identifier( |