diff options
Diffstat (limited to 'src/packet.h')
-rw-r--r-- | src/packet.h | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/src/packet.h b/src/packet.h index b014f2b..12d15fc 100644 --- a/src/packet.h +++ b/src/packet.h @@ -32,40 +32,40 @@ #include <stdint.h> +typedef enum _fastd_packet_type { + PACKET_UNKNOWN = 0, + PACKET_HANDSHAKE, + PACKET_DATA, +} fastd_packet_type; + typedef enum _fastd_reply_code { REPLY_SUCCESS = 0, } fastd_reply_code; -typedef struct __attribute__ ((__packed__)) _fastd_packet_any { + #if defined(__LITTLE_ENDIAN_BITFIELD) - unsigned req_id : 6; - unsigned cp : 1; - unsigned reply : 1; +#define FASTD_PACKET_COMMON \ + unsigned req_id : 6; \ + unsigned cp : 1; \ + unsigned reply : 1; \ + uint8_t rsv #elif defined (__BIG_ENDIAN_BITFIELD) - unsigned reply : 1; - unsigned cp : 1; - unsigned req_id : 6; +#define FASTD_PACKET_COMMON \ + unsigned reply : 1; \ + unsigned cp : 1; \ + unsigned req_id : 6; \ + uint8_t rsv #else #error "Bitfield endianess not defined." #endif - uint8_t rsv; + +typedef struct __attribute__ ((__packed__)) _fastd_packet_any { + FASTD_PACKET_COMMON; } fastd_packet_any; typedef struct __attribute__ ((__packed__)) _fastd_packet_request { -#if defined(__LITTLE_ENDIAN_BITFIELD) - unsigned req_id : 6; - unsigned cp : 1; - unsigned reply : 1; -#elif defined (__BIG_ENDIAN_BITFIELD) - unsigned reply : 1; - unsigned cp : 1; - unsigned req_id : 6; -#else -#error "Bitfield endianess not defined." -#endif - - uint8_t rsv; + FASTD_PACKET_COMMON; uint8_t flags; uint8_t proto; uint8_t method_len; @@ -73,19 +73,7 @@ typedef struct __attribute__ ((__packed__)) _fastd_packet_request { } fastd_packet_request; typedef struct __attribute__ ((__packed__)) _fastd_packet_reply { -#if defined(__LITTLE_ENDIAN_BITFIELD) - unsigned req_id : 6; - unsigned cp : 1; - unsigned reply : 1; -#elif defined (__BIG_ENDIAN_BITFIELD) - unsigned reply : 1; - unsigned cp : 1; - unsigned req_id : 6; -#else -#error "Bitfield endianess not defined." -#endif - - uint8_t rsv; + FASTD_PACKET_COMMON; uint8_t reply_code; } fastd_packet_reply; |