Compare commits

...

10 Commits

Author SHA1 Message Date
Harald Wolff 5ba98b1611 V1.10.0 2024-04-23 10:36:22 +02:00
Harald Wolff b6a965eec8 Changed version 2024-04-23 10:32:42 +02:00
Harald Wolff d01126396c Added conversion to/from byte[] from/into string 2024-04-23 10:32:13 +02:00
Harald Wolff 00d2fdec51 version 0.1.8
ln.build - build0.l--n.de build job pending Details
2021-07-10 02:20:53 +02:00
Harald Wolff 2c25cc6385 update version string
ln.build - build0.l--n.de build job pending Details
2021-07-10 02:18:42 +02:00
Harald Wolff 5ed8193971 IPv4: Add implicit casting to System.Net.IPAddress
ln.build - build0.l--n.de build job pending Details
2021-07-10 01:38:42 +02:00
Harald Wolff db015ed6db Add Minimalistic IPv4 class
ln.build - build0.l--n.de build job pending Details
2021-07-10 01:31:18 +02:00
Harald Wolff 7510e7296a Release 0.1.7
ln.build - build0.waldrennach.l--n.de build job pending Details
2020-12-28 08:41:10 +01:00
Harald Wolff 8bd39c3cc3 Added byte[].GetSingle() and byte[].GetDouble()
ln.build - build0.waldrennach.l--n.de build job pending Details
2020-12-12 17:56:15 +01:00
Harald Wolff b7a64b4609 Updated .gitignore
ln.build - build0.waldrennach.l--n.de build job pending Details
2020-12-09 14:28:03 +01:00
7 changed files with 95 additions and 4 deletions

1
.gitignore vendored
View File

@ -39,3 +39,4 @@ Thumbs.db
# dotCover
*.dotCover
.build

View File

@ -3,7 +3,7 @@
"dotnet"
],
"env": {
"NUGET_SOURCE": "https://nexus.niclas-thobaben.de/repository/l--n.de/",
"NUGET_SOURCE": "https://nexus.l--n.de/repository/ln.net/",
"CONFIGURATION": "Release"
},
"stages": [

View File

@ -62,6 +62,22 @@ namespace ln.type
}
public static uint GetUInt(this byte[] bytes, ref int offset, Endianess endianess) => BitConverter.ToUInt32(bytes.Slice(ref offset, 4).To(endianess), 0);
public static byte[] GetSingle(this byte[] bytes, ref int offset, out float value) => GetSingle(bytes, ref offset, out value, Endianess.LITTLE);
public static byte[] GetSingle(this byte[] bytes, ref int offset, out float value, Endianess endianess)
{
value = GetSingle(bytes, ref offset, endianess);
return bytes;
}
public static float GetSingle(this byte[] bytes, ref int offset, Endianess endianess) => BitConverter.ToSingle(bytes.Slice(ref offset, 4).To(endianess), 0);
public static byte[] GetDouble(this byte[] bytes, ref int offset, out double value) => GetDouble(bytes, ref offset, out value, Endianess.LITTLE);
public static byte[] GetDouble(this byte[] bytes, ref int offset, out double value, Endianess endianess)
{
value = GetDouble(bytes, ref offset, endianess);
return bytes;
}
public static double GetDouble(this byte[] bytes, ref int offset, Endianess endianess) => BitConverter.ToDouble(bytes.Slice(ref offset, 8).To(endianess), 0);
public static byte[] GetBytes(this byte[] bytes,ref int offset,int length,out byte[] value)
{

View File

@ -36,8 +36,14 @@ namespace ln.type
targetValue = value;
return true;
}
if (
if (targetType.Equals(typeof(byte[])) && value is string svalue)
{
targetValue = Convert.FromBase64String(svalue);
} else if (targetType.Equals(typeof(string)) && (value is byte[] bytes))
{
targetValue = Convert.ToBase64String(bytes);
} else if (
!Implicit(value, targetType, out targetValue) &&
!Implicit(value, value.GetType(), targetType, out targetValue) &&
!Explicit(value, targetType, out targetValue) &&

View File

@ -209,6 +209,28 @@ namespace ln.type
return BitConverter.ToDouble(bytes, 0);
}
public static string ReadCString(this Stream stream)
{
byte[] buffer = new byte[1024];
int p = 0, ch;
while ((ch = stream.ReadByte()) != -1)
{
if (ch == 0)
break;
if (p == buffer.Length)
{
byte[] nb = new byte[buffer.Length << 1];
Array.Copy(buffer, nb, buffer.Length);
buffer = nb;
}
buffer[p++] = (byte)ch;
}
return Encoding.UTF8.GetString(buffer, 0, p);
}

45
ln.type/IPv4.cs 100644
View File

@ -0,0 +1,45 @@
using System;
using System.Net;
namespace ln.type
{
public class IPv4
{
public static readonly IPv4 ANY = new IPv4();
private UInt32 _ip;
private IPv4()
{
}
public IPv4(UInt32 ip)
{
_ip = ip;
}
public IPv4(byte[] ipbytes)
{
_ip = BitConverter.ToUInt32(ipbytes, 0);
}
public byte[] ToBytes => BitConverter.GetBytes(_ip);
public override bool Equals(Object obj) => (obj is IPv4 other) && _ip == other._ip;
public override int GetHashCode() => (int)_ip;
public override string ToString()
{
byte[] ipbytes = ToBytes;
return string.Format("{0}.{1}.{2}.{3}", ipbytes[3], ipbytes[2], ipbytes[1], ipbytes[0]);
}
public static IPv4 operator ++(IPv4 ip) => new IPv4(ip._ip + 1);
public static IPv4 operator --(IPv4 ip) => new IPv4(ip._ip - 1);
public static IPv4 operator +(IPv4 ip, int n) => new IPv4((uint)(ip._ip + n));
public static IPv4 operator -(IPv4 ip, int n) => new IPv4((uint)(ip._ip - n));
public static implicit operator IPAddress(IPv4 ipv4) => new IPAddress(ipv4.ToBytes);
public static implicit operator IPv4(IPAddress ipAddress) => new IPv4(ipAddress.GetAddressBytes());
}
}

View File

@ -3,11 +3,12 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.1.6</Version>
<Version>0.1.9</Version>
<Authors>Harald Wolff-Thobaben</Authors>
<Company>l--n.de</Company>
<AssemblyVersion>0.0.1.0</AssemblyVersion>
<FileVersion>0.0.1.0</FileVersion>
<PackageVersion>0.1.10-preview0</PackageVersion>
</PropertyGroup>
<ItemGroup>