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

Docs: Actor serialization documentation #1222

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

WhitWaldo
Copy link
Contributor

@WhitWaldo WhitWaldo commented Jan 6, 2024

Description

This is my first draft of a new page in the documentation detailing how serialization works using the Dapr .NET Actors SDK today. It's my response to the issue raised #679 which is marked as a bug, but reflects a misunderstanding of how the serialization engine handles records. My goal with adding this page is to provide an upfront resource for developers using actors to understand why serialization may not be working as expected out of the box and provide not only a solution, but an explanation.

I detail how serialization is performed to illustrate the benefits to either going the parameterless constructor route or decorating types and members with the applicable attributes and then share my recommendation to use attributes and why. I dive through several examples documenting expectations in classes, structs and records and then speak a bit to other related scenarios (collections, enums, polymorphic types) towards the end pointing back to the official documentation to keep this document from getting too verbose.

This is a documentation update only and changes no code in the SDK.

This replaces a previous PR in which I had a commit that had an invalid DCO.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #679

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

* [ ] Code compiles correctly
* [ ] Created/updated tests

  • Extended the documentation

@WhitWaldo WhitWaldo requested review from a team as code owners January 6, 2024 01:31
Copy link

codecov bot commented Jan 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (233c620) 68.47% compared to head (76d2ce3) 68.47%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1222   +/-   ##
=======================================
  Coverage   68.47%   68.47%           
=======================================
  Files         172      172           
  Lines        5846     5846           
  Branches      648      648           
=======================================
  Hits         4003     4003           
  Misses       1681     1681           
  Partials      162      162           
Flag Coverage Δ
net6 68.46% <ø> (ø)
net7 68.46% <ø> (ø)
net8 68.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…ontract serialization framework.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
@WhitWaldo WhitWaldo force-pushed the docs-datacontract-serialization branch from e4f49c5 to 76d2ce3 Compare January 15, 2024 19:29
Copy link
Collaborator

@philliphoff philliphoff left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution!

@philliphoff philliphoff merged commit d023a43 into dapr:master Jan 26, 2024
12 checks passed
@WhitWaldo WhitWaldo deleted the docs-datacontract-serialization branch January 26, 2024 21:41
@onionhammer
Copy link
Contributor

This doesn't mention JSON serialization, which IIRC is an option now?

@WhitWaldo
Copy link
Contributor Author

@onionhammer That's right. This was intended largely to speak to the issue raised in #679 to explain why data contract serialization and records regarding actors didn't appear to work automagically (and to speak to why the new primary class constructors might yield a similar experience), but I didn't dig into the JSON serialization route at all.

