/// <summary> /// </summary> /// <param name="dataType"></param> /// <param name="data"></param> /// <param name="sender"></param> /// <returns></returns> public static byte[] BuildHeader(msgDataEncode dataType, byte[] data, msgSender sender) { int sizeHeader = 500; byte[] b = new byte[data.Length + sizeHeader]; b[0] = (byte)dataType; #region // msgSender int posSender = 100; b[posSender] = (byte)sender.Authentication; b[posSender + 1] = (byte)sender.Protocol; int sizeSenderInfo = 99; byte[] aEndPoint = GetBytesASCII(sender.EndPoint, sizeSenderInfo); byte[] aCodeAPI = GetBytesASCII(sender.CodeAPI, sizeSenderInfo); byte[] aUsername = GetBytesASCII(sender.Username, sizeSenderInfo); byte[] aPassword = GetBytesASCII(sender.Password, sizeSenderInfo); aEndPoint.CopyTo(b, posSender + 2); aCodeAPI.CopyTo(b, posSender + 2 + sizeSenderInfo); aUsername.CopyTo(b, posSender + 2 + (sizeSenderInfo * 2)); aPassword.CopyTo(b, posSender + 2 + (sizeSenderInfo * 3)); #endregion data.CopyTo(b, sizeHeader); return(b); }
/// <summary> /// </summary> public static byte[] Builder(msgDataEncode dataType, string data, msgSender sender) { byte[] a = new byte[0]; switch (dataType) { case msgDataEncode.string_utf8: a = Encoding.UTF8.GetBytes(data); break; case msgDataEncode.string_ascii: a = Encoding.ASCII.GetBytes(data); break; } byte[] b = BuildHeader(dataType, a, sender); return(b); }
/// <summary> /// </summary> public static byte[] Builder(msgDataEncode dataType, int data, msgSender sender) { byte[] a = BitConverter.GetBytes(data); byte[] b = BuildHeader(dataType, a, sender); return(b); }
/// <summary> /// </summary> public static byte[] Builder(msgDataEncode dataType, decimal data, msgSender sender) { byte[] a = GetBytes(data); byte[] b = BuildHeader(dataType, a, sender); return(b); }