Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
Harald Wolff | 5ba98b1611 | |
Harald Wolff | b6a965eec8 | |
Harald Wolff | d01126396c | |
Harald Wolff | 00d2fdec51 | |
Harald Wolff | 2c25cc6385 | |
Harald Wolff | 5ed8193971 | |
Harald Wolff | db015ed6db | |
Harald Wolff | 7510e7296a | |
Harald Wolff | 8bd39c3cc3 | |
Harald Wolff | b7a64b4609 |
|
@ -39,3 +39,4 @@ Thumbs.db
|
|||
|
||||
# dotCover
|
||||
*.dotCover
|
||||
.build
|
||||
|
|
2
build.ln
2
build.ln
|
@ -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": [
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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) &&
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue