Krypton.Buffers 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Krypton.Buffers --version 1.1.0                
NuGet\Install-Package Krypton.Buffers -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Krypton.Buffers" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Krypton.Buffers --version 1.1.0                
#r "nuget: Krypton.Buffers, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Krypton.Buffers as a Cake Addin
#addin nuget:?package=Krypton.Buffers&version=1.1.0

// Install Krypton.Buffers as a Cake Tool
#tool nuget:?package=Krypton.Buffers&version=1.1.0                

Krypton.Buffers

Types

The library ships with four types:

  • 2 Readers: SpanBufferReader and MemoryBufferReader (both sharing the same API)
  • 2 Writers: GrowingSpanBuffer and GrowingMemoryBuffer (both sharing the same API)

Currently the readers/writers support the following types:

  • Bool (bool stored as a byte)
  • Int8 (byte)
  • UInt8 (sbyte)
  • Int16 (short)
  • UInt16 (ushort)
  • Int32 (int)
  • UInt32 (uint)
  • Int64 (long)
  • UInt64 (ulong)
  • Float32 (float)
  • Float64 (double)
  • String8 (string in utf8)
  • Bytes (ReadOnlySpan<byte>/ReadOnlyMemory<byte>)
  • Guid (System.Guid)

There is a corresponding Read/Write method for each. Data is written in little endian

Features

Safe Allocation Free Buffer Writing with GrowingSpanBuffer

Example 1:

var buf = new GrowingSpanBuffer(stackalloc byte[64]); // initial buffer exists on the stack
buf.WriteUInt64(0);
buf.WriteString8("test");
Socket.Write(buf.Data);

Example 2:

var buf = new GrowingSpanBuffer(stackalloc byte[8]); // initial buffer exists on the stack
buf.WriteUInt64(0);
buf.WriteUInt64(0); // we resize on the heap here
Socket.Write(buf.Data);

Writer Bookmarks

Bookmarks are used for reserving a set number of bytes and writing to them later

Example:

var buf = new GrowingSpanBuffer(stackalloc byte[64]);

// strs is an IEnumerable<string>. Lets write the count after we enumerate through it
ushort count = 0;
var countBookmark = buf.ReserveBookmark(sizeof(ushort));
foreach (var str in strs)
{
    buf.WriteString8(str);
    count += 1;
}

// Now we can write the count
buf.WriteBookmark(countBookmark, count, BinaryPrimitives.WriteUInt16LittleEndian);

Reading Int Slices

The readers support reading slices of the following types:

  • Int16
  • UInt16
  • Int32
  • UInt32
  • Int64
  • UInt64

There is a Read{type}Slice method for each.

This method is allocation free on little endian machines.

Example:

var buf = new SpanBufferReader(data);

// Read 6 uint32s from the buffer
ReadOnlySpan<uint> ids = buf.ReadUInt32Slice(6);
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Krypton.Buffers:

Package Downloads
BeatTogether.Core.Messaging

Package Description

BeatTogether.LiteNetLib

Package Description

PocketSocket

Package Description

DcSharp

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 152 4/30/2024
2.0.3 5,538 3/5/2021
2.0.2 4,947 12/7/2020
2.0.1 870 12/2/2020
2.0.0 401 12/2/2020
1.1.0 2,360 5/6/2020
1.0.1 510 5/1/2020
1.0.0 505 5/1/2020