minor code style changes
This commit is contained in:
parent
726cc6facf
commit
b576b389b4
1 changed files with 62 additions and 121 deletions
183
src/protocol.cpp
183
src/protocol.cpp
|
@ -769,8 +769,7 @@ bool CProtocol::EvaluateJitBufMes ( const CVector<uint8_t>& vecData )
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract jitter buffer size
|
// extract jitter buffer size
|
||||||
const int iData =
|
const int iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
||||||
|
|
||||||
if ( ( ( iData < MIN_NET_BUF_SIZE_NUM_BL ) ||
|
if ( ( ( iData < MIN_NET_BUF_SIZE_NUM_BL ) ||
|
||||||
( iData > MAX_NET_BUF_SIZE_NUM_BL ) ) &&
|
( iData > MAX_NET_BUF_SIZE_NUM_BL ) ) &&
|
||||||
|
@ -1083,16 +1082,13 @@ void CProtocol::CreateChanInfoMes ( const CChannelCoreInfo ChanInfo )
|
||||||
CVector<uint8_t> vecData ( iEntrLen );
|
CVector<uint8_t> vecData ( iEntrLen );
|
||||||
|
|
||||||
// country (2 bytes)
|
// country (2 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ChanInfo.eCountry ), 2 );
|
||||||
static_cast<uint32_t> ( ChanInfo.eCountry ), 2 );
|
|
||||||
|
|
||||||
// instrument (4 bytes)
|
// instrument (4 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ChanInfo.iInstrument ), 4 );
|
||||||
static_cast<uint32_t> ( ChanInfo.iInstrument ), 4 );
|
|
||||||
|
|
||||||
// skill level (1 byte)
|
// skill level (1 byte)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ChanInfo.eSkillLevel ), 1 );
|
||||||
static_cast<uint32_t> ( ChanInfo.eSkillLevel ), 1 );
|
|
||||||
|
|
||||||
// name
|
// name
|
||||||
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
||||||
|
@ -1116,16 +1112,13 @@ bool CProtocol::EvaluateChanInfoMes ( const CVector<uint8_t>& vecData )
|
||||||
}
|
}
|
||||||
|
|
||||||
// country (2 bytes)
|
// country (2 bytes)
|
||||||
ChanInfo.eCountry =
|
ChanInfo.eCountry = static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
||||||
|
|
||||||
// instrument (4 bytes)
|
// instrument (4 bytes)
|
||||||
ChanInfo.iInstrument =
|
ChanInfo.iInstrument = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
||||||
|
|
||||||
// skill level (1 byte)
|
// skill level (1 byte)
|
||||||
ChanInfo.eSkillLevel =
|
ChanInfo.eSkillLevel = static_cast<ESkillLevel> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
static_cast<ESkillLevel> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
||||||
|
|
||||||
// name
|
// name
|
||||||
if ( GetStringFromStream ( vecData,
|
if ( GetStringFromStream ( vecData,
|
||||||
|
@ -1235,32 +1228,25 @@ void CProtocol::CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrPr
|
||||||
CVector<uint8_t> vecData ( iEntrLen );
|
CVector<uint8_t> vecData ( iEntrLen );
|
||||||
|
|
||||||
// length of the base network packet (frame) in bytes (4 bytes)
|
// length of the base network packet (frame) in bytes (4 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iBaseNetworkPacketSize ), 4 );
|
||||||
static_cast<uint32_t> ( NetTrProps.iBaseNetworkPacketSize ), 4 );
|
|
||||||
|
|
||||||
// block size factor (2 bytes)
|
// block size factor (2 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iBlockSizeFact ), 2 );
|
||||||
static_cast<uint32_t> ( NetTrProps.iBlockSizeFact ), 2 );
|
|
||||||
|
|
||||||
// number of channels of the audio signal, e.g. "2" is stereo (1 byte)
|
// number of channels of the audio signal, e.g. "2" is stereo (1 byte)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iNumAudioChannels ), 1 );
|
||||||
static_cast<uint32_t> ( NetTrProps.iNumAudioChannels ), 1 );
|
|
||||||
|
|
||||||
// sample rate of the audio stream (4 bytes)
|
// sample rate of the audio stream (4 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iSampleRate ), 4 );
|
||||||
static_cast<uint32_t> ( NetTrProps.iSampleRate ), 4 );
|
|
||||||
|
|
||||||
// audio coding type (2 bytes)
|
// audio coding type (2 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.eAudioCodingType ), 2 );
|
||||||
static_cast<uint32_t> ( NetTrProps.eAudioCodingType ), 2 );
|
|
||||||
|
|
||||||
// version (2 bytes)
|
// version (2 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iVersion ), 2 );
|
||||||
static_cast<uint32_t> ( NetTrProps.iVersion ), 2 );
|
|
||||||
|
|
||||||
// argument for the audio coder (4 bytes)
|
// argument for the audio coder (4 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iAudioCodingArg ), 4 );
|
||||||
static_cast<uint32_t> ( NetTrProps.iAudioCodingArg ), 4 );
|
|
||||||
|
|
||||||
CreateAndSendMessage ( PROTMESSID_NETW_TRANSPORT_PROPS, vecData );
|
CreateAndSendMessage ( PROTMESSID_NETW_TRANSPORT_PROPS, vecData );
|
||||||
}
|
}
|
||||||
|
@ -1406,8 +1392,7 @@ bool CProtocol::EvaluateLicenceRequiredMes ( const CVector<uint8_t>& vecData )
|
||||||
|
|
||||||
void CProtocol::CreateOpusSupportedMes()
|
void CProtocol::CreateOpusSupportedMes()
|
||||||
{
|
{
|
||||||
CreateAndSendMessage ( PROTMESSID_OPUS_SUPPORTED,
|
CreateAndSendMessage ( PROTMESSID_OPUS_SUPPORTED, CVector<uint8_t> ( 0 ) );
|
||||||
CVector<uint8_t> ( 0 ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProtocol::CreateReqChannelLevelListMes ( const bool bRCL )
|
void CProtocol::CreateReqChannelLevelListMes ( const bool bRCL )
|
||||||
|
@ -1576,12 +1561,10 @@ bool CProtocol::EvaluateCLPingWithNumClientsMes ( const CHostAddress& InetAd
|
||||||
}
|
}
|
||||||
|
|
||||||
// transmit time
|
// transmit time
|
||||||
const int iCurMs =
|
const int iCurMs = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
||||||
|
|
||||||
// current number of connected clients
|
// current number of connected clients
|
||||||
const int iCurNumClients =
|
const int iCurNumClients = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
||||||
|
|
||||||
// invoke message action
|
// invoke message action
|
||||||
emit CLPingWithNumClientsReceived ( InetAddr, iCurMs, iCurNumClients );
|
emit CLPingWithNumClientsReceived ( InetAddr, iCurMs, iCurNumClients );
|
||||||
|
@ -1629,20 +1612,16 @@ void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
CVector<uint8_t> vecData ( iEntrLen );
|
CVector<uint8_t> vecData ( iEntrLen );
|
||||||
|
|
||||||
// port number (2 bytes)
|
// port number (2 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( LInetAddr.iPort ), 2 );
|
||||||
static_cast<uint32_t> ( LInetAddr.iPort ), 2 );
|
|
||||||
|
|
||||||
// country (2 bytes)
|
// country (2 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ServerInfo.eCountry ), 2 );
|
||||||
static_cast<uint32_t> ( ServerInfo.eCountry ), 2 );
|
|
||||||
|
|
||||||
// maximum number of connected clients (1 byte)
|
// maximum number of connected clients (1 byte)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ServerInfo.iMaxNumClients ), 1 );
|
||||||
static_cast<uint32_t> ( ServerInfo.iMaxNumClients ), 1 );
|
|
||||||
|
|
||||||
// "is permanent" flag (1 byte)
|
// "is permanent" flag (1 byte)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ServerInfo.bPermanentOnline ), 1 );
|
||||||
static_cast<uint32_t> ( ServerInfo.bPermanentOnline ), 1 );
|
|
||||||
|
|
||||||
// name
|
// name
|
||||||
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
||||||
|
@ -1674,20 +1653,16 @@ bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
// port number (2 bytes)
|
// port number (2 bytes)
|
||||||
LInetAddr.iPort =
|
LInetAddr.iPort = static_cast<quint16> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
static_cast<quint16> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
||||||
|
|
||||||
// country (2 bytes)
|
// country (2 bytes)
|
||||||
RecServerInfo.eCountry =
|
RecServerInfo.eCountry = static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
||||||
|
|
||||||
// maximum number of connected clients (1 byte)
|
// maximum number of connected clients (1 byte)
|
||||||
RecServerInfo.iMaxNumClients =
|
RecServerInfo.iMaxNumClients = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
||||||
|
|
||||||
// "is permanent" flag (1 byte)
|
// "is permanent" flag (1 byte)
|
||||||
RecServerInfo.bPermanentOnline =
|
RecServerInfo.bPermanentOnline = static_cast<bool> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
static_cast<bool> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
||||||
|
|
||||||
// server name
|
// server name
|
||||||
if ( GetStringFromStream ( vecData,
|
if ( GetStringFromStream ( vecData,
|
||||||
|
@ -1836,24 +1811,19 @@ bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
// IP address (4 bytes)
|
// IP address (4 bytes)
|
||||||
const quint32 iIpAddr =
|
const quint32 iIpAddr = static_cast<quint32> ( GetValFromStream ( vecData, iPos, 4 ) );
|
||||||
static_cast<quint32> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
||||||
|
|
||||||
// port number (2 bytes)
|
// port number (2 bytes)
|
||||||
const quint16 iPort =
|
const quint16 iPort = static_cast<quint16> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
static_cast<quint16> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
||||||
|
|
||||||
// country (2 bytes)
|
// country (2 bytes)
|
||||||
const QLocale::Country eCountry =
|
const QLocale::Country eCountry = static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
||||||
|
|
||||||
// maximum number of connected clients (1 byte)
|
// maximum number of connected clients (1 byte)
|
||||||
const int iMaxNumClients =
|
const int iMaxNumClients = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
||||||
|
|
||||||
// "is permanent" flag (1 byte)
|
// "is permanent" flag (1 byte)
|
||||||
const bool bPermanentOnline =
|
const bool bPermanentOnline = static_cast<bool> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
static_cast<bool> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
||||||
|
|
||||||
// server name
|
// server name
|
||||||
QString strName;
|
QString strName;
|
||||||
|
@ -1955,12 +1925,10 @@ bool CProtocol::EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData )
|
||||||
}
|
}
|
||||||
|
|
||||||
// IP address (4 bytes)
|
// IP address (4 bytes)
|
||||||
const quint32 iIpAddr =
|
const quint32 iIpAddr = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
||||||
|
|
||||||
// port number (2 bytes)
|
// port number (2 bytes)
|
||||||
const quint16 iPort =
|
const quint16 iPort = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
||||||
|
|
||||||
// invoke message action
|
// invoke message action
|
||||||
emit CLSendEmptyMes ( CHostAddress ( QHostAddress ( iIpAddr ), iPort ) );
|
emit CLSendEmptyMes ( CHostAddress ( QHostAddress ( iIpAddr ), iPort ) );
|
||||||
|
@ -2102,24 +2070,19 @@ void CProtocol::CreateCLConnClientsListMes ( const CHostAddress& InetAd
|
||||||
vecData.Enlarge ( iCurListEntrLen );
|
vecData.Enlarge ( iCurListEntrLen );
|
||||||
|
|
||||||
// channel ID (1 byte)
|
// channel ID (1 byte)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecChanInfo[i].iChanID ), 1 );
|
||||||
static_cast<uint32_t> ( vecChanInfo[i].iChanID ), 1 );
|
|
||||||
|
|
||||||
// country (2 bytes)
|
// country (2 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecChanInfo[i].eCountry ), 2 );
|
||||||
static_cast<uint32_t> ( vecChanInfo[i].eCountry ), 2 );
|
|
||||||
|
|
||||||
// instrument (4 bytes)
|
// instrument (4 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecChanInfo[i].iInstrument ), 4 );
|
||||||
static_cast<uint32_t> ( vecChanInfo[i].iInstrument ), 4 );
|
|
||||||
|
|
||||||
// skill level (1 byte)
|
// skill level (1 byte)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecChanInfo[i].eSkillLevel ), 1 );
|
||||||
static_cast<uint32_t> ( vecChanInfo[i].eSkillLevel ), 1 );
|
|
||||||
|
|
||||||
// IP address (4 bytes)
|
// IP address (4 bytes)
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecChanInfo[i].iIpAddr ), 4 );
|
||||||
static_cast<uint32_t> ( vecChanInfo[i].iIpAddr ), 4 );
|
|
||||||
|
|
||||||
// name
|
// name
|
||||||
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
||||||
|
@ -2149,24 +2112,19 @@ bool CProtocol::EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
// channel ID (1 byte)
|
// channel ID (1 byte)
|
||||||
const int iChanID =
|
const int iChanID = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
||||||
|
|
||||||
// country (2 bytes)
|
// country (2 bytes)
|
||||||
const QLocale::Country eCountry =
|
const QLocale::Country eCountry = static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
||||||
|
|
||||||
// instrument (4 bytes)
|
// instrument (4 bytes)
|
||||||
const int iInstrument =
|
const int iInstrument = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
||||||
|
|
||||||
// skill level (1 byte)
|
// skill level (1 byte)
|
||||||
const ESkillLevel eSkillLevel =
|
const ESkillLevel eSkillLevel = static_cast<ESkillLevel> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
static_cast<ESkillLevel> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
||||||
|
|
||||||
// IP address (4 bytes)
|
// IP address (4 bytes)
|
||||||
const int iIpAddr =
|
const int iIpAddr = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
||||||
|
|
||||||
// name
|
// name
|
||||||
QString strCurName;
|
QString strCurName;
|
||||||
|
@ -2240,8 +2198,7 @@ void CProtocol::CreateCLChannelLevelListMes ( const CHostAddress& InetAddr
|
||||||
uint16_t levelHi = ( i + 1 < iNumClients ) ? vecLevelList[i + 1] & 0x0F : 0x0F;
|
uint16_t levelHi = ( i + 1 < iNumClients ) ? vecLevelList[i + 1] & 0x0F : 0x0F;
|
||||||
uint8_t byte = static_cast<uint8_t> ( levelLo | ( levelHi << 4 ) );
|
uint8_t byte = static_cast<uint8_t> ( levelLo | ( levelHi << 4 ) );
|
||||||
|
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( byte ), 1 );
|
||||||
static_cast<uint32_t> ( byte ), 1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_CHANNEL_LEVEL_LIST,
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_CHANNEL_LEVEL_LIST,
|
||||||
|
@ -2295,8 +2252,7 @@ void CProtocol::CreateCLRegisterServerResp ( const CHostAddress& InetAddr,
|
||||||
int iPos = 0; // init position pointer
|
int iPos = 0; // init position pointer
|
||||||
CVector<uint8_t> vecData( 1 );
|
CVector<uint8_t> vecData( 1 );
|
||||||
|
|
||||||
PutValOnStream ( vecData, iPos,
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( eResult ), 1 );
|
||||||
static_cast<uint32_t> ( eResult ), 1 );
|
|
||||||
|
|
||||||
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REGISTER_SERVER_RESP,
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REGISTER_SERVER_RESP,
|
||||||
vecData,
|
vecData,
|
||||||
|
@ -2314,8 +2270,7 @@ bool CProtocol::EvaluateCLRegisterServerResp ( const CHostAddress& InetAddr,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESvrRegResult eResult = static_cast<ESvrRegResult> (
|
ESvrRegResult eResult = static_cast<ESvrRegResult> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
GetValFromStream ( vecData, iPos, 1 ) );
|
|
||||||
|
|
||||||
// invoke message action
|
// invoke message action
|
||||||
emit CLRegisterServerResp ( InetAddr, eResult );
|
emit CLRegisterServerResp ( InetAddr, eResult );
|
||||||
|
@ -2379,8 +2334,7 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecbyData,
|
||||||
|
|
||||||
for ( i = 0; i < iLenCRCCalc; i++ )
|
for ( i = 0; i < iLenCRCCalc; i++ )
|
||||||
{
|
{
|
||||||
CRCObj.AddByte ( static_cast<uint8_t> (
|
CRCObj.AddByte ( static_cast<uint8_t> ( GetValFromStream ( vecbyData, iCurPos, 1 ) ) );
|
||||||
GetValFromStream ( vecbyData, iCurPos, 1 ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( CRCObj.GetCRC () != GetValFromStream ( vecbyData, iCurPos, 2 ) )
|
if ( CRCObj.GetCRC () != GetValFromStream ( vecbyData, iCurPos, 2 ) )
|
||||||
|
@ -2400,8 +2354,7 @@ bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecbyData,
|
||||||
|
|
||||||
for ( i = 0; i < iLenBy; i++ )
|
for ( i = 0; i < iLenBy; i++ )
|
||||||
{
|
{
|
||||||
vecbyMesBodyData[i] = static_cast<uint8_t> (
|
vecbyMesBodyData[i] = static_cast<uint8_t> ( GetValFromStream ( vecbyData, iCurPos, 1 ) );
|
||||||
GetValFromStream ( vecbyData, iCurPos, 1 ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // no error
|
return false; // no error
|
||||||
|
@ -2446,8 +2399,7 @@ bool CProtocol::GetStringFromStream ( const CVector<uint8_t>& vecIn,
|
||||||
}
|
}
|
||||||
|
|
||||||
// number of bytes for utf-8 string (2 bytes)
|
// number of bytes for utf-8 string (2 bytes)
|
||||||
const int iStrUTF8Len =
|
const int iStrUTF8Len = static_cast<int> ( GetValFromStream ( vecIn, iPos, 2 ) );
|
||||||
static_cast<int> ( GetValFromStream ( vecIn, iPos, 2 ) );
|
|
||||||
|
|
||||||
// (note that iPos was incremented by 2 in the above code!)
|
// (note that iPos was incremented by 2 in the above code!)
|
||||||
if ( ( iInLen - iPos ) < iStrUTF8Len )
|
if ( ( iInLen - iPos ) < iStrUTF8Len )
|
||||||
|
@ -2497,26 +2449,21 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
|
||||||
int iCurPos = 0; // init position pointer
|
int iCurPos = 0; // init position pointer
|
||||||
|
|
||||||
// 2 bytes TAG (all zero bits)
|
// 2 bytes TAG (all zero bits)
|
||||||
PutValOnStream ( vecOut, iCurPos,
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( 0 ), 2 );
|
||||||
static_cast<uint32_t> ( 0 ), 2 );
|
|
||||||
|
|
||||||
// 2 bytes ID
|
// 2 bytes ID
|
||||||
PutValOnStream ( vecOut, iCurPos,
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( iID ), 2 );
|
||||||
static_cast<uint32_t> ( iID ), 2 );
|
|
||||||
|
|
||||||
// 1 byte cnt
|
// 1 byte cnt
|
||||||
PutValOnStream ( vecOut, iCurPos,
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( iCnt ), 1 );
|
||||||
static_cast<uint32_t> ( iCnt ), 1 );
|
|
||||||
|
|
||||||
// 2 bytes length
|
// 2 bytes length
|
||||||
PutValOnStream ( vecOut, iCurPos,
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( iDataLenByte ), 2 );
|
||||||
static_cast<uint32_t> ( iDataLenByte ), 2 );
|
|
||||||
|
|
||||||
// encode data -----
|
// encode data -----
|
||||||
for ( i = 0; i < iDataLenByte; i++ )
|
for ( i = 0; i < iDataLenByte; i++ )
|
||||||
{
|
{
|
||||||
PutValOnStream ( vecOut, iCurPos,
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( vecData[i] ), 1 );
|
||||||
static_cast<uint32_t> ( vecData[i] ), 1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2529,18 +2476,16 @@ void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
|
||||||
|
|
||||||
for ( i = 0; i < iLenCRCCalc; i++ )
|
for ( i = 0; i < iLenCRCCalc; i++ )
|
||||||
{
|
{
|
||||||
CRCObj.AddByte ( static_cast<uint8_t> (
|
CRCObj.AddByte ( static_cast<uint8_t> ( GetValFromStream ( vecOut, iCurPos, 1 ) ) );
|
||||||
GetValFromStream ( vecOut, iCurPos, 1 ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PutValOnStream ( vecOut, iCurPos,
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( CRCObj.GetCRC() ), 2 );
|
||||||
static_cast<uint32_t> ( CRCObj.GetCRC() ), 2 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProtocol::PutValOnStream ( CVector<uint8_t>& vecIn,
|
void CProtocol::PutValOnStream ( CVector<uint8_t>& vecIn,
|
||||||
int& iPos,
|
int& iPos,
|
||||||
const uint32_t iVal,
|
const uint32_t iVal,
|
||||||
const int iNumOfBytes )
|
const int iNumOfBytes )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
note: iPos is automatically incremented in this function
|
note: iPos is automatically incremented in this function
|
||||||
|
@ -2551,9 +2496,7 @@ void CProtocol::PutValOnStream ( CVector<uint8_t>& vecIn,
|
||||||
|
|
||||||
for ( int i = 0; i < iNumOfBytes; i++ )
|
for ( int i = 0; i < iNumOfBytes; i++ )
|
||||||
{
|
{
|
||||||
vecIn[iPos] =
|
vecIn[iPos] = ( iVal >> ( i * 8 /* size of byte */ ) ) & 255 /* 11111111 */;
|
||||||
( iVal >> ( i * 8 /* size of byte */ ) ) & 255 /* 11111111 */;
|
|
||||||
|
|
||||||
iPos++;
|
iPos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2566,14 +2509,12 @@ void CProtocol::PutStringUTF8OnStream ( CVector<uint8_t>& vecIn,
|
||||||
const int iStrUTF8Len = sStringUTF8.size();
|
const int iStrUTF8Len = sStringUTF8.size();
|
||||||
|
|
||||||
// number of bytes for utf-8 string (2 bytes)
|
// number of bytes for utf-8 string (2 bytes)
|
||||||
PutValOnStream ( vecIn, iPos,
|
PutValOnStream ( vecIn, iPos, static_cast<uint32_t> ( iStrUTF8Len ), 2 );
|
||||||
static_cast<uint32_t> ( iStrUTF8Len ), 2 );
|
|
||||||
|
|
||||||
// actual utf-8 string (n bytes)
|
// actual utf-8 string (n bytes)
|
||||||
for ( int j = 0; j < iStrUTF8Len; j++ )
|
for ( int j = 0; j < iStrUTF8Len; j++ )
|
||||||
{
|
{
|
||||||
// byte-by-byte copying of the utf-8 string data
|
// byte-by-byte copying of the utf-8 string data
|
||||||
PutValOnStream ( vecIn, iPos,
|
PutValOnStream ( vecIn, iPos, static_cast<uint32_t> ( sStringUTF8[j] ), 1 );
|
||||||
static_cast<uint32_t> ( sStringUTF8[j] ), 1 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue