aboutsummaryrefslogtreecommitdiff
path: root/src/metadata.rs
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-10 06:57:12 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-10 06:57:12 +0000
commitba3dc4b8f2dc1922291274837dc3d2951a22ed3a (patch)
tree772fcd2e6530512a1c685e462bdea6a7acfeb75f /src/metadata.rs
parentc21902fbbc8837708a21f071a48ba962fdf0267c (diff)
parentb7a6f5938fe6c35af3cd9c0967485af224d3f873 (diff)
downloadgrpcio-android13-mainline-cellbroadcast-release.tar.gz
Change-Id: I48690a917107c328d61cdf9b7256fd87d145cfed
Diffstat (limited to 'src/metadata.rs')
-rw-r--r--src/metadata.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/metadata.rs b/src/metadata.rs
index 893f6e2..caaebc8 100644
--- a/src/metadata.rs
+++ b/src/metadata.rs
@@ -7,6 +7,8 @@ use std::{mem, slice, str};
use crate::error::{Error, Result};
+const BINARY_ERROR_DETAILS_KEY: &str = "grpc-status-details-bin";
+
fn normalize_key(key: &str, binary: bool) -> Result<Cow<'_, str>> {
if key.is_empty() {
return Err(Error::InvalidMetadata(
@@ -107,6 +109,13 @@ impl MetadataBuilder {
Ok(self.add_metadata(&key, value))
}
+ /// Set binary error details to support rich error model.
+ ///
+ /// See also https://grpc.io/docs/guides/error/#richer-error-model.
+ pub(crate) fn set_binary_error_details(&mut self, value: &[u8]) -> &mut MetadataBuilder {
+ self.add_metadata(BINARY_ERROR_DETAILS_KEY, value)
+ }
+
/// Create `Metadata` with configured entries.
pub fn build(mut self) -> Metadata {
unsafe {
@@ -214,6 +223,16 @@ impl Metadata {
metadata: p,
})
}
+
+ /// Search for binary error details.
+ pub(crate) fn search_binary_error_details(&self) -> &[u8] {
+ for (k, v) in self.iter() {
+ if k == BINARY_ERROR_DETAILS_KEY {
+ return v;
+ }
+ }
+ &[]
+ }
}
impl Clone for Metadata {