| Crates.io | bomboni_proto |
| lib.rs | bomboni_proto |
| version | 0.2.0 |
| created_at | 2023-11-14 05:58:33.963457+00 |
| updated_at | 2025-11-10 12:53:19.972904+00 |
| description | Utilities for working with Protobuf/gRPC. Part of Bomboni library. |
| homepage | https://github.com/tinrab/bomboni |
| repository | https://github.com/tinrab/bomboni |
| max_upload_size | |
| id | 1034412 |
| size | 181,700 |
Utilities for working with Protobuf/gRPC. Part of Bomboni library.
This crate provides enhanced implementations of Google's well-known protobuf types with additional functionality beyond the standard prost-types.
It includes comprehensive support for serialization, conversion utilities, and WebAssembly compatibility.
Any type with type URL handlinguse bomboni_proto::google::protobuf::Any;
use bomboni_proto::google::rpc::ErrorInfo;
// Convert protobuf messages to Any type
let msg = ErrorInfo {
reason: "test".to_string(),
domain: "example".to_string(),
metadata: Default::default(),
};
let any_msg = Any::from_msg(&msg).unwrap();
// Convert back from Any to original type
let decoded: ErrorInfo = any_msg.to_msg().unwrap();
assert_eq!(decoded.reason, "test");
use bomboni_proto::google::rpc::{Status, Code, BadRequest, bad_request::FieldViolation};
use bomboni_proto::google::protobuf::Any;
// Create status with error details
let bad_request = BadRequest {
field_violations: vec![
FieldViolation {
field: "name".to_string(),
description: "Required field".to_string(),
}
],
};
let status = Status::new(
Code::InvalidArgument,
"Invalid request".to_string(),
vec![Any::from_msg(&bad_request).unwrap()],
);
// Convert to/from tonic status (with tonic feature)
#[cfg(feature = "tonic")]
{
use tonic::Status;
let tonic_status = Status::try_from(status).unwrap();
let converted_back = Status::try_from(tonic_status).unwrap();
}
use bomboni_proto::google::protobuf::FieldMask;
// Create field masks
let mask = FieldMask {
paths: vec!["user.name".to_string(), "user.email".to_string()],
};
// Field masks are commonly used in update operations
// to specify which fields should be updated
use bomboni_proto::google::rpc::ErrorInfo;
use serde_json;
// Error details support serde serialization
let error_info = ErrorInfo {
reason: "INVALID_ARGUMENT".to_string(),
domain: "my.api".to_string(),
metadata: Default::default(),
};
let json = serde_json::to_string(&error_info).unwrap();
let parsed: ErrorInfo = serde_json::from_str(&json).unwrap();
testing: Enable testing utilitiestonic: Enable integration with tonic gRPC librarychrono: Enable compatibility with chrono datetime librarywasm: Enable WebAssembly support and JavaScript bindingsjs: Enable JavaScript-specific type mappingsThis crate includes and enhances the following Google protobuf files:
google/protobuf/any.proto - Dynamic message typesgoogle/protobuf/timestamp.proto - Timestamp handlinggoogle/protobuf/duration.proto - Duration handlinggoogle/protobuf/empty.proto - Empty message typegoogle/protobuf/field_mask.proto - Field mask operationsgoogle/protobuf/struct.proto - Struct and value typesgoogle/protobuf/wrappers.proto - Wrapper types for primitivesgoogle/rpc/status.proto - RPC status and error handlinggoogle/rpc/code.proto - RPC status codesgoogle/rpc/error_details.proto - Detailed error information