Example #1
0
        public void WriteBuffer(ByteBuffer buffer)
        {
            EnsureCapacity(buffer.Length);

            System.Buffer.BlockCopy(buffer.Buffer, 0, Buffer, Position, buffer.Length);
            Position += buffer.Length;

            Length = BitArithmetic.Align(Math.Max(Position, Length), _align);
        }
Example #2
0
        public void WriteBytes(byte[] bytes)
        {
            EnsureCapacity(bytes.Length);

            System.Buffer.BlockCopy(bytes, 0, Buffer, Position, bytes.Length);
            Position += bytes.Length;

            Length = BitArithmetic.Align(Math.Max(Position, Length), _align);
        }
Example #3
0
        public void WriteUInt16(ushort value)
        {
            EnsureCapacity(2);

            Buffer[Position++] = (byte)value;
            Buffer[Position++] = (byte)(value >> 8);

            Length = BitArithmetic.Align(Math.Max(Position, Length), _align);
        }
Example #4
0
        public void WriteUInt64(ulong value)
        {
            EnsureCapacity(8);

            Buffer[Position++] = (byte)value;
            Buffer[Position++] = (byte)(value >> 8);
            Buffer[Position++] = (byte)(value >> 16);
            Buffer[Position++] = (byte)(value >> 24);
            Buffer[Position++] = (byte)(value >> 32);
            Buffer[Position++] = (byte)(value >> 40);
            Buffer[Position++] = (byte)(value >> 48);
            Buffer[Position++] = (byte)(value >> 56);

            Length = BitArithmetic.Align(Math.Max(Position, Length), _align);
        }
Example #5
0
        private void EnsureCapacity(int value)
        {
            if (Position + value <= Buffer.Length)
            {
                return;
            }

            int oldLength = Buffer.Length;
            int length    = BitArithmetic.Align(Math.Max(oldLength + value, oldLength * 2), _align);

            byte[] oldBuffer = Buffer;
            byte[] buffer    = new byte[length];

            System.Buffer.BlockCopy(oldBuffer, 0, buffer, 0, oldLength);
            Buffer = buffer;
        }
Example #6
0
        public static byte[] ToZeroEndBytes(string @string)
        {
            int size = @string.Length + 1;

            return(ToBytes(@string, BitArithmetic.Align((uint)size, 4u)));
        }
Example #7
0
 public void WriteByte(byte value)
 {
     EnsureCapacity(1);
     Buffer[Position++] = value;
     Length             = BitArithmetic.Align(Math.Max(Position, Length), _align);
 }