StructStreamKit 0.9.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package StructStreamKit --version 0.9.6
                    
NuGet\Install-Package StructStreamKit -Version 0.9.6
                    
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="StructStreamKit" Version="0.9.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StructStreamKit" Version="0.9.6" />
                    
Directory.Packages.props
<PackageReference Include="StructStreamKit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add StructStreamKit --version 0.9.6
                    
#r "nuget: StructStreamKit, 0.9.6"
                    
#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.
#:package StructStreamKit@0.9.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=StructStreamKit&version=0.9.6
                    
Install as a Cake Addin
#tool nuget:?package=StructStreamKit&version=0.9.6
                    
Install as a Cake Tool

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 Person objects 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/x-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/x-protobuf
Accept: application/x-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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on StructStreamKit:

Package Downloads
StructStreamKit.Web

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.21 2,500 5/6/2026
0.9.20 5,922 2/23/2026
0.9.18 5,750 12/9/2025
0.9.17 1,278 12/1/2025
0.9.16 1,052 11/27/2025
0.9.15 326 11/26/2025
0.9.14 258 11/25/2025
0.9.13 388 11/25/2025
0.9.12 431 11/19/2025
0.9.11 805 11/18/2025
0.9.10 1,334 11/4/2025
0.9.9 1,218 10/17/2025
0.9.8 1,057 10/9/2025
0.9.7 1,345 9/24/2025
0.9.6 818 9/17/2025
0.9.5 348 9/17/2025
0.9.4 338 9/15/2025
0.9.3 3,471 7/15/2025
0.9.2 208 7/14/2025
0.9.1 170 7/11/2025
Loading failed

CHANGELOG.md