public override bool TryAdd(XmlDictionaryString s, out int key) { if (this.bytesRemaining == 0) { key = -1; return(false); } int byteCount = Encoding.UTF8.GetByteCount(s.Value); byteCount += IntEncoder.GetEncodedSize(byteCount); if (byteCount > this.bytesRemaining) { key = -1; this.bytesRemaining = 0; return(false); } if (!base.TryAdd(s, out key)) { return(false); } if (this.newStrings == null) { this.newStrings = new List <XmlDictionaryString>(); } this.newStrings.Add(s); this.bytesRemaining -= byteCount; return(true); }
private void WriteChunkSize(int size) { if (size > 0) { int bytesEncoded = IntEncoder.Encode(size, _encodedSize, 0); base.Connection.Write(_encodedSize, 0, bytesEncoded, false, TimeSpan.FromMilliseconds(this.WriteTimeout)); } }
private void WriteChunkSize(int size) { if (size > 0) { int num = IntEncoder.Encode(size, this.encodedSize, 0); base.Connection.Write(this.encodedSize, 0, num, false, TimeSpan.FromMilliseconds((double)this.WriteTimeout)); } }
private Task WriteChunkSizeAsync(int size) { if (size > 0) { int bytesEncoded = IntEncoder.Encode(size, _encodedSize, 0); return(base.Connection.WriteAsync(_encodedSize, 0, bytesEncoded, false, TimeSpan.FromMilliseconds(this.WriteTimeout))); } else { return(TaskHelpers.CompletedTask()); } }
internal EncodedFramingRecord(FramingRecordType recordType, string value) { int byteCount = Encoding.UTF8.GetByteCount(value); int encodedSize = IntEncoder.GetEncodedSize(byteCount); this.encodedBytes = DiagnosticUtility.Utility.AllocateByteArray((1 + encodedSize) + byteCount); this.encodedBytes[0] = (byte)recordType; int offset = 1; offset += IntEncoder.Encode(byteCount, this.encodedBytes, offset); Encoding.UTF8.GetBytes(value, 0, value.Length, this.encodedBytes, offset); this.SetEncodedBytes(this.encodedBytes); }
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); }
public static ArraySegment <byte> EncodeMessageFrame(ArraySegment <byte> messageFrame) { int encodedSize = IntEncoder.GetEncodedSize(messageFrame.Count); int offset = messageFrame.Offset - encodedSize; if (offset < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageFrame.Offset", messageFrame.Offset, System.ServiceModel.SR.GetString("SpaceNeededExceedsMessageFrameOffset", new object[] { encodedSize }))); } byte[] array = messageFrame.Array; IntEncoder.Encode(messageFrame.Count, array, offset); return(new ArraySegment <byte>(array, offset, messageFrame.Count + encodedSize)); }
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)); }
public static ArraySegment <byte> EncodeMessageFrame(ArraySegment <byte> messageFrame) { int spaceNeeded = 1 + IntEncoder.GetEncodedSize(messageFrame.Count); int offset = messageFrame.Offset - spaceNeeded; if (offset < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageFrame.Offset", messageFrame.Offset, SR.GetString(SR.SpaceNeededExceedsMessageFrameOffset, spaceNeeded))); } byte[] buffer = messageFrame.Array; buffer[offset++] = (byte)FramingRecordType.SizedEnvelope; IntEncoder.Encode(messageFrame.Count, buffer, offset); return(new ArraySegment <byte>(buffer, messageFrame.Offset - spaceNeeded, messageFrame.Count + spaceNeeded)); }
private ArraySegment <byte> AddSessionInformationToMessage(ArraySegment <byte> messageData, BufferManager bufferManager, int maxMessageSize) { int num = 0; byte[] array = messageData.Array; if (this.writerSession.HasNewStrings) { IList <XmlDictionaryString> newStrings = this.writerSession.GetNewStrings(); for (int i = 0; i < newStrings.Count; i++) { int byteCount = Encoding.UTF8.GetByteCount(newStrings[i].Value); num += IntEncoder.GetEncodedSize(byteCount) + byteCount; } int num4 = messageData.Offset + messageData.Count; int num5 = maxMessageSize - num4; if ((num5 - num) < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QuotaExceededException(System.ServiceModel.SR.GetString("MaxSentMessageSizeExceeded", new object[] { maxMessageSize }))); } int bufferSize = (messageData.Offset + messageData.Count) + num; if (array.Length < bufferSize) { byte[] dst = bufferManager.TakeBuffer(bufferSize); Buffer.BlockCopy(array, messageData.Offset, dst, messageData.Offset, messageData.Count); bufferManager.ReturnBuffer(array); array = dst; } Buffer.BlockCopy(array, messageData.Offset, array, messageData.Offset + num, messageData.Count); int num7 = messageData.Offset; for (int j = 0; j < newStrings.Count; j++) { string s = newStrings[j].Value; int num9 = Encoding.UTF8.GetByteCount(s); num7 += IntEncoder.Encode(num9, array, num7); num7 += Encoding.UTF8.GetBytes(s, 0, s.Length, array, num7); } this.writerSession.ClearNewStrings(); } int encodedSize = IntEncoder.GetEncodedSize(num); int offset = messageData.Offset - encodedSize; int count = (encodedSize + messageData.Count) + num; IntEncoder.Encode(num, array, offset); return(new ArraySegment <byte>(array, offset, count)); }