SoftBuffer 类 |
命名空间: HslCommunication.BasicFramework
SoftBuffer 类型公开以下成员。
名称 | 说明 | |
---|---|---|
SoftBuffer |
使用默认的大小(10个字节)初始化缓存空间 Initialize the cache space with the default size (10 bytes). | |
SoftBuffer(Int32) |
使用指定的容量初始化缓存数据块,长度以字节为单位 Initializes cache chunks with the specified capacity, with a length in bytes |
名称 | 说明 | |
---|---|---|
ByteTransform |
当前的数据变换机制,当你需要从字节数据转换类型数据的时候需要。 The current data transformation mechanism is required when you need to convert type data from byte data. | |
IsBoolReverseByWord |
获取或设置当前的bool操作是否按照字节反转 Gets or sets whether the current bool operation is reversed by bytes |
名称 | 说明 | |
---|---|---|
Dispose | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. | |
Dispose(Boolean) |
释放当前的对象
| |
Equals | Determines whether the specified object is equal to the current object. (继承自 Object。) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (继承自 Object。) | |
GetBool(Int32) |
获取指定的位置的bool值,如果超出,则引发异常 Get the bool value at the specified position, if it exceeds, an exception is thrown | |
GetBool(Int32, Int32) |
获取指定位置的bool数组值,如果超过,则引发异常 Get the bool array value at the specified position, if it exceeds, an exception is thrown | |
GetByte |
获取byte类型的数据 Get byte data | |
GetBytes |
获取内存所有的数据信息 Get all data information in memory | |
GetBytes(Int32, Int32) |
获取内存指定长度的数据信息 Get data information of specified length in memory | |
GetCustomerT |
读取自定义类型的数据,需要规定解析规则 Read custom types of data, need to specify the parsing rules | |
GetDouble(Int32) |
获取double类型的数据到缓存区 Get double type data to cache | |
GetDouble(Int32, Int32) |
获取double类型的数组到缓存区 Get double type array to cache | |
GetHashCode | Serves as the default hash function. (继承自 Object。) | |
GetInt16(Int32) |
获取short类型的数据到缓存区 Get short data to the cache | |
GetInt16(Int32, Int32) |
获取short类型的数组到缓存区 Get short type array to cache | |
GetInt32(Int32) |
获取int类型的数据到缓存区 Get int type data to cache | |
GetInt32(Int32, Int32) |
获取int类型的数组到缓存区 Get int type array to cache | |
GetInt64(Int32) |
获取long类型的数据到缓存区 Get long type data to cache | |
GetInt64(Int32, Int32) |
获取long类型的数组到缓存区 Get long type array to cache | |
GetSingle(Int32) |
获取float类型的数据到缓存区 Get float type data to cache | |
GetSingle(Int32, Int32) |
获取float类型的数组到缓存区 Get float type array to cache | |
GetType | Gets the Type of the current instance. (继承自 Object。) | |
GetUInt16(Int32) |
获取ushort类型的数据到缓存区 Get ushort type data to cache | |
GetUInt16(Int32, Int32) |
获取ushort类型的数组到缓存区 Get ushort type array to cache | |
GetUInt32(Int32) |
获取uint类型的数据到缓存区 Get uint type data to cache | |
GetUInt32(Int32, Int32) |
获取uint类型的数组到缓存区 Get uint type array to cache | |
GetUInt64(Int32) |
获取ulong类型的数据到缓存区 Get ulong type data to cache | |
GetUInt64(Int32, Int32) |
获取ulong类型的数组到缓存区 Get ulong type array to cache | |
MemberwiseClone | Creates a shallow copy of the current Object. (继承自 Object。) | |
SetBool(Boolean, Int32) |
设置指定的位置bool值,如果超出,则丢弃数据,该位置是指按照位为单位排序的 Set the bool value at the specified position, if it is exceeded, the data is discarded, the position refers to sorting in units of bits | |
SetBool(Boolean, Int32) |
设置指定的位置的bool数组,如果超出,则丢弃数据,该位置是指按照位为单位排序的 Set the bool array at the specified position, if it is exceeded, the data is discarded, the position refers to sorting in units of bits | |
SetBytes(Byte, Int32) |
设置指定的位置的数据块,如果超出,则丢弃数据 Set the data block at the specified position, if it is exceeded, the data is discarded | |
SetBytes(Byte, Int32, Int32) |
设置指定的位置的数据块,如果超出,则丢弃数据
Set the data block at the specified position, if it is exceeded, the data is discarded
| |
SetBytes(Byte, Int32, Int32, Int32) |
设置指定的位置的数据块,如果超出,则丢弃数据 Set the data block at the specified position, if it is exceeded, the data is discarded | |
SetCustomerT |
写入自定义类型的数据到缓存中去,需要规定生成字节的方法 Write custom type data to the cache, need to specify the method of generating bytes | |
SetValue(Byte, Int32) |
设置byte类型的数据到缓存区 Set byte type data to the cache area | |
SetValue(Double, Int32) |
设置double类型的数据到缓存区 Set double type data to the cache area | |
SetValue(Double, Int32) |
设置double数组的数据到缓存区 Set double array data to the cache area | |
SetValue(Int16, Int32) |
设置short类型的数据到缓存区 Set short type data to the cache area | |
SetValue(Int16, Int32) |
设置short数组的数据到缓存区 Set short array data to the cache area | |
SetValue(Int32, Int32) |
设置int类型的数据到缓存区 Set int type data to the cache area | |
SetValue(Int32, Int32) |
设置int数组的数据到缓存区 Set int array data to the cache area | |
SetValue(Int64, Int32) |
设置long类型的数据到缓存区 Set long type data to the cache area | |
SetValue(Int64, Int32) |
设置long数组的数据到缓存区 Set long array data to the cache area | |
SetValue(Single, Int32) |
设置float类型的数据到缓存区 Set float type data to the cache area | |
SetValue(Single, Int32) |
设置float数组的数据到缓存区 Set float array data to the cache area | |
SetValue(UInt16, Int32) |
设置ushort类型的数据到缓存区 Set ushort type data to the cache area | |
SetValue(UInt16, Int32) |
设置ushort数组的数据到缓存区 Set ushort array data to the cache area | |
SetValue(UInt32, Int32) |
设置uint类型的数据到缓存区 Set uint byte data to the cache area | |
SetValue(UInt32, Int32) |
设置uint数组的数据到缓存区 Set uint array data to the cache area | |
SetValue(UInt64, Int32) |
设置ulong类型的数据到缓存区 Set ulong byte data to the cache area | |
SetValue(UInt64, Int32) |
设置ulong数组的数据到缓存区 Set long array data to the cache area | |
ToString | Returns a string that represents the current object. (重写 ObjectToString.) |
名称 | 说明 | |
---|---|---|
ToJsonString |
获取当前对象的JSON格式表示的字符串。 (由 HslExtension 定义。)Gets the string represented by the JSON format of the current object. |
public class SoftBufferExample { private SoftBuffer softBuffer = new SoftBuffer( 1000 ); // 实例化个1000个byte长度的缓冲区 private Random random = new Random( ); public void SoftBufferExample1( ) { // 举例设置100-199长度的数据值 byte[] buffer = new byte[100]; random.NextBytes( buffer ); // 本语句是线程安全的,可以在任意的线程进行操作 softBuffer.SetBytes( buffer, 100 ); // 然后我们把数据进行读取出来,和上述的buffer是一致的 byte[] data = softBuffer.GetBytes( 100, 100 ); } public void SoftBufferExample2( ) { // 举例设置读取指定的数据类型的方法 int[] buffer = new int[10]; for (int i = 0; i < buffer.Length; i++) { buffer[i] = random.Next( 10000 ); } // 本语句是线程安全的,可以在任意的线程进行操作 softBuffer.SetValue( buffer, 100 ); // 然后我们把数据进行读取出来,和上述的buffer是一致的 int[] data = softBuffer.GetInt32( 100, 10 ); } // 其他的类型读写也是类似的,如果是自定义类型 public class UserData : IDataTransfer { public float temp1 = 0; public float temp2 = 0; public ushort temp3 = 0; public ushort ReadCount => 10; public void ParseSource( byte[] Content ) { temp1 = BitConverter.ToSingle( Content, 0 ); temp2 = BitConverter.ToSingle( Content, 4 ); temp3 = BitConverter.ToUInt16( Content, 8 ); } public byte[] ToSource( ) { byte[] buffer = new byte[10]; BitConverter.GetBytes( temp1 ).CopyTo( buffer, 0 ); BitConverter.GetBytes( temp2 ).CopyTo( buffer, 4 ); BitConverter.GetBytes( temp3 ).CopyTo( buffer, 8 ); return buffer; } } public void SoftBufferExample3( ) { // 举例设置读取自定义的数据类型 UserData userData = new UserData( ) { temp1 = 123.456f, temp2 = 1.23f, temp3 = 12345, }; // 本语句是线程安全的,可以在任意的线程进行操作 softBuffer.SetCustomer( userData, 100 ); // 然后我们把数据进行读取出来,和上述的buffer是一致的 UserData data = softBuffer.GetCustomer<UserData>( 100 ); } }