Esempio n. 1
0
 public void RemoveRef()
 {
     if (Interlocked.Decrement(ref m_RefCount) == 0)
     {
         FragmentPool.Return(this);
     }
 }
Esempio n. 2
0
 public bool TryReturn()
 {
     if (m_RefCount == 0)
     {
         FragmentPool.Return(this);
         return(true);
     }
     return(false);
 }
Esempio n. 3
0
        public static bool TryUnpack(byte[] buf, ref int offset, out UnreliableData data)
        {
            var channel  = BinaryUtil.ReadShort(buf, ref offset);
            var type     = buf[offset++];
            var sequence = BinaryUtil.ReadShort(buf, ref offset);
            var payload  = FragmentPool.Get();

            payload.Read(buf, ref offset);
            data = new UnreliableData(channel, sequence, payload);
            return(true);
        }
Esempio n. 4
0
        public static bool TryUnpack(byte[] buf, ref int offset, out ReliableData data)
        {
            var channel = BinaryUtil.ReadShort(buf, ref offset);

            if ((byte)Type != buf[offset++])
            {
                data = default;
                return(false);
            }
            var sequence        = BinaryUtil.ReadShort(buf, ref offset);
            var receiveSequence = BinaryUtil.ReadShort(buf, ref offset);
            var payload         = FragmentPool.Get();

            payload.Read(buf, ref offset);
            data = new ReliableData(channel, sequence, receiveSequence, payload);
            return(true);
        }
Esempio n. 5
0
 public static void GetFragments(byte[] buf, int offset, int size, short id, int fragmentSize, List <Fragment> list)
 {
     list.Clear();
     while (size > 0)
     {
         int count    = size > fragmentSize ? fragmentSize : size;
         var fragment = FragmentPool.Get();
         fragment.Id       = id;
         fragment.DataSize = (short)count;
         Buffer.BlockCopy(buf, offset, fragment.Data, 0, count);
         offset += count;
         size   -= count;
         list.Add(fragment);
     }
     for (short i = 0; i < list.Count; i++)
     {
         list[i].Index  = i;
         list[i].Length = (short)list.Count;
     }
 }