private ArraySegment <byte> CreatePreamble() { EncodedVia encodedVia = new EncodedVia(this.Via.AbsoluteUri); EncodedContentType encodedContentType = EncodedContentType.Create(this.MessageEncoder.ContentType); // calculate preamble length int startSize = ClientDuplexEncoder.ModeBytes.Length + SessionEncoder.CalcStartSize(encodedVia, encodedContentType); int preambleEndOffset = 0; if (_upgrade == null) { preambleEndOffset = startSize; startSize += ClientDuplexEncoder.PreambleEndBytes.Length; } byte[] startBytes = Fx.AllocateByteArray(startSize); Buffer.BlockCopy(ClientDuplexEncoder.ModeBytes, 0, startBytes, 0, ClientDuplexEncoder.ModeBytes.Length); SessionEncoder.EncodeStart(startBytes, ClientDuplexEncoder.ModeBytes.Length, encodedVia, encodedContentType); if (preambleEndOffset > 0) { Buffer.BlockCopy(ClientDuplexEncoder.PreambleEndBytes, 0, startBytes, preambleEndOffset, ClientDuplexEncoder.PreambleEndBytes.Length); } return(new ArraySegment <byte>(startBytes, 0, startSize)); }
private ArraySegment <byte> EncodeSessionPreamble() { EncodedVia via = new EncodedVia(this.Via.AbsoluteUri); EncodedContentType contentType = EncodedContentType.Create(this.encoder.ContentType); int bufferSize = (ClientSimplexEncoder.ModeBytes.Length + SessionEncoder.CalcStartSize(via, contentType)) + SessionEncoder.PreambleEndBytes.Length; byte[] dst = this.Factory.BufferManager.TakeBuffer(bufferSize); Buffer.BlockCopy(ClientSimplexEncoder.ModeBytes, 0, dst, 0, ClientSimplexEncoder.ModeBytes.Length); SessionEncoder.EncodeStart(dst, ClientSimplexEncoder.ModeBytes.Length, via, contentType); Buffer.BlockCopy(SessionEncoder.PreambleEndBytes, 0, dst, bufferSize - SessionEncoder.PreambleEndBytes.Length, SessionEncoder.PreambleEndBytes.Length); return(new ArraySegment <byte>(dst, 0, bufferSize)); }
ArraySegment <byte> EncodeSessionPreamble() { EncodedVia encodedVia = new EncodedVia(this.Via.AbsoluteUri); EncodedContentType encodedContentType = EncodedContentType.Create(this.encoder.ContentType); int startSize = ClientSimplexEncoder.ModeBytes.Length + SessionEncoder.CalcStartSize(encodedVia, encodedContentType) + ClientSimplexEncoder.PreambleEndBytes.Length; byte[] startBytes = this.Factory.BufferManager.TakeBuffer(startSize); Buffer.BlockCopy(ClientSimplexEncoder.ModeBytes, 0, startBytes, 0, ClientSimplexEncoder.ModeBytes.Length); SessionEncoder.EncodeStart(startBytes, ClientSimplexEncoder.ModeBytes.Length, encodedVia, encodedContentType); Buffer.BlockCopy(ClientSimplexEncoder.PreambleEndBytes, 0, startBytes, startSize - ClientSimplexEncoder.PreambleEndBytes.Length, ClientSimplexEncoder.PreambleEndBytes.Length); return(new ArraySegment <byte>(startBytes, 0, startSize)); }
private ArraySegment <byte> CreatePreamble() { EncodedVia via = new EncodedVia(this.Via.AbsoluteUri); EncodedContentType contentType = EncodedContentType.Create(base.MessageEncoder.ContentType); int size = ClientDuplexEncoder.ModeBytes.Length + SessionEncoder.CalcStartSize(via, contentType); int dstOffset = 0; if (this.upgrade == null) { dstOffset = size; size += SessionEncoder.PreambleEndBytes.Length; } byte[] dst = DiagnosticUtility.Utility.AllocateByteArray(size); Buffer.BlockCopy(ClientDuplexEncoder.ModeBytes, 0, dst, 0, ClientDuplexEncoder.ModeBytes.Length); SessionEncoder.EncodeStart(dst, ClientDuplexEncoder.ModeBytes.Length, via, contentType); if (dstOffset > 0) { Buffer.BlockCopy(SessionEncoder.PreambleEndBytes, 0, dst, dstOffset, SessionEncoder.PreambleEndBytes.Length); } return(new ArraySegment <byte>(dst, 0, size)); }