SFBPacket.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00027 #ifndef SFBPACKET_H_
00028 #define SFBPACKET_H_
00029
00030 #include "SFBTypes.h"
00031 #include "SFBAssert.h"
00032
00038 struct PacketHeader {
00039 u8 f[4];
00040 enum Fields {
00041 SOURCE,
00042 FLAGS,
00043 CURSOR,
00044 LENGTH,
00045 FIELD_COUNT
00046 };
00047 };
00048
00050 struct PacketBuffer {
00051 union {
00052 u32 wh;
00053 PacketHeader ph;
00054 } h;
00055 u8 bbuf[SINGLE_PACKET_BUFFER_SIZE_BYTES];
00056 };
00059
00060 #define PFSC_END ((u8) '\012')
00061 #define PFSC_ESC ((u8) '\333')
00062 #define PFSC_EEND ((u8) '\334')
00063 #define PFSC_EESC ((u8) '\335')
00064
00065 #define CHECK_BYTE_INIT_VALUE (0xF0)
00066 #define CHECK_BYTE_UPDATE(v,d) ((v) = ((v<<1)|((v>>7)&1))^d)
00067
00072 inline const PacketHeader & packetHeaderInternalUnsafeConst(const u8 * packet) {
00073 return *(const PacketHeader *) (packet-4);
00074 }
00075
00076 inline PacketHeader & packetHeaderInternalUnsafe(u8 * packet) {
00077 return *(PacketHeader *) (packet-4);
00078 }
00079
00092 extern bool packetEqual(const u8 * packet1, const u8 * packet2);
00093
00094 extern u8 packetLength(const u8 * packet);
00095
00096 extern u8 packetReadLength(const u8 * packet);
00097
00098 extern u8 packetFlags(const u8 * packet);
00099
00100 extern u8 packetSource(const u8 * packet);
00101
00102 extern u8 packetCursor(const u8 * packet);
00103
00104 extern bool packetCheckByteValid(const u8 * packet);
00105
00106 #define API_ASSERT_VALID_PACKET(u8ptr) API_ASSERT(validPacket(u8ptr),E_API_INVALID_PACKET)
00107
00108 extern bool validPacket(const u8 * packet) ;
00109
00110 extern void packetReread(u8 * packet, u32 newIndex = 0) ;
00111
00112 extern bool packetRead(u8 * packet, int &result, int code = DEC, u32 maxLen = MAX_PACKET_LENGTH) ;
00113
00114 extern bool packetRead(u8 * packet, u32 &result, int code = DEC, u32 maxLen = MAX_PACKET_LENGTH) ;
00115
00116 extern bool packetRead(u8 * packet, u64 &result) ;
00117
00118 extern bool packetRead(u8 * packet, u8 * result, u32 length) ;
00119
00120 extern bool packetReadCheckByte(u8 * packet) ;
00121
00122 extern bool packetReadEOF(u8 * packet) ;
00123
00124 extern bool packetReadPacket(u8 * packet, u8 *& subpacket) ;
00125
00126 extern bool zpacketPrefix(u8 * packet, const char * to);
00127
00128 extern u8 * makePacket(u8 * buffer, u32 bufferLength, u8 face, const char * packetData);
00129
00130 extern u8 * makePacket(u8 * buffer, u32 bufferLength, u8 face, const u8 * packetData, u32 packetDataLength);
00131
00136 #endif