mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[util] Add message short and long poke functions
Both big and little endian.
This commit is contained in:
parent
972b0f8a70
commit
f596eacf0c
2 changed files with 61 additions and 0 deletions
|
@ -52,6 +52,11 @@ void MSG_WriteAngle16 (sizebuf_t *sb, float angle);
|
|||
void MSG_WriteAngle16V (sizebuf_t *sb, const vec3_t angle);
|
||||
void MSG_WriteUTF8 (sizebuf_t *sb, unsigned utf8);
|
||||
|
||||
void MSG_PokeShort (sizebuf_t *sb, unsigned offset, int c);
|
||||
void MSG_PokeShortBE (sizebuf_t *sb, unsigned offset, int c);
|
||||
void MSG_PokeLong (sizebuf_t *sb, unsigned offset, int c);
|
||||
void MSG_PokeLongBE (sizebuf_t *sb, unsigned offset, int c);
|
||||
|
||||
typedef struct msg_s {
|
||||
unsigned readcount;
|
||||
qboolean badread; // set if a read goes beyond end of message
|
||||
|
|
|
@ -244,6 +244,62 @@ MSG_WriteUTF8 (sizebuf_t *sb, unsigned utf8)
|
|||
}
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
MSG_PokeShort (sizebuf_t *sb, unsigned offset, int c)
|
||||
{
|
||||
if (__builtin_expect (offset + 2 > sb->cursize, 0)) {
|
||||
Sys_Error ("MSG_PokeShort: invalid offset %d / %d",
|
||||
offset, sb->cursize);
|
||||
}
|
||||
byte *buf = sb->data + offset;
|
||||
|
||||
*buf++ = ((unsigned int) c) & 0xff;
|
||||
*buf = ((unsigned int) c) >> 8;
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
MSG_PokeShortBE (sizebuf_t *sb, unsigned offset, int c)
|
||||
{
|
||||
if (__builtin_expect (offset + 2 > sb->cursize, 0)) {
|
||||
Sys_Error ("MSG_PokeShortBE: invalid offset %d / %d",
|
||||
offset, sb->cursize);
|
||||
}
|
||||
byte *buf = sb->data + offset;
|
||||
|
||||
*buf++ = ((unsigned int) c) >> 8;
|
||||
*buf = ((unsigned int) c) & 0xff;
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
MSG_PokeLong (sizebuf_t *sb, unsigned offset, int c)
|
||||
{
|
||||
if (__builtin_expect (offset + 2 > sb->cursize, 0)) {
|
||||
Sys_Error ("MSG_PokeLong: invalid offset %d / %d",
|
||||
offset, sb->cursize);
|
||||
}
|
||||
byte *buf = sb->data + offset;
|
||||
|
||||
*buf++ = ((unsigned int) c) & 0xff;
|
||||
*buf++ = (((unsigned int) c) >> 8) & 0xff;
|
||||
*buf++ = (((unsigned int) c) >> 16) & 0xff;
|
||||
*buf = ((unsigned int) c) >> 24;
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
MSG_PokeLongBE (sizebuf_t *sb, unsigned offset, int c)
|
||||
{
|
||||
if (__builtin_expect (offset + 2 > sb->cursize, 0)) {
|
||||
Sys_Error ("MSG_PokeLongBE: invalid offset %d / %d",
|
||||
offset, sb->cursize);
|
||||
}
|
||||
byte *buf = sb->data + offset;
|
||||
|
||||
*buf++ = ((unsigned int) c) >> 24;
|
||||
*buf++ = (((unsigned int) c) >> 16) & 0xff;
|
||||
*buf++ = (((unsigned int) c) >> 8) & 0xff;
|
||||
*buf = ((unsigned int) c) & 0xff;
|
||||
}
|
||||
|
||||
// reading functions ==========================================================
|
||||
|
||||
VISIBLE void
|
||||
|
|
Loading…
Reference in a new issue