-
Notifications
You must be signed in to change notification settings - Fork 0
docs: update README usage section with serialize sample and blittable structs #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
google-labs-jules
wants to merge
4
commits into
main
Choose a base branch
from
jules-17471951661693468938-4938ae38
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a613f3c
docs: update README with serialize sample and blittable struct section
google-labs-jules[bot] e3dfff4
docs: address PR comments in README.md
google-labs-jules[bot] 9fbda9c
docs: address additional PR review feedback on README.md
google-labs-jules[bot] b1d1b88
docs: update README with TIP callout and remove redundant section
google-labs-jules[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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. | ||||
|
|
@@ -58,6 +63,35 @@ ReadOnlyMemory<byte> retainedData = packetView; | |||
| ``` | ||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||||
| ``` | ||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.