xbuffer.cs

来自「语音视频功能 里面实现了基本的QQ与语音对话」· CS 代码 · 共 34 行

CS
34
字号
using System;
using System.IO;

namespace Org.Mentalis.Security.Ssl.Shared {
	/// <summary>
	/// Creates a stream whose backing store is memory.
	/// </summary>
	/// <remarks>This class is created by Kevin Knoop.</remarks>
	internal class XBuffer : MemoryStream {
		/// <summary>
		/// Initializes a new instance of the XBuffer class with an expandable capacity initialized to zero.
		/// </summary>
		public XBuffer() : base() {
			//
		}
		/// <summary>
		/// Removes a number of leading bytes from the buffer.
		/// </summary>
		/// <param name="aByteCount">The number of bytes to remove.</param>
		/// <exception cref="ArgumentException"><paramref name="aByteCount"/> is invalid.</exception>
		public void RemoveXBytes(int aByteCount) {
			if (aByteCount > Length) {
				throw new ArgumentException("Not enough data in buffer");
			}
			if (aByteCount == Length) {
				SetLength(0);
			} else {
				byte[] buff = GetBuffer();
				Array.Copy(buff, aByteCount, buff, 0, (int)Length-aByteCount);
				SetLength(Length-aByteCount);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?