using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*********************************************************************************************************
*
* 说明:
*
* 统一的数据转换中心,共有3种转换的机制
* 1. 对等转换,字节不需要颠倒,比如三菱PLC,Hsl通信协议
* 2. 颠倒转换,字节需要完全颠倒,比如西门子PLC
* 3. 以2字节为单位颠倒转换,比如Modbus协议
*
*********************************************************************************************************/
namespace MECF.Framework.Common.Net
{
///
/// 支持转换器的基础接口
///
public interface IByteTransform
{
#region Get Value From Bytes
///
/// 从缓存中提取出bool结果
///
/// 缓存数据
/// 位的索引
/// bool对象
bool TransBool( byte[] buffer, int index );
///
/// 从缓存中提取出bool数组结果
///
/// 缓存数据
/// 位的索引
/// bool长度
/// bool数组
bool[] TransBool( byte[] buffer, int index, int length );
///
/// 从缓存中提取byte结果
///
/// 缓存数据
/// 索引位置
/// byte对象
byte TransByte( byte[] buffer, int index );
///
/// 从缓存中提取byte数组结果
///
/// 缓存数据
/// 索引位置
/// 读取的数组长度
///
byte[] TransByte( byte[] buffer, int index, int length );
///
/// 从缓存中提取short结果
///
/// 缓存数据
/// 索引位置
/// short对象
short TransInt16( byte[] buffer, int index );
///
/// 从缓存中提取short数组结果
///
/// 缓存数据
/// 索引位置
/// 读取的数组长度
/// short数组对象
short[] TransInt16( byte[] buffer, int index, int length );
///
/// 从缓存中提取ushort结果
///
/// 缓存数据
/// 索引位置
/// ushort对象
ushort TransUInt16( byte[] buffer, int index );
///
/// 从缓存中提取ushort数组结果
///
/// 缓存数据
/// 索引位置
/// 读取的数组长度
/// ushort数组对象
ushort[] TransUInt16( byte[] buffer, int index, int length );
///
/// 从缓存中提取int结果
///
/// 缓存数据
/// 索引位置
/// int对象
int TransInt32( byte[] buffer, int index );
///
/// 从缓存中提取int数组结果
///
/// 缓存数据
/// 索引位置
/// 读取的数组长度
/// int数组对象
int[] TransInt32( byte[] buffer, int index, int length );
///
/// 从缓存中提取uint结果
///
/// 缓存数据
/// 索引位置
/// uint对象
uint TransUInt32( byte[] buffer, int index );
///
/// 从缓存中提取uint数组结果
///
/// 缓存数据
/// 索引位置
/// 读取的数组长度
/// uint数组对象
uint[] TransUInt32( byte[] buffer, int index, int length );
///
/// 从缓存中提取long结果
///
/// 缓存数据
/// 索引位置
/// long对象
long TransInt64( byte[] buffer, int index );
///
/// 从缓存中提取long数组结果
///
/// 缓存数据
/// 索引位置
/// 读取的数组长度
/// long数组对象
long[] TransInt64( byte[] buffer, int index, int length );
///
/// 从缓存中提取ulong结果
///
/// 缓存数据
/// 索引位置
/// ulong对象
ulong TransUInt64( byte[] buffer, int index );
///
/// 从缓存中提取ulong数组结果
///
/// 缓存数据
/// 索引位置
/// 读取的数组长度
/// ulong数组对象
ulong[] TransUInt64( byte[] buffer, int index, int length );
///
/// 从缓存中提取float结果
///
/// 缓存对象
/// 索引位置
/// float对象
float TransSingle( byte[] buffer, int index );
///
/// 从缓存中提取float数组结果
///
/// 缓存数据
/// 索引位置
/// 读取的数组长度
///
float[] TransSingle( byte[] buffer, int index, int length );
///
/// 从缓存中提取double结果
///
/// 缓存对象
/// 索引位置
/// double对象
double TransDouble( byte[] buffer, int index );
///
/// 从缓存中提取double数组结果
///
/// 缓存对象
/// 索引位置
/// 读取的数组长度
///
double[] TransDouble( byte[] buffer, int index, int length );
///
/// 从缓存中提取string结果,使用指定的编码
///
/// 缓存对象
/// 索引位置
/// byte数组长度
/// 字符串的编码
/// string对象
string TransString( byte[] buffer, int index, int length, Encoding encoding );
#endregion
#region Get Bytes From Value
///
/// bool变量转化缓存数据
///
/// 等待转化的数据
/// buffer数据
byte[] GetBytes( bool value );
///
/// bool数组变量转化缓存数据
///
/// 等待转化的数组
/// buffer数据
byte[] GetBytes( bool[] values );
///
/// byte变量转化缓存数据
///
/// 等待转化的数据
/// buffer数据
byte[] GetBytes( byte value );
///
/// short变量转化缓存数据
///
/// 等待转化的数据
/// buffer数据
byte[] GetBytes( short value );
///
/// short数组变量转化缓存数据
///
/// 等待转化的数组
/// buffer数据
byte[] GetBytes( short[] values );
///
/// ushort变量转化缓存数据
///
/// 等待转化的数据
/// buffer数据
byte[] GetBytes( ushort value );
///
/// ushort数组变量转化缓存数据
///
/// 等待转化的数组
/// buffer数据
byte[] GetBytes( ushort[] values );
///
/// int变量转化缓存数据
///
/// 等待转化的数据
/// buffer数据
byte[] GetBytes( int value );
///
/// int数组变量转化缓存数据
///
/// 等待转化的数组
/// buffer数据
byte[] GetBytes( int[] values );
///
/// uint变量转化缓存数据
///
/// 等待转化的数据
/// buffer数据
byte[] GetBytes( uint value );
///
/// uint数组变量转化缓存数据
///
/// 等待转化的数组
/// buffer数据
byte[] GetBytes( uint[] values );
///
/// long变量转化缓存数据
///
/// 等待转化的数据
/// buffer数据
byte[] GetBytes( long value );
///
/// long数组变量转化缓存数据
///
/// 等待转化的数组
/// buffer数据
byte[] GetBytes( long[] values );
///
/// ulong变量转化缓存数据
///
/// 等待转化的数据
/// buffer数据
byte[] GetBytes( ulong value );
///
/// ulong数组变量转化缓存数据
///
/// 等待转化的数组
/// buffer数据
byte[] GetBytes( ulong[] values );
///
/// float变量转化缓存数据
///
/// 等待转化的数据
/// buffer数据
byte[] GetBytes( float value );
///
/// float数组变量转化缓存数据
///
/// 等待转化的数组
/// buffer数据
byte[] GetBytes( float[] values );
///
/// double变量转化缓存数据
///
/// 等待转化的数据
/// buffer数据
byte[] GetBytes( double value );
///
/// double数组变量转化缓存数据
///
/// 等待转化的数组
/// buffer数据
byte[] GetBytes( double[] values );
///
/// 使用指定的编码字符串转化缓存数据
///
/// 等待转化的数据
/// 字符串的编码方式
/// buffer数据
byte[] GetBytes( string value, Encoding encoding );
#endregion
#region Public Properties
///
/// 获取或设置数据解析的格式,默认ABCD,可选BADC,CDAB,DCBA格式
///
DataFormat DataFormat { get; set; }
#endregion
}
}