mudbus_master_csharp project added directly to the solution

This commit is contained in:
Stoyan Zlatev
2023-09-04 13:38:00 +02:00
parent f83e576be3
commit 2adc8756bc
44 changed files with 9942 additions and 79 deletions
@@ -0,0 +1,41 @@
using System;
using System.Text;
using XYLEM.Communication;
namespace XYLEM.Communication.ValueEncoders
{
public static class StringEncoderUnicode
{
/// <summary>
/// Standard Windows 1252-encoding page.
/// </summary>
static Encoding s_Unicode = Encoding.BigEndianUnicode;
public static byte[] Encode(string value, int lenght)
{
if (value.Length > lenght)
{
throw new ArgumentException("value.Length is too long", "value");
}
var result = new byte[lenght];
s_Unicode.GetBytes(value).CopyTo(result, 0);
return result;
}
public static string Decode(byte[] value, int lenght)
{
if (value.Length > lenght)
{
throw new ArgumentException("value.Length wrong lenght", "value");
}
var result = s_Unicode.GetString(value);
var index = result.IndexOf('\0');
if (index >= 0)
return result.Substring(0, result.IndexOf('\0'));
else
return result;
}
}
}