Skip to content
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

Indexed fields as spans #780

Merged
merged 8 commits into from
May 16, 2020
Merged

Conversation

gatesy
Copy link
Contributor

@gatesy gatesy commented May 13, 2020

This PR exposes an array field as a ReadOnlySpan.

This was motivated by the need to store a GUID in a field. The natural way to do this is using a field of 16 bytes, which means the way to extract and encode it requires copying to an intermediate array. The C# GUID struct provides a ReadOnlySpan constructor, allowing us to create a GUID without copying to an intermediate byte buffer, e.g.:

var guid = new Guid(message.Guid);

and for encoding store:

var guidBytes = Guid.NewGuid().ToByteArray();

then set it using:

message.Guid = new ReadOnlySpan<byte>(guidBytes);

I've also added an AsSpan() method, to support writing directly from a Guid object to the underlying array. This allows you to write a Guid like this:

guid.TryWriteBytes(message.GuidAsSpan());

@mjpt777
Copy link
Contributor

mjpt777 commented May 15, 2020

@billsegall Do you have any views on this?

@billsegall
Copy link
Contributor

I think it's a useful helper function. I see no compatibility issues.

@gatesy
Copy link
Contributor Author

gatesy commented May 16, 2020

Could we get this change merged up and a new version of the sbe-tool NuGet package published? Is there anything I can help with to get this done?

@billsegall
Copy link
Contributor

billsegall commented May 16, 2020 via email

@mjpt777 mjpt777 merged commit 4c541ac into real-logic:master May 16, 2020
mjpt777 added a commit that referenced this pull request May 16, 2020
@billsegall
Copy link
Contributor

I've done a nuget release as 1.17.1. Consistent versioning across all backend languages is a little tricky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants