I Built a Serializer That Refuses to Own Your Data
How The Singularity Workshop turned a recurring binary-IO problem into a tiny .NET boundary—and why the smallest part of the design may be the most important part.
There is a particular kind of software problem that appears harmless at first.
You have some state.
You need to turn it into bytes.
So you write a serializer.
Then another part of the application needs bytes, so you add another serializer.
Then a cache needs them.
Then a manifest needs them.
Then a transport layer needs them.
Then somebody decides JSON is better here, binary is better there, and suddenly the architecture has six different opinions about what a piece of data is.
That was the problem I was running into while building The Singularity Workshop.
The interesting part is that I didn't actually need a giant serialization framework.
I needed a boundary.
So I built one.
It is called:
TheSingularityWorkshop.FSM_Serialization
And it is deliberately small.
That is the point.
The Problem Wasn't Turning Objects Into Bytes
Serialization is usually described as a mechanical operation:
object → serializer → bytes
That description hides something important.
An object has meaning.
Bytes do not.
Bytes are a representation of meaning.
That distinction becomes increasingly important as an architecture grows.
The Workshop ecosystem is being built around several deliberately separated responsibilities:
FSM_API
│
│ behavior and state
▼
FSM_COS
│
│ composition and runtime assembly
▼
FSM_Serialization
│
│ representation
▼
storage / transport / host
I didn't want FSM_COS to become a serializer.
I didn't want a MicroBundle to have to know how a filesystem works.
I didn't want a database abstraction hiding inside a representation layer.
And I definitely didn't want every higher-level system inventing its own binary stream interface.
So I extracted the smallest reusable boundary I could identify.
That boundary became FSM_Serialization.
The First Design Decision
The most important rule in the package is also the simplest:
The type that owns the meaning should own the representation rules.

FSM_Serialization provides the machinery for crossing the byte boundary.
It does not decide what your data means.
That means the package doesn't contain some enormous reflection-based object graph engine that looks at your class and decides what should be serialized.
Instead, the type explicitly says:
public interface IBinaryPackable
{
void Pack(IBinaryStream stream);
}
And the reverse direction is equally explicit:
public interface IBinaryUnpackable
{
void Unpack(IBinaryStream stream);
}
If a type needs both:
public interface IBinarySerializable :
IBinaryPackable,
IBinaryUnpackable
{
}
That's the entire conceptual model.
No magic.
No global serializer registry.
No reflection-based guesswork.
No framework deciding that a private field suddenly became part of your persistent format.
The domain owns that decision.
Why I Didn't Just Use System.IO.Stream
This is probably the first question a .NET developer will ask.
And honestly, it is a good question.
.NET already has System.IO.Stream.
Why introduce another interface?
Because I wasn't trying to replace Stream.
I was trying to establish a package-owned contract.
The current abstraction is:
public interface IBinaryStream : IDisposable
{
bool CanRead { get; }
bool CanWrite { get; }
long Position { get; set; }
long Length { get; }
int Read(Span<byte> buffer);
void Write(ReadOnlySpan<byte> buffer);
void Flush();
}
Notice what isn't there.
There is no:
- filename;
- filesystem;
- database;
- socket;
- HTTP request;
- serializer registry;
- schema;
- domain metadata;
- application configuration.
The interface only knows about the byte boundary.
That makes it possible to write serialization code against one very small abstraction while letting the host decide what is actually underneath it.
The Two Directions Matter
There is another small decision here that I think becomes important in larger systems.

Packing and unpacking are separate capabilities.
A type that produces a representation does not necessarily need to consume one.
Likewise, a type may consume a representation without being responsible for producing it.
So the package doesn't force everything into one giant:
Serialize()
Deserialize()
method.
Instead:
DOMAIN TYPE
│
┌──────────┴──────────┐
│ │
Pack Unpack
│ │
▼ ▲
representation representation
│ │
└──────────┬──────────┘
▼
byte stream
That separation costs almost nothing.
But architecturally, it keeps the ownership visible.
The Smallest Possible Example
Let's make this concrete.
Imagine a domain object containing one integer.
That's intentionally boring.
Boring is useful here because it lets us see exactly where the responsibility lives.
using System.Buffers.Binary;
using TheSingularityWorkshop.FSM_Serialization;
public sealed class ExampleState : IBinarySerializable
{
public int Value { get; private set; }
public ExampleState()
{
}
public ExampleState(int value)
{
Value = value;
}
public void Pack(IBinaryStream stream)
{
Span<byte> buffer = stackalloc byte[sizeof(int)];
BinaryPrimitives.WriteInt32LittleEndian(
buffer,
Value);
stream.Write(buffer);
}
public void Unpack(IBinaryStream stream)
{
Span<byte> buffer = stackalloc byte[sizeof(int)];
if (stream.Read(buffer) != buffer.Length)
throw new EndOfStreamException();
Value = BinaryPrimitives.ReadInt32LittleEndian(buffer);
}
}
There is no serializer object.
There is no configuration object.
There is no registration step.
The object itself defines its representation.
That is intentional.
Now Let's Actually Serialize Something
The package includes MemoryBinaryStream, which is exactly what it sounds like: an in-memory implementation of IBinaryStream.
That makes testing and temporary representations extremely simple.
using var stream = new MemoryBinaryStream();
var original = new ExampleState(42);
original.Pack(stream);
stream.Position = 0;
var restored = new ExampleState();
restored.Unpack(stream);
Console.WriteLine(restored.Value);
Output:
42
That's it.
The complete flow is:
ExampleState
│
│ Pack
▼
MemoryBinaryStream
│
│ bytes
▼
Position = 0
│
│ Unpack
▼
ExampleState
The package supplied the boundary.
The domain supplied the meaning.
Installation

If you want to try it yourself, the current published alpha is:
dotnet add package TheSingularityWorkshop.FSM_Serialization --version 0.1.0-alpha.2
Or:
<PackageReference
Include="TheSingularityWorkshop.FSM_Serialization"
Version="0.1.0-alpha.2" />
The current package targets .NET 8.
This is intentionally an alpha release.
That doesn't mean the contracts are casual.
Quite the opposite.
A binary representation is one of those things where small assumptions can become enormous compatibility problems later.
So I'm treating the package as alpha while treating its architectural boundaries seriously.
What About Real Files?

This is where StreamBinaryStream enters.
The package includes an adapter around an ordinary .NET Stream:
using var file = File.OpenRead("state.bin");
using var stream = new StreamBinaryStream(file);
Now the same domain serialization code can operate against the package abstraction without knowing that a file exists.
The relationship is:
ExampleState
│
▼
IBinaryStream
│
▼
StreamBinaryStream
│
▼
System.IO.Stream
│
▼
file / memory / whatever the host provides
That is a very different architecture from:
ExampleState
│
▼
ExampleStateSerializer
│
▼
FileSystemSerializerManager
│
▼
ApplicationStorageService
The latter might be useful somewhere.
It just doesn't belong in this package.
The Stream Adapter Is Supposed to Be Boring
This is one of those cases where boring code is a compliment.
StreamBinaryStream essentially delegates:
public int Read(Span<byte> buffer)
=> _stream.Read(buffer);
public void Write(ReadOnlySpan<byte> buffer)
=> _stream.Write(buffer);
public void Flush()
=> _stream.Flush();
That's not a weakness.
It's the point.
The adapter is not supposed to invent behavior.
It establishes a stable contract between two layers.
Then I Ran Into a Very Important Detail

A byte stream is not the same thing as an array.
This matters:
int count = stream.Read(buffer);
You cannot blindly assume:
count == buffer.Length
So a fixed-width decoder in FSM_Serialization explicitly checks:
if (stream.Read(buffer) != buffer.Length)
throw new EndOfStreamException();
That may look like a tiny implementation detail.
It isn't.
It establishes an architectural rule:
Never interpret an incomplete representation as a complete value.
The serializer shouldn't quietly manufacture missing data.
If the representation is incomplete, the domain implementation gets to decide what that means.
In the current examples, that means rejecting it.
Serialization Is Not Storage
This distinction became increasingly important as the Workshop architecture grew.
Consider these questions:
Serialization
How are these values represented as bytes?
Storage
Where do those bytes live?
Transport
How do those bytes move between boundaries?

Those are three different questions.
So:
SEMANTIC DATA
│
▼
representation
│
▼
FSM_Serialization
│
┌───────┴───────┐
▼ ▼
storage transport
A database is not a serializer.
A filesystem is not a serializer.
An HTTP endpoint is not a serializer.
A cache is not a serializer.
They may all consume serialized data.
That doesn't make them the same architectural layer.
This is exactly the kind of distinction that seems unnecessary when an application is small and becomes incredibly valuable when an ecosystem starts growing.
Why Binary?
I am not claiming that binary is universally superior to JSON.
It isn't.
JSON is fantastic for many things.
Text is fantastic for many things.
Human-readable configuration is valuable.
Debugging matters.
Authoring matters.
Interoperability with external systems matters.
The reason I created this package is narrower.
There are situations where I want an explicit, compact, byte-oriented representation.
For example:
- runtime state;
- manifests;
- dependency metadata;
- compact configuration;
- cache entries;
- identity records;
- version records;
- lineage metadata;
- persistence;
- transport payloads.
The important thing is that the semantic model shouldn't have to become identical to its wire representation.
Deterministic Does Not Mean Magical

The package's NuGet description talks about deterministic binary serialization.
There is an important qualification.
Implementing:
IBinaryPackable
does not magically make your representation deterministic.
You have to define deterministic rules.
For example, suppose your object contains a collection that is semantically unordered.
If you serialize it in whatever order happens to be present at runtime, two semantically identical objects could produce different byte sequences.
If deterministic bytes matter, the domain needs something like:
semantic collection
│
▼
canonical ordering
│
▼
explicit representation
│
▼
deterministic bytes
That distinction matters if bytes are later used for:
- caching;
- content identity;
- synchronization;
- comparison;
- reproducible builds;
- lineage;
- integrity checks.
Again, the package supplies the boundary.
It does not pretend to know your domain's canonical ordering rules.
Versioning Gets Interesting
This is another reason I didn't want a magical object serializer.
Once bytes leave your process, they can outlive the code that created them.
Imagine:
Application v1
│
▼
bytes
│
│ time passes
▼
Application v2
What happens?
That is a representation contract question.
A durable binary format may need to distinguish between:
semantic object version
format version
dependency version
Those are not necessarily the same thing.
Your semantic object can change while the representation remains compatible.
Your representation can change while the semantic concept remains the same.
A dependency can change independently of both.
FSM_Serialization intentionally doesn't impose one universal versioning strategy.
Different domains need different compatibility policies.
What it does is make the boundary explicit enough that you can actually have that conversation.
The Package Came From a Real Application

This is probably the most important part of the story.
FSM_Serialization wasn't created because I thought:
"The world needs another serialization library."
There are already plenty of serialization libraries.
The package emerged from building the Workshop itself.
The development pattern was:
working application
│
│ repeated infrastructure appears
▼
explicit contract
│
│ extract
▼
reusable package
│
│ consume again
▼
working application
That distinction matters.
I wasn't trying to abstract everything before I had a reason to abstract it.
The application became the proving ground.
Once the boundary became clear, I extracted it.
That is a much healthier way to create infrastructure.
And This Is Where FSM_COS Enters the Story
The larger ecosystem is becoming increasingly compositional.

FSM_COS is concerned with questions like:
What runtime composition was requested?
Which MicroBundles are required?
What dependencies are reachable?
How do those capabilities reconcile?
When is the composition stable enough to hand to a host?
FSM_Serialization answers a different question:
How do we represent the values that need to cross a byte boundary?
That means a future conceptual flow can look something like:
Runtime Manifest
│
▼
FSM_COS
│
│ composition
▼
Runtime Assembly
│
│ representation
▼
FSM_Serialization
│
▼
bytes
And then those bytes might eventually go somewhere else:
FSM_Serialization
│
┌──────────┼──────────┐
▼ ▼ ▼
storage transport cache
│ │ │
└──────────┼──────────┘
▼
host
The serializer doesn't become FSM_COS.
FSM_COS doesn't become a serializer.
That separation is exactly what I'm trying to preserve.
The Tests Tell the Same Story
The package currently has a deliberately small test surface.
It verifies things such as:
- an empty
MemoryBinaryStream is readable and writable;
- bytes survive a write/read round trip;
- existing byte arrays can initialize a memory stream;
- null input is rejected;
- end-of-input returns zero;
- positioning and overwriting work;
StreamBinaryStream delegates correctly;
- null wrapped streams are rejected;
- writes reach the underlying stream;
IBinaryPackable and IBinaryUnpackable can round-trip;
IBinarySerializable combines both contracts;
- incomplete binary input is rejected.
One of the tests is essentially the entire architectural idea in executable form:
var original = new TestValue(123456789);
using var stream = new MemoryBinaryStream();
original.Pack(stream);
stream.Position = 0;
var restored = new TestValue();
restored.Unpack(stream);
Assert.Equal(original.Value, restored.Value);
Tests aren't merely protecting the implementation here.
They are defining the boundary.
I Also Benchmarked It
Because eventually somebody is going to ask:
"Okay, but what does that abstraction cost?"
Good.
Let's measure it.
The companion benchmark project uses BenchmarkDotNet against .NET 8 and exercises payloads from 16 bytes through 100,000 bytes.
The interesting result isn't that FSM_Serialization magically beats MemoryStream.
It doesn't.
That's not what I was trying to prove.
The useful result is that the abstraction can remain extremely close to the underlying primitive for substantial workloads.
At 100,000 bytes, the benchmark measured approximately:
MemoryStream write:
39,894.85 ns
MemoryBinaryStream write:
40,005.59 ns
That's effectively the same scale.
Likewise, the adapter path was approximately:
MemoryStream read:
2,272.47 ns
StreamBinaryStream read:
2,298.40 ns
Again, very close.
And the end-to-end IBinarySerializable benchmark measured:
16 bytes 64.08 ns
1,024 bytes 207.47 ns
10,000 bytes 1,481.61 ns
100,000 bytes 60,152.74 ns
But there is an important qualification.
The benchmark measures the whole operation, including things like creating the test value, creating the stream, packing, rewinding, allocating the destination payload, and unpacking.
So I'm not going to pretend those numbers represent some universal "serialization speed."
They represent a measured workload.
That's much more useful.
The Benchmark Question I Actually Care About
The interesting engineering question isn't:
"Is my interface faster than MemoryStream?"
The interface isn't supposed to be the star of the show.
The question is:
Can I establish a useful architectural boundary without making the underlying operation prohibitively expensive?
The current measurements suggest that, for these workloads, the answer is yes.
And that's exactly where I want infrastructure to live.
The abstraction should be visible architecturally and nearly invisible computationally.
What I Deliberately Did Not Build
This may be the most important section of the entire package.
FSM_Serialization should not become:
- an FSM engine;
- a game framework;
- a GUI framework;
- a browser framework;
- a Unity integration layer;
- a database abstraction;
- a filesystem framework;
- an HTTP client;
- an application configuration system;
- a MicroBundle implementation;
- an Experience runtime;
- a reflection-driven object graph serializer;
- a global serializer registry.
Those things may all be useful.
They just aren't this thing.
That restraint is part of the architecture.
A small package becomes powerful when other systems can depend on it without having to inherit the systems it was never supposed to understand.
So What Would You Actually Use It For?
If you're building a .NET application and you have a domain type whose state needs to cross a byte-oriented boundary, the starting point is incredibly small.
Install the package:
dotnet add package TheSingularityWorkshop.FSM_Serialization --version 0.1.0-alpha.2
Define your representation:
public sealed class MyState : IBinarySerializable
{
public int Id { get; set; }
public void Pack(IBinaryStream stream)
{
Span<byte> buffer = stackalloc byte[sizeof(int)];
BinaryPrimitives.WriteInt32LittleEndian(
buffer,
Id);
stream.Write(buffer);
}
public void Unpack(IBinaryStream stream)
{
Span<byte> buffer = stackalloc byte[sizeof(int)];
if (stream.Read(buffer) != buffer.Length)
throw new EndOfStreamException();
Id = BinaryPrimitives.ReadInt32LittleEndian(buffer);
}
}
Use memory when you need a temporary representation:
using var stream = new MemoryBinaryStream();
state.Pack(stream);
byte[] bytes = stream.ToArray();
Use a normal .NET stream when the host provides one:
using var file = File.Create("state.bin");
using var stream = new StreamBinaryStream(file);
state.Pack(stream);
And that's basically the entire learning curve.
The difficult part isn't learning the API.
The difficult part is deciding what your domain actually means by its representation.
I think that's exactly where the difficult part belongs.
A Serializer Shouldn't Become Your Architecture
This is the idea that kept resurfacing while I built the package.
It's very easy for infrastructure to become the thing it was supposed to merely support.
A serializer starts storing metadata.
Then it starts deciding schemas.
Then it starts managing versions.
Then it starts talking to databases.
Then it starts managing transports.
Then it starts discovering domain types.
Eventually your "serialization library" is quietly running your architecture.
I wanted the opposite.
I wanted something I could put underneath the architecture and forget about until I actually needed to cross the boundary.
So the package can be reduced to one equation:
semantic state
+
explicit representation rules
+
byte boundary
=
portable representation
Not:
object
+
magic serializer
=
architecture
That's the difference.
The Boundary I Want to Preserve
The entire package can ultimately be reduced to this:
DOMAIN
│
owns meaning and rules
│
▼
Pack / Unpack contract
│
▼
FSM_Serialization
│
byte boundary
│
┌──────────┴──────────┐
▼ ▼
storage transport
│ │
└──────────┬──────────┘
▼
HOST
│
manifestation
The serializer owns the boundary.
The domain owns the meaning.
The host owns the destination.
That is the architecture.
Why I Think Small Infrastructure Is Worth Talking About
There is a tendency in software writing to focus on the enormous systems.
The massive framework.
The clever algorithm.
The huge benchmark.
The complicated application.
But some of the most consequential architectural decisions are tiny.
An interface.
A boundary.
A decision about ownership.
A decision about what a component doesn't know.
FSM_Serialization is one of those experiments.
It isn't trying to replace every serialization technology in .NET.
It isn't trying to declare that binary is the future.
It is much more modest:
I needed a clean byte boundary for a growing compositional architecture, so I built the smallest one I could.
Then I tested it.
Then I benchmarked it.
Then I packaged it.
And now I'm putting it out there so somebody else can kick it.
You Don't Have to Take My Word for It
That's ultimately why I publish these projects.
Install it.
Implement one type.
Serialize something you actually care about.
Put it under your own workload.
Decide whether the ownership model makes sense to you.
Measure it.
Break it.
Tell me where the boundary doesn't hold.
That's much more interesting to me than somebody simply agreeing with the architecture.
The package is available now as an alpha.
And if you find a place where this tiny boundary lets you remove a surprisingly large amount of architectural mess, I'd genuinely like to hear about it.
Resources & Code:
The FSM Package (Unity Asset Store):
https://assetstore.unity.com/packages/slug/332450
NuGet Packages:
https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API
https://www.nuget.org/packages/TheSingularityWorkshop.FSM_Serialization/
GitHub Repositories:
https://github.com/TrentBest/FSM_API
https://github.com/TrentBest/TheSingularityWorkshop.FSM_Serialization
Support Our Work:
Patreon Page:
https://www.patreon.com/c/TheSingularityWorkshop
Support Us (PayPal Donation):
https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J
We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.
