Skip to content
Draft
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 } };
Span<byte> 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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
View construction does not read every property. Values are decoded directly from the original memory only on access.
> [!TIP]
> View construction does not read every property. Values are decoded directly from the original memory only on access.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatted view construction note as a GitHub [!TIP] callout.

Expand All @@ -58,6 +63,35 @@ ReadOnlyMemory<byte> retainedData = packetView;
```

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed implicit conversion section as suggested.



## 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 table.
- **Maximum Performance**: Fast direct memory copy operations with zero 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]; // 12 bytes
int writtenBytes = transform.Serialize(buffer);

// Reading via View or materializing back to the original struct
var view = new TransformView(buffer);
Transform original = view.Materialize();
```





Expand Down
Loading