f1_api/nineteen/flag.rs
1//! Decoder for flags that can be shown to cars
2
3use std::io::{Cursor, Error, ErrorKind};
4
5use bytes::{Buf, BytesMut};
6
7use crate::types::Flag;
8
9/// Decode a flag that can be shown to cars
10pub fn decode_flag(cursor: &mut Cursor<&mut BytesMut>) -> Result<Flag, Error> {
11 let value = cursor.get_i8();
12
13 match value {
14 -1 => Ok(Flag::Invalid),
15 0 => Ok(Flag::None),
16 1 => Ok(Flag::Green),
17 2 => Ok(Flag::Blue),
18 3 => Ok(Flag::Yellow),
19 4 => Ok(Flag::Red),
20 _ => Err(Error::new(ErrorKind::InvalidData, "Failed to decode flag.")),
21 }
22}