예제 #1
0
        /// <summary>
        /// Writes the chunk into a byte array.
        /// </summary>
        /// <param name="buffer">The byte array.</param>
        /// <param name="offset">The offset at which to start writing the chunk.</param>
        /// <returns>The number of bytes written.</returns>
        protected override int ToBuffer(byte[] buffer, int offset, out int dataLength)
        {
            dataLength = 0;

            int start = offset;

            offset += NetworkHelpers.CopyTo(this.CumulativeTSNAck, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.AdvertisedReceiverWindowCredit, buffer, offset);
            offset += NetworkHelpers.CopyTo((ushort)(this.GapAckBlocks == null ? 0 : this.GapAckBlocks.Count), buffer, offset);
            offset += NetworkHelpers.CopyTo((ushort)(this.DuplicateTSNs == null ? 0 : this.DuplicateTSNs.Count), buffer, offset);

            if (this.GapAckBlocks != null &&
                this.GapAckBlocks.Any())
            {
                foreach (var block in this.GapAckBlocks)
                {
                    offset += NetworkHelpers.CopyTo(block.GapAckBlockStart, buffer, offset);
                    offset += NetworkHelpers.CopyTo(block.GapAckBlockEnd, buffer, offset);
                }
            }

            if (this.DuplicateTSNs != null &&
                this.DuplicateTSNs.Any())
            {
                foreach (var dtsn in this.DuplicateTSNs)
                {
                    offset += NetworkHelpers.CopyTo(dtsn, buffer, offset);
                }
            }

            return(offset - start);
        }
예제 #2
0
        /// <summary>
        /// Writes the chunk parameter into a byte array.
        /// </summary>
        /// <param name="buffer">the byte array.</param>
        /// <param name="offset">The Offset at which to start writing the chunk parameter.</param>
        /// <returns>The number of bytes written.</returns>
        public int ToArray(byte[] buffer, int offset)
        {
            int start = offset;

            offset += NetworkHelpers.CopyTo((ushort)this.Type, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.Length, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.Value, buffer, offset);
            return(offset - start);
        }
예제 #3
0
        /// <summary>
        /// Writes the common header into a byte array at a given offset.
        /// </summary>
        /// <param name="buffer">The byte array</param>
        /// <param name="offset">The offset.</param>
        /// <returns>The number of bytes written to the byte array.</returns>
        public int ToArray(byte[] buffer, int offset)
        {
            int start = offset;

            offset += NetworkHelpers.CopyTo(this.SourcePort, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.DestinationPort, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.VerificationTag, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.Checksum, buffer, offset);
            return(offset - start);
        }
예제 #4
0
파일: CommonHeader.cs 프로젝트: sgf/SCTP
        /// <summary>
        /// Writes the common header into a byte array at a given offset.
        /// </summary>
        /// <param name="buffer">The byte array</param>
        /// <param name="offset">The offset.</param>
        /// <returns>The number of bytes written to the byte array.</returns>
        public int ToArray(byte[] buffer, int offset)
        {
            int start = offset;

            offset += NetworkHelpers.CopyTo(this.SrcPort, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.DstPort, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.VerTag, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.Chksum, buffer, offset);
            return(offset - start);
        }
예제 #5
0
        /// <summary>
        /// Writes the chunk into a byte array.
        /// </summary>
        /// <param name="buffer">The byte array.</param>
        /// <param name="offset">The offset at which to start writing the chunk.</param>
        /// <returns>The number of bytes written.</returns>
        protected override int ToBuffer(byte[] buffer, int offset, out int dataLength)
        {
            dataLength = 0;

            if (this.Type == ChunkType.Shutdown)
            {
                offset += NetworkHelpers.CopyTo(this.CumulativeTSNAck, buffer, offset);
                return(4);
            }

            return(0);
        }
예제 #6
0
        /// <summary>
        /// Writes the chunk into a byte array.
        /// </summary>
        /// <param name="buffer">The byte array.</param>
        /// <param name="offset">The offset at which to start writing the chunk.</param>
        /// <returns>The number of bytes written.</returns>
        protected override int ToBuffer(byte[] buffer, int offset, out int dataLength)
        {
            dataLength = this.UserData.Count;

            int start = offset;

            offset += NetworkHelpers.CopyTo(this.TSN, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.StreamId, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.StreamSeqNo, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.PayloadProtocolId, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.UserData, buffer, offset);
            return(offset - start);
        }
예제 #7
0
파일: Chunk.cs 프로젝트: sipsorcery/SCTP
        /// <summary>
        /// Outputs the chunk into a byte array.
        /// </summary>
        /// <param name="buffer">The byte array.</param>
        /// <param name="offset">The offset into the array to start writing the chunk.</param>
        /// <returns>The length of the chunk.</returns>
        public int ToArray(byte[] buffer, int offset)
        {
            int start = offset;

            this.Length = (ushort)this.CalculateLength(out int bufferSize);

            offset += NetworkHelpers.CopyTo((byte)this.Type, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.Flags, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.Length, buffer, offset);
            offset += this.ToBuffer(buffer, offset, out int dataLength);

            return(offset - start);
        }
예제 #8
0
        /// <summary>
        /// Writes the chunk into a byte array.
        /// </summary>
        /// <param name="buffer">The byte array.</param>
        /// <param name="offset">The offset at which to start writing the chunk.</param>
        /// <returns>The number of bytes written.</returns>
        protected override int ToBuffer(byte[] buffer, int offset, out int dataLength)
        {
            dataLength = 0;

            offset += NetworkHelpers.CopyTo(this.InitiateTag, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.AdvertisedReceiverWindowCredit, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.OutboundStreams, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.InboundStreams, buffer, offset);
            offset += NetworkHelpers.CopyTo(this.InitialTSN, buffer, offset);
            int paramsLength = 0;

            if (this.Parameters != null &&
                this.Parameters.Any())
            {
                foreach (var parm in this.Parameters)
                {
                    offset       += parm.ToArray(buffer, offset);
                    paramsLength += parm.Length;
                }
            }

            return(16 + paramsLength);
        }
예제 #9
0
 /// <summary>
 /// Writes the data to a byte array.
 /// </summary>
 /// <param name="buffer">The byte array</param>
 /// <param name="offset">The offset at which to write the data.</param>
 /// <returns>The number of bytes written.</returns>
 protected override int ToBuffer(byte[] buffer, int offset)
 {
     offset += NetworkHelpers.CopyTo(this.StreamId, buffer, offset);
     offset += NetworkHelpers.CopyTo(this.Reserved, buffer, offset);
     return(4);
 }
예제 #10
0
 protected override int ToBuffer(byte[] buffer, int offset, out int dataLength)
 {
     dataLength = 0;
     offset    += NetworkHelpers.CopyTo(this.Cookie, buffer, offset, false);
     return(this.Cookie.Length);
 }