⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binary.cs

📁 短信网关的应用开发
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;

namespace SMPP.Variable
{
	/// <summary>
	/// 定长二进制传
	/// </summary>
	public class Binary : Variable
	{
		#region IVariable 成员

		/// <summary>
		/// 获取字节数组
		/// </summary>
		/// <returns></returns>
		public override byte[] GetBytes()
		{
			byte[] ret = new byte[_Value.Length];

			Array.Copy(_Value, ret, ret.Length);

			return ret;
		}

		/// <summary>
		/// 二进制串字节数
		/// </summary>
		public override int Length
		{
			get
			{
				return _Value.Length;
			}
		}

		public void SetLength(int Length)
		{
			byte[] NewData = new byte[Length];

			Array.Copy(_Value, NewData, Length > _Value.Length ? _Value.Length : Length);

			_Value = NewData;
		}

		/// <summary>
		/// 从字节数组中解析二进制串对象
		/// </summary>
		/// <param name="Datas">字节数组</param>
		/// <param name="Index">起始索引</param>
		public override void Parse(byte[] Datas, ref int Index)
		{
			int len;
			len = Datas.Length - Index > _Value.Length ? _Value.Length : Datas.Length - Index;
			Array.Clear(_Value, 0, _Value.Length);
			Array.Copy(Datas, Index, _Value, 0, len);

			Index += len;
		}

		#endregion
		
		/// <summary>
		/// 保存的真实数据
		/// </summary>
		protected byte[] _Value = new byte[0];

		public byte[] Value
		{
			get
			{
				return _Value;
			}
			set
			{
				Array.Clear(_Value, 0, _Value.Length);
				Array.Copy(value, 0, _Value, 0, value.Length >= _Value.Length ? _Value.Length : value.Length);
			}
		}

		public Binary(int Length)
		{
			_Value = new byte[Length];
		}
	}
}

⌨️ 快捷键说明

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