From a613f3c746f6feae675b5c3e084b22981b72f50f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 20 Aug 2026 22:06:12 +0000 Subject: [PATCH 1/4] docs: update README with serialize sample and blittable struct section --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index e80593c..6d94788 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,11 @@ public class Packet public string Name { get; } public int[] Values { get; } } + +// Serializing data into a buffer using generated 'Serialize' extension method. +var packet = new Packet { Id = 1, Name = "John", Values = new[] { 10, 20 } }; +var buffer = new byte[256]; +int writtenBytes = packet.Serialize(buffer); ``` View construction does not read every property. Values are decoded directly from the original memory only on access. @@ -58,6 +63,36 @@ ReadOnlyMemory retainedData = packetView; ``` +## Blittable Structs + +Structs marked with both `[ZeroSerializer]` and `[StructLayout(LayoutKind.Sequential, Pack = 1)]` are recognized as blittable structs. + +Blittable structs provide significant benefits: +- **No Offset Table**: Serialized directly as raw memory payloads without field offset overhead. +- **Instant Materialization**: Convert a View directly back to the original struct using the `.Materialize()` extension method. +- **Maximum Performance**: Fast direct memory copy operations with zero deserialization overhead. + +```csharp +[ZeroSerializer] +[StructLayout(LayoutKind.Sequential, Pack = 1)] +public struct Transform +{ + public float PositionX; + public float PositionY; + public float PositionZ; +} + +// Serializing a blittable struct (exact fixed byte size available via RequiredByteLength) +var transform = new Transform { PositionX = 1.0f, PositionY = 2.0f, PositionZ = 3.0f }; +var buffer = new byte[TransformView.RequiredByteLength]; +int writtenBytes = transform.Serialize(buffer); + +// Reading via View or materializing back to the original struct +var view = new TransformView(buffer); +Transform original = view.Materialize(); +``` + + From e3dfff4062b3359871be493faddf6cfb3ae53991 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 20 Aug 2026 22:42:09 +0000 Subject: [PATCH 2/4] docs: address PR comments in README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6d94788..73c5b5a 100644 --- a/README.md +++ b/README.md @@ -69,8 +69,7 @@ Structs marked with both `[ZeroSerializer]` and `[StructLayout(LayoutKind.Sequen Blittable structs provide significant benefits: - **No Offset Table**: Serialized directly as raw memory payloads without field offset overhead. -- **Instant Materialization**: Convert a View directly back to the original struct using the `.Materialize()` extension method. -- **Maximum Performance**: Fast direct memory copy operations with zero deserialization overhead. +- **Maximum Performance**: Fast direct memory copy operations with zero serialization/deserialization overhead. ```csharp [ZeroSerializer] @@ -84,7 +83,7 @@ public struct Transform // Serializing a blittable struct (exact fixed byte size available via RequiredByteLength) var transform = new Transform { PositionX = 1.0f, PositionY = 2.0f, PositionZ = 3.0f }; -var buffer = new byte[TransformView.RequiredByteLength]; +var buffer = new byte[TransformView.RequiredByteLength]; // 12 bytes int writtenBytes = transform.Serialize(buffer); // Reading via View or materializing back to the original struct From 9fbda9c12d2e642951b76d2b9a33f3036d6eca39 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 20 Aug 2026 23:00:12 +0000 Subject: [PATCH 3/4] docs: address additional PR review feedback on README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 73c5b5a..96a4dc3 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ public class Packet // Serializing data into a buffer using generated 'Serialize' extension method. var packet = new Packet { Id = 1, Name = "John", Values = new[] { 10, 20 } }; -var buffer = new byte[256]; +Span buffer = stackalloc byte[256]; int writtenBytes = packet.Serialize(buffer); ``` @@ -68,8 +68,8 @@ ReadOnlyMemory retainedData = packetView; Structs marked with both `[ZeroSerializer]` and `[StructLayout(LayoutKind.Sequential, Pack = 1)]` are recognized as blittable structs. Blittable structs provide significant benefits: -- **No Offset Table**: Serialized directly as raw memory payloads without field offset overhead. -- **Maximum Performance**: Fast direct memory copy operations with zero serialization/deserialization overhead. +- **No Offset Table**: Serialized directly as raw memory payloads without field offset table. +- **Maximum Performance**: Fast direct memory copy operations with zero overhead. ```csharp [ZeroSerializer] From b1d1b88ae3981a1a33c49c1e67bd676507a43565 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 21 Aug 2026 04:52:39 +0000 Subject: [PATCH 4/4] docs: update README with TIP callout and remove redundant section --- README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 96a4dc3..ab40d43 100644 --- a/README.md +++ b/README.md @@ -53,14 +53,8 @@ Span buffer = stackalloc byte[256]; int writtenBytes = packet.Serialize(buffer); ``` -View construction does not read every property. Values are decoded directly from the original memory only on access. - -The complete serialized region is also available through implicit conversion: - -```csharp -ReadOnlySpan serializedData = packetView; -ReadOnlyMemory retainedData = packetView; -``` +> [!TIP] +> View construction does not read every property. Values are decoded directly from the original memory only on access. ## Blittable Structs