Esempio n. 1
0
 void WriteChunkSize(int size)
 {
     if (size > 0)
     {
         int bytesEncoded = IntEncoder.Encode(size, encodedSize, 0);
         base.Connection.Write(encodedSize, 0, bytesEncoded, false, TimeSpan.FromMilliseconds(WriteTimeout));
     }
 }
Esempio n. 2
0
        internal EncodedFramingRecord(FramingRecordType recordType, string value)
        {
            int valueByteCount = Encoding.UTF8.GetByteCount(value);
            int sizeByteCount  = IntEncoder.GetEncodedSize(valueByteCount);

            _encodedBytes    = Fx.AllocateByteArray(checked (1 + sizeByteCount + valueByteCount));
            _encodedBytes[0] = (byte)recordType;
            int offset = 1;

            offset += IntEncoder.Encode(valueByteCount, _encodedBytes, offset);
            Encoding.UTF8.GetBytes(value, 0, value.Length, _encodedBytes, offset);
            SetEncodedBytes(_encodedBytes);
        }
Esempio n. 3
0
        public static ArraySegment <byte> EncodeMessageFrame(ArraySegment <byte> messageFrame)
        {
            int spaceNeeded = IntEncoder.GetEncodedSize(messageFrame.Count);
            int offset      = messageFrame.Offset - spaceNeeded;

            if (offset < 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageFrame.Offset",
                                                                                                          messageFrame.Offset, SR.Format(SR.SpaceNeededExceedsMessageFrameOffset, spaceNeeded)));
            }

            byte[] buffer = messageFrame.Array;
            IntEncoder.Encode(messageFrame.Count, buffer, offset);
            return(new ArraySegment <byte>(buffer, offset, messageFrame.Count + spaceNeeded));
        }