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

Add cs:type support #782

Merged
merged 5 commits into from
Feb 4, 2022
Merged

Add cs:type support #782

merged 5 commits into from
Feb 4, 2022

Conversation

pepone
Copy link
Member

@pepone pepone commented Feb 3, 2022

This PR adds support for cs:type attribute, see #674

Currently it doesn't work with optional or tagged types, I will add that in a follow up PR.

Copy link
Member

@bernardnormier bernardnormier left a comment

Choose a reason for hiding this comment

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

Looks good.


public static class MyTimeSpanExtensions
{
public static void Encode(ref IceRpc.Slice.SliceEncoder encoder, TimeSpan value) =>
Copy link
Member

@bernardnormier bernardnormier Feb 3, 2022

Choose a reason for hiding this comment

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

The proposal was to use EncodeMyTimeSpan and DecodeMyTimeSpan. We already use these EncodeXxx/DecodeXxx names for generated enums, and they have the advantage to avoid ambiguity, especially for Decode.

The ambiguity can be an issue not for the generated code but for hand-written code using these extension methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed as per the proposal

@@ -16,9 +16,23 @@ module IceRpc::Tests::Slice
st: MyStruct,
}

[cs:type("System.TimeSpan")]
struct MyTimeSpan
Copy link
Member

Choose a reason for hiding this comment

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

What's actually nice with the proposal is you can name this compact struct simply TimeSpan and use TimeSpan (IceRpc::TimeSpan or maybe define it in a sub-module) in your Slice definitions, and it's mapped to System.TimeSpan in C#. MyTimeSpan is fine for the test.

Choose a reason for hiding this comment

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

Yeah I think it's fine; the MyXXX is practically standard for the tests at this point.

Copy link
Member

@InsertCreativityHere InsertCreativityHere left a comment

Choose a reason for hiding this comment

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

Looks good to me!

We check struct_ref.definition().has_attribute("cs:type", false) alot, so if you want to, you could add a helper method for this in slicec_ext/typeref_ext. Something like

is_custom_type(struct_ref: &TypeRef<Struct>) { ... }

Maybe that's not worth it though. Up to you.

tools/slicec-cs/src/cs_validator.rs Outdated Show resolved Hide resolved
tools/slicec-cs/src/cs_validator.rs Show resolved Hide resolved
tools/slicec-cs/src/struct_visitor.rs Outdated Show resolved Hide resolved
tests/IceRpc.Tests.Slice/StructTests.slice Outdated Show resolved Hide resolved
@@ -16,9 +16,23 @@ module IceRpc::Tests::Slice
st: MyStruct,
}

[cs:type("System.TimeSpan")]
struct MyTimeSpan

Choose a reason for hiding this comment

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

Yeah I think it's fine; the MyXXX is practically standard for the tests at this point.

tools/slicec-cs/src/encoding.rs Outdated Show resolved Hide resolved
pepone and others added 4 commits February 4, 2022 10:43
Co-authored-by: Austin Henriksen <austin.r.henriksen79@gmail.com>
Co-authored-by: Austin Henriksen <austin.r.henriksen79@gmail.com>
Co-authored-by: Austin Henriksen <austin.r.henriksen79@gmail.com>
@pepone pepone merged commit 1e690d4 into icerpc:main Feb 4, 2022
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.

3 participants