From 1d18f972554c8bad0f08b3ff6727c87586e97094 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 6 Mar 2012 21:29:34 +0100 Subject: Reorganized type definitions --- src/packet.h | 56 ++++++++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) (limited to 'src/packet.h') 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 +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; -- cgit v1.2.3