SocketHelper
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Runtime.CompilerServices;
namespace TestIt.helper
{
public static class SocketHelper
{
public static byte[] GetByteArrayFromStructure(byte[] CompleteStructure, int StartPosition, int length)
{
byte[] temp = new byte[length];
for (int ArrayCount = 0; ArrayCount < length; ArrayCount++)
{
temp[ArrayCount] = CompleteStructure[StartPosition + ArrayCount];
}
return temp;
}
public static char[] GetPreciseArrayForString(string Str, int ArraySize)
{
Str = Str.Replace('\0', ' ');
string temp = new string(' ', ArraySize);
temp = Str + temp;
temp = temp.Substring(0, ArraySize);
temp = temp.Replace(' ', '\0');
return temp.ToCharArray();
}
public static byte[] ConvertCharFrom16to8bit1(char[] CharArray)
{
byte[] temp = Encoding.ASCII.GetBytes(CharArray);
return temp;
}
public static byte[] GetBytesFromNumbers1(Int16 Number)
{
byte[] temp = BitConverter.GetBytes(Number);
return temp;
}
public static byte[] GetBytesFromNumbers1(Int32 Number)
{
byte[] temp = BitConverter.GetBytes(Number);
return temp;
}
public static T[] SubArray<T>(this T[] data, int index, int length)
{
T[] result = new T[length];
Array.Copy(data, index, result, 0, length);
return result;
}
public static string ByteString(this byte[] data)
{
string Message = Encoding.UTF8.GetString(data, 0, data.Length);
return Message.Replace('\0', ' ').Trim();
}
}
}
Comments
Post a Comment