jamesmcroft pushed a commit to jamesmcroft/dotnet-sdk that referenced this pull request Feb 9, 2024
…ontract serialization framework. (dapr#1222)

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
Signed-off-by: James Croft <jamz_c@hotmail.co.uk>
jamesmcroft pushed a commit to jamesmcroft/dotnet-sdk that referenced this pull request Feb 16, 2024
…ontract serialization framework. (dapr#1222)

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
Signed-off-by: James Croft <jamz_c@hotmail.co.uk>
philliphoff added a commit that referenced this pull request Feb 16, 2024
* Added documentation detailing how serialization works using the DataContract serialization framework. (#1222)

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
Signed-off-by: James Croft <jamz_c@hotmail.co.uk>

* Weakly typed actor polymorphic and null responses (#1214)

Signed-off-by: Remco Blok <remco.blok@resilientenergy.com>
Co-authored-by: Remco Blok <remco.blok@resilientenergy.com>
Co-authored-by: Phillip Hoff <phillip@orst.edu>
Signed-off-by: James Croft <jamz_c@hotmail.co.uk>

* Enable vault name mapping and error suppression

Signed-off-by: Yash Nisar <yashnisar@microsoft.com>
Signed-off-by: James Croft <jamz_c@hotmail.co.uk>

* Add additional secret descriptor constructor for required without key map

Signed-off-by: James Croft <jamz_c@hotmail.co.uk>

* Update configuration load exception rethrow to match rules

Signed-off-by: James Croft <jamz_c@hotmail.co.uk>

* Add tests for required/not required exception handling

Signed-off-by: James Croft <jamz_c@hotmail.co.uk>

* Implementing Cryptography building block in .NET (#1217)

* Added method to DaprClient and GRPC implementation to call cryptography proto endpoints

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* First pass at implementing all exposed Cryptography methods on Go interface

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Added examples for Cryptography block

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Added missing copyright statements

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated to properly support Crypto API this time

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Added copyright statements

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Removed deprecated examples as the subtle APIs are presently disabled

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated example to reflect new API shape

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated example and readme

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Added overloads for encrypting/decrypting streams instead of just fixed byte arrays. Added example demonstrating the same encrypting a file via a FileStream and decrypting from a MemoryStream.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Added some unit tests to pair with the implementation

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Added null check for the stream argument

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Changed case of the arguments as they should read "plaintext" and not "plainText"

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Reduced number of encryption implementations by just wrapping byte array into memory stream

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Constrainted returned member types per review suggestion

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated methods to use ReadOnlyMemory<byte> instead of byte[] - updated implementations to use low-allocation spans where possible (though ToArray is necessary to wrap with MemoryStream).

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated to use encryption/decryption options instead of lots of method overload variations. Simplified gRPC implementation to use fewer methods. Applied argument name updates applied previously (plainText -> plaintext).

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated tests

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Removed unused reference

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated examples to reflect new method shapes. Downgraded package to .net 6 instead of .net 8 per review suggestion.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated to reflect non-aliased values per review suggestion

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Update to ensure that both send/receive streams run at the same time instead of sequentially.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated to support streamed results in addition to fixed byte arrays. Refactored implementation to minimize duplicative code.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated example to fix compile issue

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Removed encrypt/decrypt methods that accepted streams and returned ReadOnlyMemory<byte>. Marked implementations that use this on the gRPC class as private instead.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Added missing Obsolete attributes on Encrypt/Decrypt methods. Added overloads on decrypt methods that do not require a DecryptionOptions to be passed in.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated encrypt/decrypt options so the streaming block size no longer uses a uint. Added validation in its place to ensure the value provided is never less than or equal to 0.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated how validation works in the options to accommodate lack of the shorter variation in .NET 6

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated names of encrypt/decrypt streaming methods so everything uses just EncryptAsync or DecryptAsync

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Fixed regression that would have prevented data from being sent entirely to the sidecar. Also simplified operation per suggestion in review.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated examples to reflect changed API

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated so IAsyncEnumerable methods (encrypt and decrypt) return IAsyncEnumerable<ReadOnlyMemory<byte>> instead of IAsyncEnumerable<byte[]>.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated example to reflect change from IAsyncEnumerable<byte> to IAsyncEnumerable<ReadOnlyMemory<byte>>

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Avoiding allocation by using MemoryMarshal instead of .ToArray() to create MemoryStream from ReadOnlyMemory<byte>.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Performance updates to minimize unnecessary byte array copies and eliminate unnecessary allocations.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Removed unnecessary return from SendPlaintextStreamAsync and SendCiphertextStreamAsync methods

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated exception text to be more specific as to what's wrong with the input value.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Minor tweak to prefer using using a Memory

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Deduplicated some of the Decrypt methods, simplifying the implementation

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Eliminated duplicate encryption method, simplifying implementation

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated to eliminate an unnecessary `await` and `async foreach`.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Updated stream example to reflect the changes to the API shape

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

* Added notes about operations with stream-based data

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

---------

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
Signed-off-by: James Croft <jamz_c@hotmail.co.uk>

* Update DaprSecretDescriptor constructors and documentation

Signed-off-by: James Croft
Signed-off-by: James Croft <jamz_c@hotmail.co.uk>

* Remove DaprSecretStoreConfigurationProvider Console.WriteLine

Signed-off-by: James Croft <jamz_c@hotmail.co.uk>

---------

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
Signed-off-by: James Croft <jamz_c@hotmail.co.uk>
Signed-off-by: Remco Blok <remco.blok@resilientenergy.com>
Signed-off-by: Yash Nisar <yashnisar@microsoft.com>
Signed-off-by: James Croft
Co-authored-by: Whit Waldo <whit.waldo@innovian.net>
Co-authored-by: Remco Blok <remcoblok@hotmail.com>
Co-authored-by: Remco Blok <remco.blok@resilientenergy.com>
Co-authored-by: Phillip Hoff <phillip@orst.edu>
Co-authored-by: Yash Nisar <yashnisar@microsoft.com>
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.

Can't use C# 9.0 Record for actor method return type
3 participants