FluentPacket 1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package FluentPacket --version 1.0.0
NuGet\Install-Package FluentPacket -Version 1.0.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="FluentPacket" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FluentPacket --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FluentPacket, 1.0.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 FluentPacket as a Cake Addin #addin nuget:?package=FluentPacket&version=1.0.0 // Install FluentPacket as a Cake Tool #tool nuget:?package=FluentPacket&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Fluent Packet
Getting Started
/**
* Uses the default packet builder to easily build a data packet.
*/
using FluentPacket.Builder;
DefaultPacket message = new DefaultPacketBuilder()
.WithData<byte>(9)
.WithData(new byte[] { 3, 2, 1 })
.WithData<short>(2)
.Build();
packet.Serialize(out var bytes);
// Prints 9,3,2,1,2,0
Console.WriteLine(string.Join(",",bytes));
Defining Custom Packets
/**
* Now lets do something a little more robust
*/
// SimplePacket.cs
public class SimplePacket : FluentPacket.DefaultPacket
{
// Tags are identifiers for data used in conjuction with SetData and GetData
// The intent is to wrap your packet definitions in an implementation of DefaultPacket,
// so usage of Tags should be relegated to the wrapping class.
public enum Tags
{
DeviceId,
DeviceEnabled
}
public int DeviceId
{
get => GetData<int>((int)Tags.DeviceId);
set => SetData((int)Tags.DeviceId, value);
}
public bool DeviceEnabled
{
get => GetData<bool>((int)Tags.DeviceEnabled);
set => SetData((int)Tags.DeviceEnabled, value);
}
public SimplePacket WithDeviceId(int id)
{
DeviceId = id;
return this;
}
public SimplePacket WithDeviceEnabled(bool enabled)
{
DeviceEnabled = enabled;
return this;
}
}
// SimplePacketBuilder.cs
public class SimplePacketBuilder : FluentPacket.Builder<SimplePacket>
{
// SimplePacket Format: STX|DEVICE_ID|DEVICE_ENABLED|ETX
// Define your packet specification here. The hardcoded '|', 0x02, and 0x03
// don't need to be exposed to the user of a SimplePacket. Just bake them in
// to the definition of the packet and forget about it.
public override void Assemble()
{
const char delimiter = '|';
WithData<byte>(0x02)
.WithData(delimiter)
.WithData(0, (int)SimplePacket.Tags.DeviceId)
.WithData(delimiter)
.WithData(false, (int)SimplePacket.Tags.DeviceEnabled)
.WithData(delimiter)
.WithData<byte>(0x03);
}
}
// Program .cs
SimplePacket message = new SimplePacketBuilder()
.Produce()
.WithDeviceId(42)
.WithDeviceEnabled(false)
.Build();
packet.Serialize(out var bytes);
// Prints 2,124,42,0,0,0,124,0,124,3
Console.WriteLine(string.Join(",",bytes));
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- Newtonsoft.Json (>= 13.0.1)
-
net6.0
- Newtonsoft.Json (>= 13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial Release