forked from tokio-rs/prost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
TypeUrl
trait + Any
encoding support
As discussed in tokio-rs#299, adds a `TypeUrl` trait which associates a type URL constant with a `Message` type. This enables adding methods to `Any` for decoding/encoding messages: - `Any::from_message`: encodes a given `Message`, returning `Any`. - `Any::to_message`: decodes `Any::value` as the given `Message`, first validating the message type has the expected type URL.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! Support for associating a type URL with a [`Message`]. | ||
use crate::Message; | ||
|
||
/// Associate a type URL with the given [`Message]`. | ||
pub trait TypeUrl: Message { | ||
/// Type URL for this [`Message`]. They take the form: | ||
/// | ||
/// ```text | ||
/// /<package>.<TypeName> | ||
/// ``` | ||
/// | ||
/// For example: | ||
/// | ||
/// ```text | ||
/// /foo.bar.baz.MyTypeName | ||
/// ``` | ||
const TYPE_URL: &'static str; | ||
} |