Quake II RTX doxygen  1.0 dev
sizebuf.c File Reference
#include "shared/shared.h"
#include "common/protocol.h"
#include "common/sizebuf.h"

Go to the source code of this file.

Functions

void SZ_TagInit (sizebuf_t *buf, void *data, size_t size, uint32_t tag)
 
void SZ_Init (sizebuf_t *buf, void *data, size_t size)
 
void SZ_Clear (sizebuf_t *buf)
 
voidSZ_GetSpace (sizebuf_t *buf, size_t len)
 
void SZ_WriteByte (sizebuf_t *sb, int c)
 
void SZ_WriteShort (sizebuf_t *sb, int c)
 
void SZ_WriteLong (sizebuf_t *sb, int c)
 

Function Documentation

◆ SZ_Clear()

◆ SZ_GetSpace()

void* SZ_GetSpace ( sizebuf_t *  buf,
size_t  len 
)

Definition at line 48 of file sizebuf.c.

49 {
50  void *data;
51 
52  if (buf->cursize > buf->maxsize) {
53  Com_Error(ERR_FATAL,
54  "%s: %#x: already overflowed",
55  __func__, buf->tag);
56  }
57 
58  if (len > buf->maxsize - buf->cursize) {
59  if (len > buf->maxsize) {
60  Com_Error(ERR_FATAL,
61  "%s: %#x: %"PRIz" is > full buffer size %"PRIz"",
62  __func__, buf->tag, len, buf->maxsize);
63  }
64 
65  if (!buf->allowoverflow) {
66  Com_Error(ERR_FATAL,
67  "%s: %#x: overflow without allowoverflow set",
68  __func__, buf->tag);
69  }
70 
71  //Com_DPrintf("%s: %#x: overflow\n", __func__, buf->tag);
72  SZ_Clear(buf);
73  buf->overflowed = qtrue;
74  }
75 
76  data = buf->data + buf->cursize;
77  buf->cursize += len;
78  buf->bitpos = buf->cursize << 3;
79  return data;
80 }

Referenced by CL_SendBatchedCmd(), CL_SendDefaultCmd(), MSG_WriteByte(), MSG_WriteChar(), MSG_WriteLong(), MSG_WriteShort(), SV_WriteFrameToClient_Enhanced(), SZ_WriteByte(), SZ_WriteLong(), and SZ_WriteShort().

◆ SZ_Init()

void SZ_Init ( sizebuf_t *  buf,
void data,
size_t  size 
)

Definition at line 31 of file sizebuf.c.

32 {
33  memset(buf, 0, sizeof(*buf));
34  buf->data = data;
35  buf->maxsize = size;
36  buf->allowoverflow = qtrue;
37  buf->allowunderflow = qtrue;
38 }

Referenced by CL_GTV_Resume(), CL_ParseZPacket(), CL_Record_f(), CL_Seek_f(), demo_read_message(), demo_skip_map(), FIFO_ReadMessage(), MVD_Seek_f(), NET_GetUdpPackets(), NetchanNew_Setup(), NetchanOld_Setup(), read_binary_file(), read_first_message(), read_next_message(), and SV_MvdInit().

◆ SZ_TagInit()

void SZ_TagInit ( sizebuf_t *  buf,
void data,
size_t  size,
uint32_t  tag 
)

Definition at line 23 of file sizebuf.c.

24 {
25  memset(buf, 0, sizeof(*buf));
26  buf->data = data;
27  buf->maxsize = size;
28  buf->tag = tag;
29 }

Referenced by MSG_Init(), NetchanNew_Setup(), NetchanNew_Transmit(), NetchanNew_TransmitNextFragment(), and NetchanOld_Transmit().

◆ SZ_WriteByte()

void SZ_WriteByte ( sizebuf_t *  sb,
int  c 
)

◆ SZ_WriteLong()

void SZ_WriteLong ( sizebuf_t *  sb,
int  c 
)

Definition at line 99 of file sizebuf.c.

100 {
101  byte *buf;
102 
103  buf = SZ_GetSpace(sb, 4);
104  buf[0] = c & 0xff;
105  buf[1] = (c >> 8) & 0xff;
106  buf[2] = (c >> 16) & 0xff;
107  buf[3] = c >> 24;
108 }

Referenced by NetchanNew_Transmit(), NetchanNew_TransmitNextFragment(), and NetchanOld_Transmit().

◆ SZ_WriteShort()

void SZ_WriteShort ( sizebuf_t *  sb,
int  c 
)

Definition at line 90 of file sizebuf.c.

91 {
92  byte *buf;
93 
94  buf = SZ_GetSpace(sb, 2);
95  buf[0] = c & 0xff;
96  buf[1] = c >> 8;
97 }

Referenced by NetchanNew_TransmitNextFragment(), NetchanOld_Transmit(), resume_record(), SV_MvdConfigstring(), SV_MvdMulticast(), SV_MvdStartSound(), and write_pending_download().

SZ_GetSpace
void * SZ_GetSpace(sizebuf_t *buf, size_t len)
Definition: sizebuf.c:48
Com_Error
void Com_Error(error_type_t type, const char *fmt,...)
Definition: g_main.c:258
c
statCounters_t c
Definition: main.c:30
SZ_Clear
void SZ_Clear(sizebuf_t *buf)
Definition: sizebuf.c:40