-
Notifications
You must be signed in to change notification settings - Fork 10
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
Cleanup and pull in recent Java SDK features #28
Cleanup and pull in recent Java SDK features #28
Conversation
@@ -23,6 +23,58 @@ use crate::cloudevents::cloud_event::CloudEventAttributeValue; | |||
use crate::cloudevents::cloud_event::Data as CloudEventData; | |||
use crate::cloudevents::CloudEvent as CloudEventProto; | |||
|
|||
use crate::uprotocol::umessage::UMessage; | |||
use crate::uri::serializer::{LongUriSerializer, UriSerializer}; |
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.
IMHO it'd be nice if we're only using LongUriSerializer
to only have to use that one, i.e. only have to:
use crate::uri::serializer::{LongUriSerializer};
I think we can achieve that by modifying this line:
use crate::uri::serializer::{SerializationError, UriSerializer};
to
pub use crate::uri::serializer::{SerializationError, UriSerializer};
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.
Good catch!
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.
Addendum - this doesn't really work for some reason, dependent code still won't compile without explicitly use-ing the Trait implementation. I guess I'll revert this change for now.
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.
My bad! Looks like this is not possible in Rust. We have to bring the trait into scope explicitly with a use
. Seems this is a conscious design decision to help when multiple traits define things with the same names and helps readability to understand where a function could be coming from.
|
||
impl From<UMessage> for cloudevents::Event { | ||
fn from(source_event: UMessage) -> Self { | ||
let source = source_event.source.get_or_default(); |
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.
I noticed leaning on getting default and unwraps throughout.
I'm wondering if we should be doing any additional error checking and make it TryFrom instead to reflect that it may fail?
I suppose it depends on the context in which this will be used as well.
WDYT?
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.
we have a try_from now - However, next I will have to spend some quality time revisiting the test setup for cloudevent.rs, stay tuned for another change in that area.
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.
Tests redone, looking a bit more robust
attributes: UAttributes, | ||
method: UUri, | ||
request: UPayload, | ||
options: CallOptions, |
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.
👍
src/rpc/rpcmapper.rs
Outdated
let payload = response?; // Directly returns in case of error | ||
Any::try_from(payload) | ||
let message = response?; // Directly returns in case of error | ||
Any::try_from(message.payload.unwrap()) |
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.
Funnily enough, I was doing the same thing over in this PR 😆
We should probably be a little more careful here, similar to what I did on that PR s.t. we don't accidentally panic.
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.
Pulled that in - and apologies for waltzing over your work there!
let any = RpcMapper::pack_any(&status)?; | ||
Ok(any.try_into().unwrap()) | ||
let payload = |
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.
Again, funny we both did this haha
Kai gave some good feedback on that PR on how to handle this nicely, perhaps you could reference that?
src/uri/validator/urivalidator.rs
Outdated
/// # Returns | ||
/// | ||
/// Returns `true` if the `UAuthority` can be represented in micro format, `false` otherwise. | ||
pub fn is_micro_form_authority(authority: &UAuthority) -> bool { |
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.
This one I would pause on tho. IMHO it makes more sense to merge the PR I've got going for this functionality. That PR goes into a lot more detail in checking also that the fields from the UUri are able to fit the specified number of bits & bytes available.
If the PR I have for checking micro form goes through, that can then be mirrored back to up-java
.
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.
Removed!
Overall good to stay in sync with I'll go close this other PR doing just the invoke_method() -> UMessage bit. If you could remove that bit, I think we're good 👍 |
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.
Mapping error for priority that needs fixing
if let Some(token) = &attributes.token { | ||
event.set_extension("token", ExtensionValue::String(token.to_string())); | ||
} | ||
if let Ok(priority) = attributes.priority.enum_value() { |
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.
CloudEvent priority needs to be "CS1", "CS2" i.e string. I'm adding the mapping in core-api now so you can pull from proto but it is not an integer. eclipse-uprotocol/up-core-api#98
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.
I made the changes to achieve this - not yet based off the referenced PR, but manually. Will change that bit as soon as up-core-api#98 is merged.
@dakrbo let me know when this is ready for merge (lint & test failed) |
Will take a couple of days yet - need to revisit some test cases at the very least, plus want to wait for up-core-api 1.5.6
Will let you know once this is ready!
|
Ok; I did the test case rework that was necessary - now this needs a new/current tag in up-core-api, with the recent protobuf-options changes in. @stevenhartley are you planning to do a tag there soon? |
Yes I will do a release this week, not waiting for the other changes that I want to review at the generic uProtocol meeting on Thursday. |
@@ -41,7 +51,7 @@ pub trait UTransport { | |||
/// | |||
/// # Returns | |||
/// Returns () on success, otherwise an Err(UStatus) with the appropriate failure information. | |||
async fn send( | |||
async fn send_parts( |
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.
FMPOV we do not need this function now that we use UMessage
as the input parameter.
However, it seems that we are missing the Receive function required by the spec ...
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.
Agree and fixed
@@ -47,7 +47,7 @@ pub trait UTransport { | |||
/// On success, returns a tuple containing the received `UPayload` and `UAttributes` wrapped in `Ok(_)`. | |||
/// If receiving the message fails, it returns `Err(UStatus)`, | |||
/// where `UStatus` contains a `UCode` indicating the specific error or failure reason. | |||
async fn receive(&self, topic: UUri) -> Result<(UPayload, UAttributes), UStatus>; | |||
async fn receive(&self, topic: UUri) -> Result<UMessage, UStatus>; |
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.
The doc comment still refers to the original types. Which also is a good example for why you should not mention the types of parameters in the doc comments at all (they are obvious from the generated documentation anyway) ;-)
@AnotherDaniel There is no doubt that the changes in this PR are relevant and helpful 👍 Oh, and before I forget: you should probably make sure that you squash your changes into a few consistent commits before having the PR merged ... |
I'm still mentally working my way down from the all-encompassing initial commit, but point taken :) |
@PLeVasseur , I had to do a number on the MicroUriSerializer code, to make it work with up-core-api v1.5.6 - sorry to get in the way of of your #18 there, probably you can update that one to the same up-core-api and then take over my changes? |
Why do you want to remove the getters from UAuthority in the first place? Aren't they useful anymore? |
They now come with the generated code... |
@AnotherDaniel can you rebase this PR? |
ef1df37
to
d1839ce
Compare
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.
LGTM
@stevenhartley the changes you requested wrt up-core-api 1.5.6 (umessage option strings) are in now |
UTransport::registerListener()
using marker trait dispatch for message types + generic #60