private static void WritePadding(Stream stream, int bytesWritten) { int num = DimeRecord.PaddedCount(bytesWritten) - bytesWritten; for (int i = 0; i < num; i++) { stream.WriteByte(0); } }
private static void ReadPadding(Stream stream, int bytesRead) { int num = DimeRecord.PaddedCount(bytesRead) - bytesRead; for (int i = 0; i < num; i++) { stream.ReadByte(); } }
private void WriteHeader(bool endOfRecord, bool endOfMessage, long contentLength) { byte[] array = new byte[12]; byte[] array2 = null; byte[] array3 = null; DimeRecord.HeaderFlagsEnum headerFlagsEnum = (DimeRecord.HeaderFlagsEnum) 0; if (this.m_chunked && !endOfRecord) { headerFlagsEnum = DimeRecord.HeaderFlagsEnum.ChunkedRecord; } if (this.m_beginOfMessage) { headerFlagsEnum |= DimeRecord.HeaderFlagsEnum.BeginOfMessage; this.m_beginOfMessage = false; } if (endOfMessage) { headerFlagsEnum |= DimeRecord.HeaderFlagsEnum.EndOfMessage; } TypeFormatEnum typeFormatEnum; Uri uri; string text; if (!this.m_chunked || this.m_firstChunk) { typeFormatEnum = this.m_typeFormat; uri = this.m_id; text = this.m_type; } else { typeFormatEnum = TypeFormatEnum.Unchanged; uri = null; text = null; } array[0] = (byte)(headerFlagsEnum | (DimeRecord.HeaderFlagsEnum) 8); array[1] = (byte)((byte)typeFormatEnum << 4); if (!this.m_chunked || this.m_firstChunk) { array[2] = 0; array[3] = 4; } int length; if (uri != null && (length = uri.AbsoluteUri.Length) > 0) { int byteCount = Encoding.ASCII.GetByteCount(uri.AbsoluteUri); if (byteCount > 65535) { throw new Exception(XmlaSR.DimeRecord_EncodedTypeLengthExceeds8191); } array3 = new byte[DimeRecord.PaddedCount(byteCount)]; Encoding.ASCII.GetBytes(this.m_id.AbsoluteUri, 0, length, array3, 0); array[4] = (byte)(byteCount >> 8); array[5] = (byte)byteCount; } if (text != null && text.Length > 0) { int byteCount = Encoding.ASCII.GetByteCount(text); if (byteCount > 65535) { throw new Exception(XmlaSR.DimeRecord_EncodedTypeLengthExceeds8191); } array2 = new byte[DimeRecord.PaddedCount(byteCount)]; Encoding.ASCII.GetBytes(text, 0, text.Length, array2, 0); array[6] = (byte)(byteCount >> 8); array[7] = (byte)byteCount; } if (contentLength > 0L) { array[8] = (byte)(contentLength >> 24 & 255L); array[9] = (byte)(contentLength >> 16 & 255L); array[10] = (byte)(contentLength >> 8 & 255L); array[11] = (byte)(contentLength & 255L); } this.m_stream.Write(array, 0, 12); if (array3 != null && array3.Length > 0) { this.m_stream.Write(array3, 0, array3.Length); } if (!this.m_chunked || this.m_firstChunk) { this.m_stream.Write(this.m_Options.GetBytes(), 0, 4); } if (array2 != null && array2.Length > 0) { this.m_stream.Write(array2, 0, array2.Length); } this.m_firstChunk = false; }