Last active
June 14, 2021 15:28
-
-
Save cab/86bf4ea772e792725a532584f1f69f2e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
syntax = "proto2"; | |
package ext; | |
import "google/protobuf/descriptor.proto"; | |
extend google.protobuf.FieldOptions { | |
optional bool required = 30004; | |
} | |
message HelloWorld { | |
optional string name = 1 [(ext.required) = true]; | |
} |
This file contains hidden or 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
pub struct RequiredExt { | |
} | |
impl ::prost::Extension for RequiredExt { | |
type Value = bool; | |
const NUMBER: i32 = 30004; | |
} | |
#[derive(Clone, PartialEq, ::prost::Message)] | |
pub struct HelloWorld { | |
#[prost(string, optional, tag="1")] | |
pub name: ::std::option::Option<std::string::String>, | |
} | |
impl HelloWorld { | |
pub fn name_ext<E>() -> ::std::option::Option<E::Value> where E: ::prost::Extension { | |
use ::prost::Message; | |
match E::NUMBER { | |
30004 => { | |
let mut message = E::Value::decode_length_delimited::<&[u8]>(&[2, 8, 1]).ok()?; | |
::std::option::Option::Some(message) | |
}, | |
_ => None | |
} | |
} | |
} |
This file contains hidden or 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
HelloWorld::name_ext<RequiredExt>() // Some(true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment