Ejemplo n.º 1
0
 /// <summary>
 /// Validates buffer capacity before writing into it.
 /// </summary>
 /// <param name="nextValueLength">Length of next bytes sequence to write into buffer.</param>
 private void ValidateBufferSize(int nextValueLength)
 {
     if (m_Offset + nextValueLength > m_Buffer.Length)
     {
         L2Buffer.Extend(ref m_Buffer, nextValueLength + m_DefaultOverflowValue);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Resizes <see cref="Packet"/> buffer to it's actual capacity and appends buffer length to the beginning of <see cref="Packet"/> buffer.
        /// </summary>
        /// <param name="headerSize"><see cref="Packet"/> header (opcodes) capacity.</param>
        public unsafe void Prepare(int headerSize)
        {
            m_Offset += headerSize;

            L2Buffer.Extend(ref m_Buffer, headerSize, m_Offset);

            fixed(byte *buf = m_Buffer)
            {
                if (headerSize == sizeof(short))
                {
                    *(( short * )(buf)) = ( short )m_Offset;
                }
                else
                {
                    *(( int * )(buf)) = m_Offset;
                }
            }
        }