Skip to content

Instantly share code, notes, and snippets.

@cab
Last active June 14, 2021 15:28
Show Gist options
  • Save cab/86bf4ea772e792725a532584f1f69f2e to your computer and use it in GitHub Desktop.
Save cab/86bf4ea772e792725a532584f1f69f2e to your computer and use it in GitHub Desktop.
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];
}
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
}
}
}
HelloWorld::name_ext<RequiredExt>() // Some(true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment