StructStreamKit.Web
0.9.23
dotnet add package StructStreamKit.Web --version 0.9.23
NuGet\Install-Package StructStreamKit.Web -Version 0.9.23
<PackageReference Include="StructStreamKit.Web" Version="0.9.23" />
<PackageVersion Include="StructStreamKit.Web" Version="0.9.23" />
<PackageReference Include="StructStreamKit.Web" />
paket add StructStreamKit.Web --version 0.9.23
#r "nuget: StructStreamKit.Web, 0.9.23"
#:package StructStreamKit.Web@0.9.23
#addin nuget:?package=StructStreamKit.Web&version=0.9.23
#tool nuget:?package=StructStreamKit.Web&version=0.9.23
Struct Streaming Kit
A comprehensive .NET library designed to simplify serialization and deserialization of objects to and from multiple well-known formats. It provides a consistent API across different serialization technologies while optimizing for performance and flexibility.
Overview
Struct Streaming Kit offers a unified approach to data serialization with support for both value types (structs) and reference types (classes). The library handles individual objects as well as collections, making it versatile for a wide range of use cases from data storage to API communication.
Supported Formats
- JSON: Uses System.Text.Json for high-performance JSON serialization
- Protocol Buffers: Implements Google's Protocol Buffers binary format using protobuf-net
- XML: XML serialization using .NET's built-in capabilities
- MessagePack: Compact binary serialization format optimized for performance
Key Features
- Unified API across all supported formats
- Support for both structs and classes
- Collections support (List<T>) for both structs and classes
- Schema generation for supported formats
- Seamless ASP.NET Core integration via output formatters
- Content negotiation based on Accept headers for responses and Content-Type for requests
- Full support for input and output formatting in ASP.NET Core applications
- Performance optimized serialization and deserialization
Target Frameworks
- Core Library: Targets
.NET7 - Web Extensions: Built for ASP.NET Core applications
- Compatible .NET 7, .NET 8, .NET 9
Installation
NuGet Package Manager (coming soon)
dotnet add package StructStreamKit
dotnet add package StructStreamKit.Web # For ASP.NET Core applications
Manual Installation
Clone the repository and reference the projects directly:
git clone https://github.com/Elixeum/lab-struct-stream-kit.git
Getting Started
Basic Usage
// Create a serializer instance
var jsonSerializer = SerializerFactory.CreateJsonSerializer();
var protoSerializer = SerializerFactory.CreateProtoSerializer();
var xmlSerializer = SerializerFactory.CreateXmlSerializer();
var messagePackSerializer = SerializerFactory.CreateMessagePackSerializer();
// Serialize an object
var person = new Person {
FirstName = "John",
LastName = "Doe",
Age = 30
};
// Serialize to the desired format
(byte[] bytes, string schema) = jsonSerializer.SerializeStruct(person);
// Deserialize back to object
Person deserializedPerson = jsonSerializer.DeserializeStruct<Person>(bytes);
Working with Collections
var people = new List<Person> {
new Person { FirstName = "John", LastName = "Doe", Age = 30 },
new Person { FirstName = "Jane", LastName = "Smith", Age = 28 }
};
// Serialize list
(byte[] bytes, string schema) = jsonSerializer.SerializeStructList(people);
// Deserialize back to list
List<Person> deserializedList = jsonSerializer.DeserializeStructList<Person>(bytes);
Examples
Console Application
The Terminal example demonstrates serializing and deserializing both individual objects and collections in all supported formats, with comparison of serialized data size and performance.
# Build and run the Console example
./build_run.sh # For Unix/Linux/macOS
build_run.ps1 # For Windows
The example:
- Creates sample
Personobjects and collections - Serializes them to all supported formats
- Reports on serialized data size
- Deserializes back to objects
- Validates data integrity by comparing with original objects
ASP.NET Core Web API
The WebAPI example demonstrates how to integrate StructStreamKit into an ASP.NET Core application with automatic content negotiation based on Accept headers.
Setup in Program.cs
// Register StructStreamKit formatters in your ASP.NET Core application
builder.Services.AddControllers()
.AddStructStreamFormattersAndInputFormatters(); // Adds both input and output formatters
Usage in Controllers
[ApiController]
[Route("api/[controller]")]
public class BooksController : ControllerBase
{
[HttpGet("{id}")]
public IActionResult GetBook(int id)
{
var book = new Book {
Title = "The Great Gatsby",
YearPublished = 1925,
ISBN = "9780743273565",
Price = 10.99m
};
// Return the object directly - the formatter will handle serialization
// based on the client's Accept header
return Ok(book);
}
[HttpGet]
public IActionResult GetBooks()
{
var books = new List<Book> {
new Book { Title = "The Great Gatsby", YearPublished = 1925, ISBN = "9780743273565", Price = 10.99m },
new Book { Title = "To Kill a Mockingbird", YearPublished = 1960, ISBN = "9780061120084", Price = 12.99m }
};
// Collections are also supported
return Ok(books);
}
}
Client Usage
Receiving Data
Clients can request specific response formats using the HTTP Accept header:
GET /api/books HTTP/1.1
Host: localhost:5000
Accept: application/json
GET /api/books HTTP/1.1
Host: localhost:5000
Accept: application/protobuf
Sending Data
Clients can send data in specific formats using the Content-Type header:
POST /api/books HTTP/1.1
Host: localhost:5000
Content-Type: application/json
Accept: application/json
{
"title": "The Great Gatsby",
"author": {
"id": "12345678-1234-1234-1234-123456789012",
"name": "F. Scott Fitzgerald",
"biography": "American novelist",
"dateOfBirth": "1896-09-24"
},
"yearPublished": 1925,
"genre": "Fiction",
"isbn": "9780743273565",
"pages": 180,
"publisher": "Scribner",
"language": "English",
"price": 10.99
}
POST /api/books HTTP/1.1
Host: localhost:5000
Content-Type: application/protobuf
Accept: application/protobuf
[Binary Protocol Buffer data]
Performance Considerations
- JSON: Best for human-readable data and web APIs
- Protocol Buffers: Most efficient for binary serialization with schema evolution support
- MessagePack: Best for high-speed, compact serialization when schema evolution is not required
- XML: Best for interoperability with older systems and when human readability is important
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 is compatible. 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 is compatible. 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 is compatible. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net7.0
- StructStreamKit (>= 0.9.21)
-
net8.0
- StructStreamKit (>= 0.9.21)
-
net9.0
- StructStreamKit (>= 0.9.21)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.9.23 | 2,475 | 5/6/2026 |
| 0.9.22 | 5,906 | 2/23/2026 |
| 0.9.20 | 5,736 | 12/9/2025 |
| 0.9.19 | 1,252 | 12/1/2025 |
| 0.9.18 | 1,024 | 11/27/2025 |
| 0.9.17 | 302 | 11/26/2025 |
| 0.9.16 | 236 | 11/25/2025 |
| 0.9.15 | 320 | 11/25/2025 |
| 0.9.14 | 411 | 11/19/2025 |
| 0.9.13 | 784 | 11/18/2025 |
| 0.9.12 | 1,321 | 11/4/2025 |
| 0.9.11 | 1,208 | 10/17/2025 |
| 0.9.10 | 1,029 | 10/9/2025 |
| 0.9.9 | 483 | 10/2/2025 |
| 0.9.8 | 1,044 | 9/24/2025 |
| 0.9.7 | 797 | 9/17/2025 |
| 0.9.6 | 325 | 9/17/2025 |
| 0.9.5 | 315 | 9/15/2025 |
| 0.9.4 | 3,444 | 7/15/2025 |
| 0.9.3 | 190 | 7/15/2025 |
CHANGELOG.md