Skip to content
Snippets Groups Projects
Commit a6685460 authored by LJ Sonic's avatar LJ Sonic
Browse files

Make byte stream manipulation code easier to read

parent 13778247
Branches
Tags
1 merge request!1698Fix issues with chat messages
...@@ -150,27 +150,58 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) ...@@ -150,27 +150,58 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr)
#undef DEALIGNED #undef DEALIGNED
#define WRITESTRINGN(p,s,n) do { size_t tmp_i = 0; for (; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); if (tmp_i < n) WRITECHAR(p, '\0');} while (0) #define WRITESTRINGN(p, s, n) ({ \
#define WRITESTRING(p,s) do { size_t tmp_i = 0; for (; s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); WRITECHAR(p, '\0');} while (0) size_t tmp_i; \
#define WRITEMEM(p,s,n) do { memcpy(p, s, n); p += n; } while (0) \
for (tmp_i = 0; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) \
WRITECHAR(p, s[tmp_i]); \
\
if (tmp_i < n) \
WRITECHAR(p, '\0'); \
})
#define WRITESTRING(p, s) ({ \
size_t tmp_i; \
\
for (tmp_i = 0; s[tmp_i] != '\0'; tmp_i++) \
WRITECHAR(p, s[tmp_i]); \
\
WRITECHAR(p, '\0'); \
})
#define WRITEMEM(p, s, n) ({ \
memcpy(p, s, n); \
p += n; \
})
#define SKIPSTRING(p) while (READCHAR(p) != '\0') #define SKIPSTRING(p) while (READCHAR(p) != '\0')
#define SKIPSTRINGN(p,n) ({ size_t tmp_i = 0; for (; tmp_i < n && READCHAR(p) != '\0'; tmp_i++); })
#define SKIPSTRINGN(p, n) ({ \
#define READSTRINGN(p,s,n) ({ size_t tmp_i = 0; for (; tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';}) size_t tmp_i = 0; \
#define READSTRING(p,s) ({ size_t tmp_i = 0; for (; (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';}) \
#define READMEM(p,s,n) ({ memcpy(s, p, n); p += n; }) while (tmp_i < n && READCHAR(p) != '\0') \
tmp_i++; \
#if 0 // old names })
#define WRITEBYTE(p,b) WRITEUINT8(p,b)
#define WRITESHORT(p,b) WRITEINT16(p,b) #define READSTRINGN(p, s, n) ({ \
#define WRITEUSHORT(p,b) WRITEUINT16(p,b) size_t tmp_i = 0; \
#define WRITELONG(p,b) WRITEINT32(p,b) \
#define WRITEULONG(p,b) WRITEUINT32(p,b) while (tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0') \
tmp_i++; \
#define READBYTE(p) READUINT8(p) \
#define READSHORT(p) READINT16(p) s[tmp_i] = '\0'; \
#define READUSHORT(p) READUINT16(p) })
#define READLONG(p) READINT32(p)
#define READULONG(p) READUINT32(p) #define READSTRING(p, s) ({ \
#endif size_t tmp_i = 0; \
\
while ((s[tmp_i] = READCHAR(p)) != '\0') \
tmp_i++; \
\
s[tmp_i] = '\0'; \
})
#define READMEM(p, s, n) ({ \
memcpy(s, p, n); \
p += n; \
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment