I've just published my first-ever NuGet Package,
FastestBinaryStream. It's very simple - but that's largely the point!
FastestBinaryStream is an all-in-one fluent class for binary protocol implementation in C#. It foregoes safety checks, abstractions, and maintainability in favor of operating as quickly as mechanically possible.
Here's an example that uses it to convert a public key from its raw form into an SSH-formatted public key:
new BinaryStream(sizeof(int) + publicKeyAlgorithm.Length + sizeof(int) + publicKeyData.Length) .WriteBig(KeyType.Length) // write an integer in big-endian byte order .Write(Encoding.ASCII.GetBytes(publicKeyAlgorithm)) // write an array of bytes, verbatim .WriteBig(publicKeyData.Length) .Write(publicKey) .FlushBase64String(out var sshPublicKey) .Dispose();
Right now, it's my best guess based on past experience optimizing code. In the future, I hope to verify that it's achieving its goal by analyzing the IL it produces, and by running performance tests.
Contributions and feedback are welcome. There's a to-do list in the readme.