3. Receiving

The data received by the receiving function of the communications library (which in the case of the PIA library is the nn::pia::transport::UnreliableProtocol::Receive function) can be either data for the game or data for VoiceChat.

The VCT_HandleData function looks at the received data to determine whether it is VoiceChat data, and performs the necessary processing if it is. To determine whether the data is meant for VoiceChat, the function looks for the Magic Token in the first four bytes of the received data. (See 6. Audio Data Format.)

The following example shows how this function is used.

Code 3-1 Handling Received Data (for the PIA Library)
result = nn::pia::transport::Transport::GetInstance()->GetProtocol<nn::pia::transport::UnreliableProtocol>(s_UnreliableProtocolHandle)->Receive(&srcId, recvBuf, &recvSize, sizeof(recvBuf));
if(result.IsSuccess())
{
    BOOL flag = VCT_HandleData( static_cast<u16>((srcId + 1) & 0xFFFF)), recvBuf, recvSize);
    if (flag == FALSE)
    {
        /*
        If the return value is FALSE, either the received data is not VoiceChat data,
        or the VCT library has not been initialized. 
        Implement the processing required for the game here.
         */
    }
}
 

If the return value is TRUE, the received data is VCT library data. In this case, the necessary processing is conducted inside the VCT_HandleData function and the callback function is called.


CONFIDENTIAL