Example #1
0
    private byte[] CombineBuffer_Header_And_Packet <Packet>(Packet pPacket, Packet_Header pPacketHeader) where Packet : INetworkPacket
    {
        bool bIsGenerate = pPacketHeader != null;

        if (bIsGenerate == false)
        {
            OnGeneratePacketHeader(pPacket, out bIsGenerate, out pPacketHeader);
        }

        _pBufferSend.Clear();
        if (bIsGenerate)
        {
            pPacketHeader.INetworkPacketHeader_Set_Header(SCByteHelper.SizeOf <Packet>(), pPacket.INetworkPacket_Get_PacketID());
            _pBufferSend.Enqueue(SCByteHelper.ConvertByteArray(pPacketHeader));
        }
        _pBufferSend.Enqueue(SCByteHelper.ConvertByteArray(pPacket));

        return(_pBufferSend.Dequeue_OrNull(_pBufferSend.Count));
    }
Example #2
0
    public void 링버퍼_인큐_디큐_테스트()
    {
        SPacketTest_Struct pPacketTest  = new SPacketTest_Struct(1, "인큐_디큐_테스트");
        SPacketTest_Struct pPacketTest2 = new SPacketTest_Struct(2, "더미데이터");

        byte[] arrPacketData = SCByteHelper.ConvertByteArray(pPacketTest);
        int    iDataSize     = arrPacketData.Length;

        var pBuffer = new CircularBuffer <byte>(10240);

        pBuffer.Enqueue(arrPacketData);

        Assert.AreNotEqual(pPacketTest.iValue, pPacketTest2.iValue);
        Assert.AreNotEqual(pPacketTest.strValue, pPacketTest2.strValue);

        byte[] arrPacketData2 = pBuffer.Dequeue_OrNull(iDataSize);
        arrPacketData2.Convert_ToStruct(out pPacketTest2);

        Assert.AreEqual(pPacketTest.iValue, pPacketTest2.iValue);
        Assert.AreEqual(pPacketTest.strValue, pPacketTest2.strValue);
    }