FlatWire 1.1.0

dotnet add package FlatWire --version 1.1.0
                    
NuGet\Install-Package FlatWire -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="FlatWire" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FlatWire" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="FlatWire" />
                    
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 FlatWire --version 1.1.0
                    
#r "nuget: FlatWire, 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.
#:package FlatWire@1.1.0
                    
#: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=FlatWire&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=FlatWire&version=1.1.0
                    
Install as a Cake Tool

FlatWire (.NET)

Streaming JSON serialization that keeps memory flat and time linear. Stream large collections element-by-element instead of materializing the whole payload, so peak memory is bounded by the largest single element — not the collection size. Built on System.Text.Json; wire format is plain JSON.

Part of the cross-language flatwire project (identical API in Python, Node, .NET, Rust, Go, and Java).

Install

dotnet add package FlatWire

Usage

using FlatWire;

// Whole value
byte[] bytes = Flat.Encode(new { hello = "world" });
var value = Flat.Decode<MyType>(bytes);

// Stream a large collection — flat memory
Flat.EncodeArray(items, stream);
await foreach (var row in Flat.DecodeArray<Row>(stream))
{
    // one element at a time; the whole array is never in memory at once
}

API

Method Description
Encode<T>(value) value → byte[]
Decode<T>(data) bytes → value
EncodeTo<T>(value, stream) stream a single value out
DecodeFrom<T>(stream) read a single value
EncodeArray<T>(items, stream) stream a large collection
DecodeArray<T>(stream, ct?) IAsyncEnumerable<T> over a large array

Formats

Beyond JSON (default), the streaming array pair also speaks XML, binary MessagePack, and binary CBOR — same flat memory, separate helper classes:

FlatXml.EncodeArray(items, stream);
await foreach (var row in ...) { }              // FlatXml.DecodeArray(stream)
FlatMsgPack.EncodeArray(items, stream);          // FlatMsgPack.DecodeArray(stream)
FlatCbor.EncodeArray(items, stream);             // FlatCbor.DecodeArray(stream)

MessagePack and CBOR are byte-identical across all six flatwire languages (see the conformance matrix).

Checked streams

Partial-stream failure semantics: wrap a streamed array in an envelope whose terminal status is written last, so the consumer distinguishes clean completion, an in-band producer error after N rows, and truncation.

using FlatWire;

FlatChecked.EncodeCheckedArray(rows, stream);   // writes ...,"complete":true} last

try
{
    foreach (var row in FlatChecked.DecodeCheckedArray<Row>(stream))
        Handle(row);
}
catch (CheckedStreamException e) { /* producer failed after N rows */ }
catch (TruncatedStreamException) { /* stream ended without a terminal status */ }

The envelope is plain JSON, so a checked stream written in any flatwire language decodes in every other. See docs/FAILURE.md.

HTTP adapter

Stream a large collection to any Stream with flat memory; wire it into an ASP.NET Minimal API via the built-in Results.Stream:

app.MapGet("/rows", () =>
    Results.Stream(
        stream => { FlatHttp.WriteArray(GetRows(), stream, "cbor"); return Task.CompletedTask; },
        FlatHttp.MediaTypes["cbor"]));            // json | xml | msgpack | cbor

See docs/ADAPTERS.md.

License

Apache-2.0 — see the repository.

Benchmarks

See the live benchmark dashboard and the cross-language summary.

Changelog

See CHANGELOG.md.

Product Compatible and additional computed target framework versions.
.NET 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 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.  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.
  • net8.0

    • No dependencies.

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
1.1.0 97 8/10/2026
1.0.0 86 8/9/2026
0.10.0 89 8/9/2026
0.9.0 88 8/9/2026
0.8.0 88 8/9/2026
0.7.0 95 8/9/2026
0.6.0 91 8/9/2026
0.5.0 92 8/9/2026
0.4.0 94 8/9/2026
0.3.0 102 8/9/2026
0.2.0 96 8/9/2026
0.1.0 94 8/9/2026

0.4.0: streaming MessagePack binary format (FlatMsgPack) alongside JSON and XML; wire-compatible with standard MessagePack. Full changelog: https://github.com/flatwire-io/flatwire/blob/main/CHANGELOG.md