Byter 1.2.0
See the version list below for details.
dotnet add package Byter --version 1.2.0
NuGet\Install-Package Byter -Version 1.2.0
<PackageReference Include="Byter" Version="1.2.0" />
paket add Byter --version 1.2.0
#r "nuget: Byter, 1.2.0"
// Install Byter as a Cake Addin
#addin nuget:?package=Byter&version=1.2.0
// Install Byter as a Cake Tool
#tool nuget:?package=Byter&version=1.2.0
Byter
Byte parse. Convert byte to object and object to byte
Usage
Namespace
using Byter
Types
byte, bool, byte[], short, ushort, int, uint, long, ulong, float, double, char, string, Vector2
Writer
using Byter; using System.Text; // Create instance var w = new Writer(); // Create default instance _ = new Writer(new byte[] { 1, 1, 1, 1 }); // Create instance with default data _ = new Writer(new Writer()); // Create instance and copy from existing Writer // Write data w.Write((char) 'A'); // Write char w.Write((int) 1024); // Write int w.Write((string) "Byter"); // Write string w.Write((string) "Byter", Encoding.ASCII); // Write string w.Write((byte[]) new byte[] { 1, 1, 1, 1 }); // Write bytes // Output byte[] bytes = w.GetBytes(); // Get writes in Byte[] List<byte> list = w.GetList(); // Get writes in List<byte> // Other int length = w.Length; // Returns the length of bytes written w.Dispose(); // Destroy the Writer object // Console output Console.WriteLine($"Write length: {length}"); Console.WriteLine($"Write bytes[] length: {bytes.Length}"); Console.WriteLine($"Write List<byte> length: {list.Count}"); w.Clear(); Console.WriteLine($"Clear writer..."); Console.WriteLine($"Write length: {w.Length}");
Reader
using Byter; using System.Text; // Create sample input var w = new Writer(); // Write sample datas w.Write((int) 1024); w.Write((byte) 255); w.Write((string) "Byter"); w.Write((byte[]) new byte[] { 1, 1, 1, 1 }); // Create instance var r = new Reader(ref w); // Create instance and copy buffer from existing Writer _ = new Reader(new byte[] { 1, 1, 1, 1 }); // Create instance with bytes (byte[]) // Read data int _int = r.Read<int>(); // Output: 1024 byte _byte = r.Read<byte>(); // Output: 255 string _string = r.Read<string>(); // Output: "Byter" byte[] _bytes = r.Read<byte[]>(); // Output: [ 1, 1, 1, 1 ] // Output bool success = r.Success; // Returns success if there was no error retrieving the data // Other int position = r.Position; // Return the read pointer position int length = r.Length; // Returns the length of buffer r.Seek(position); // Moves the read pointer to any existing index r.Dispose(); // Destroy the Reader object // Console output Console.WriteLine($"Int -> {_int} "); Console.WriteLine($"Byte -> {_byte} "); Console.WriteLine($"String -> {_string} "); Console.WriteLine($"Byte[] -> {_bytes} "); Console.WriteLine($"Success -> {success} "); Console.WriteLine($"Position -> {position} "); Console.WriteLine($"Length -> {length} ");
Warning
Internally, before data is written a prefix is added in front of it, so when reading it always compares the prefix of the (data type) you want to read with the strings in the read buffer. if the prefixes do not match then o (Reader. Success = False), eg. If you write an (int) and try to read a float (Reader.Success = False) because the prefix of an (int) is different from that of a (float), it is recommended to read all the data and at the end check the success, if it is (Reader.Success = False) then one or more data is corrupt. This means that Writer and Reader add dipping to your write and read data.
Sample
using Byter;
// writing
Writer writer = new();
writer.Write(1000); // index
writer.Write("{JSON}"); // content
writer.Write(new byte[]{ 1, 1, 1, 1 }); // image
// geting buffer
byte[] buffer = writer.GetBytes();
writer.Dispose(); // Destroy Writer
// reading
Reader reader = new(buffer);
int index = reader.Read<int>();
string json = reader.Read<string>();
byte[] image = reader.Read<byte[]>();
// Check error
if (!reader.Success) // IS FALSE
{
Console.WriteLine("*** ERROR ****");
return;
}
// Check success
Console.WriteLine("*** SUCCESS ****");
// Output
Console.WriteLine($"Index: {index}"); // output: 1000
Console.WriteLine($"JSON : {json }"); // output: JSON
Console.WriteLine($"Image: {image.Length}"); // output: 4
Console.WriteLine($"Status: {reader.Success}"); // output: True
// Making error
float delay = reader.Read<float>();
/*
WARNING:
if you reverse the reading order or try to read more data than added (Reader.Succes = False),
Remembering does not return exception when trying to read data that does not exist it just
returns the default construction, and (Reader.Success) will be assigned (False) */
if (reader.Success) // IS FALSE, THE IS NOT WRITED IN BUFFER
Console.WriteLine($"Delay: {delay}");
else // IS TRUE, THE DELAY NOT EXIST
Console.WriteLine($"Delay not exist");
// Output of status
Console.WriteLine($"Status: {reader.Success}"); // output: False
reader.Dispose(); // Destroy Reader
Install
Nuget SEE HERE
.NET CLI
dotnet add package Byter --version 1.2.0
Submodule
# Install - recommend a stable branch e.g. "1.x" or use a fork repository git submodule add --name byter --branch main https://github.com/alec1o/byter vendor/byter # Rebuilding - Download repository and link it in file location, must add this step in dotnet.yaml if using git submodule update --init # Update submodule - Update and load new repository updates git submodule update --remote # PATH # |__ vendor # | |__ byter # | |__ src # | |__ Byter.csproj # | # |__ app # | |__ app.csproj # | # |__ app.sln # |__ .git # |__ .gitignore # |__ .gitmodules # .NET link on .sln cd <PATH> dotnet sln add vendor/byter/src/Byter.csproj # .NET link on .csproj cd app/ dotnet add reference ../vendor/byter/src/Byter.csproj # Rebuild dependencies to be linked in the project dotnet restore
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Byter:
Package | Downloads |
---|---|
Netly
Netly is a socket library for c# (C-Sharp). It facilitates the use of socket (UDP and TCP, Client and Server). Docs: https://netly.docs.kezero.com Sample: https://netly.docs.kezero.com/overview/quick-start Fork me: https://github.com/alec1o/Netly |
GitHub repositories
This package is not used by any popular GitHub repositories.
+ Read Vector2 type
+ Write Vector2 type
+ Improve .NET standard 2.0 to 2.1