Skip to content

Commit fcabdb9

Browse files
authored
Merge pull request #32 from Kermalis/net7
2 parents d3c3359 + 0fea856 commit fcabdb9

27 files changed

+4074
-711
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
###############################################################################
22
# Set default behavior to automatically normalize line endings.
33
###############################################################################
4-
* text=auto
4+
* text eol=lf
55

66
###############################################################################
77
# Set default behavior for command prompt diff.

README.md

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ For example, classes and structs in C# cannot have ignored members when marshall
1616
The `EndianBinaryPrimitives` static class which resembles `System.Buffers.Binary.BinaryPrimitives` is an API that converts to/from data types using `Span<T>`/`ReadOnlySpan<T>` with specific endianness, rather than streams.
1717

1818
----
19-
## Changelog For v2.0.1
20-
Check the comment on [the release page](https://github.com/Kermalis/EndianBinaryIO/releases/tag/v2.0.1)!
21-
22-
## Changelog For v2.0.0
23-
Check the comment on [the release page](https://github.com/Kermalis/EndianBinaryIO/releases/tag/v2.0.0)!
19+
## Changelog For v2.1.0
20+
Check the comment on [the release page](https://github.com/Kermalis/EndianBinaryIO/releases/tag/v2.1.0)!
2421

2522
----
2623
## 🚀 Usage:
@@ -48,6 +45,7 @@ class MyBasicObj
4845
public ShortSizedEnum Type { get; set; }
4946
public short Version { get; set; }
5047
public DateTime Date { get; set; }
48+
public Int128 Int128 { get; set; }
5149

5250
// Property that is ignored when reading and writing
5351
[BinaryIgnore]
@@ -81,6 +79,7 @@ And assume these are our input bytes (in little endian):
8179
0x00, 0x08, // ShortSizedEnum.Val2
8280
0xFF, 0x01, // (short)511
8381
0x00, 0x00, 0x4A, 0x7A, 0x9E, 0x01, 0xC0, 0x08, // (DateTime)Dec. 30, 1998
82+
0x48, 0x49, 0x80, 0x44, 0x82, 0x44, 0x88, 0xC0, 0x42, 0x24, 0x88, 0x12, 0x44, 0x44, 0x25, 0x24, // (Int128)48,045,707,429,126,174,655,160,174,263,614,327,112
8483
8584
0x00, 0x00, 0x00, 0x00, // (uint)0
8685
0x01, 0x00, 0x00, 0x00, // (uint)1
@@ -115,6 +114,7 @@ var obj = new MyBasicObj();
115114
obj.Type = reader.ReadEnum<ShortSizedEnum>(); // Reads the enum type based on the amount of bytes of the enum's underlying type (short/2 in this case)
116115
obj.Version = reader.ReadInt16(); // Reads a 'short' (2 bytes)
117116
obj.Date = reader.ReadDateTime(); // Reads a 'DateTime' (8 bytes)
117+
obj.Int128 = reader.ReadInt128(); // Reads an 'Int128' (16 bytes)
118118
119119
obj.ArrayWith16Elements = new uint[16];
120120
reader.ReadUInt32s(obj.ArrayWith16Elements); // Reads 16 'uint's (4 bytes each)
@@ -141,6 +141,7 @@ var obj = new MyBasicObj
141141
Type = ShortSizedEnum.Val2,
142142
Version = 511,
143143
Date = new DateTime(1998, 12, 30),
144+
Int128 = Int128.Parse("48,045,707,429,126,174,655,160,174,263,614,327,112", NumberStyles.AllowThousands, NumberFormatInfo.InvariantInfo),
144145

145146
DoNotReadOrWrite = ByteSizedEnum.Val1,
146147

@@ -159,6 +160,7 @@ var writer = new EndianBinaryWriter(stream, endianness: Endianness.LittleEndian,
159160
writer.WriteEnum(obj.Type); // Writes the enum type based on the amount of bytes of the enum's underlying type (short/2 in this case)
160161
writer.WriteInt16(obj.Version); // Writes a 'short' (2 bytes)
161162
writer.WriteDateTime(obj.Date); // Writes a 'DateTime' (8 bytes)
163+
writer.WriteInt128(obj.Int128); // Writes an 'Int128' (16 bytes)
162164
writer.WriteUInt32s(obj.ArrayWith16Elements); // Writes 16 'uint's (4 bytes each)
163165
writer.WriteBoolean(obj.Bool32); // Writes a 'bool' (4 bytes in this case, since the reader's current bool state is BooleanSize.U32)
164166
@@ -170,25 +172,6 @@ writer.WriteChars_Count(obj.UTF16String, 10); // Writes 10 UTF16-LE chars as a '
170172
```
171173
### Writing Automatically (With Reflection):
172174
```cs
173-
var obj = new MyBasicObj
174-
{
175-
Type = ShortSizedEnum.Val2,
176-
Version = 511,
177-
Date = new DateTime(1998, 12, 30),
178-
179-
DoNotReadOrWrite = ByteSizedEnum.Val1,
180-
181-
ArrayWith16Elements = new uint[16]
182-
{
183-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
184-
},
185-
186-
Bool32 = false,
187-
188-
NullTerminatedASCIIString = "EndianBinaryIO",
189-
UTF16String = "Kermalis",
190-
};
191-
192175
var writer = new EndianBinaryWriter(stream, endianness: Endianness.LittleEndian);
193176
writer.Write(obj); // Write all properties in the 'MyBasicObj' in order, ignoring any with a 'BinaryIgnoreAttribute'
194177
// Other objects that are properties in this object will also be written in the same way recursively

Source/EndianBinaryIO.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<OutputType>Library</OutputType>
77
<RootNamespace>Kermalis.EndianBinaryIO</RootNamespace>
@@ -13,7 +13,7 @@
1313
<Title>EndianBinaryIO</Title>
1414
<PackageId>EndianBinaryIO</PackageId>
1515
<AssemblyName>EndianBinaryIO</AssemblyName>
16-
<Version>2.0.1</Version>
16+
<Version>2.1.0</Version>
1717
<RepositoryUrl>https://github.com/Kermalis/EndianBinaryIO</RepositoryUrl>
1818
<RepositoryType>git</RepositoryType>
1919
<Description>This .NET library provides a simple API to read/write bytes from/to streams and spans using user-specified endianness.
@@ -28,13 +28,13 @@ Project URL and Samples ― https://github.com/Kermalis/EndianBinaryIO</Descript
2828
<PackageTags>Serialization;Reflection;Endianness;LittleEndian;BigEndian;EndianBinaryIO</PackageTags>
2929
<PackageReadmeFile>README.md</PackageReadmeFile>
3030
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
31-
<PackageReleaseNotes>Version 2.0.1 Changelog:
32-
* Added TrimNullTerminators(ref char[] chars) and TrimNullTerminators(ref Span&lt;char&gt; chars) to EndianBinaryPrimitives which will remove all '\0' from the end
33-
* Added ReadSBytes(ReadOnlySpan&lt;byte&gt; src, Span&lt;sbyte&gt; dest) and WriteSBytes(Span&lt;byte&gt; dest, ReadOnlySpan&lt;sbyte&gt; src) to EndianBinaryPrimitives
34-
* Added heavily optimized enum methods to EndianBinaryPrimitives that use the same optimization techniques as the ones in EndianBinaryReader and EndianBinaryWriter
35-
* Added PeekBytes(Span&lt;byte&gt; dest) to EndianBinaryReader
31+
<PackageReleaseNotes># Version 2.1.0 Changelog:
32+
* .NET 7.0 support only.
33+
* Added methods for reading/writing `Int128`/`UInt128`.
34+
* Added `TrimNullTerminators(ref ReadOnlySpan&lt;char&gt; chars)` to `EndianBinaryPrimitives`.
35+
* Added "unsafe" methods to `EndianBinaryPrimitives` that read/write to/from `ReadOnlySpan&lt;T&gt;`/`Span&lt;T&gt;`. These are similar to their non-`_Unsafe` counterparts, aside from the fact that they don't check for errors. Their goal is performance.
3636

37-
No breaking changes from v2.0.0</PackageReleaseNotes>
37+
No breaking changes from v2.0.1</PackageReleaseNotes>
3838
</PropertyGroup>
3939

4040
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

0 commit comments

Comments
 (0)