MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / packString

Method packString

Engine/source/sim/netConnection.cpp:1121–1163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1119}
1120
1121void NetConnection::packString(BitStream *stream, const char *str)
1122{
1123 if(!*str)
1124 {
1125 stream->writeInt(NullString, 2);
1126 return;
1127 }
1128 if(U8(str[0]) == StringTagPrefixByte)
1129 {
1130 stream->writeInt(TagString, 2);
1131 stream->writeInt(dAtoi(str + 1), ConnectionStringTable::EntryBitSize);
1132 return;
1133 }
1134 if(str[0] == '-' || (str[0] >= '0' && str[0] <= '9'))
1135 {
1136 char buf[16];
1137 S32 num = dAtoi(str);
1138 dSprintf(buf, sizeof(buf), "%d", num);
1139 if(!dStrcmp(buf, str))
1140 {
1141 stream->writeInt(Integer, 2);
1142 if(stream->writeFlag(num < 0))
1143 num = -num;
1144 if(stream->writeFlag(num < 128))
1145 {
1146 stream->writeInt(num, 7);
1147 return;
1148 }
1149 if(stream->writeFlag(num < 32768))
1150 {
1151 stream->writeInt(num, 15);
1152 return;
1153 }
1154 else
1155 {
1156 stream->writeInt(num, 31);
1157 return;
1158 }
1159 }
1160 }
1161 stream->writeInt(CString, 2);
1162 stream->writeString(str);
1163}
1164
1165void NetConnection::unpackString(BitStream *stream, char readBuffer[1024])
1166{

Callers 1

packMethod · 0.80

Calls 6

dSprintfFunction · 0.85
writeIntMethod · 0.80
dAtoiFunction · 0.50
dStrcmpFunction · 0.50
writeFlagMethod · 0.45
writeStringMethod · 0.45

Tested by

no test coverage detected