Skip to main content

Module prost

Module prost 

Source
Available on crate feature prost only.
Expand description

Validation and decoding for messages encoded with protobuf using prost

use hedwig::validators::prost::{ProstValidator, ProstDecoder, ExactSchemaMatcher};

#[derive(Clone, PartialEq, ::prost::Message)]
struct MyMessage {
    #[prost(string, tag = "1")]
    payload: String,
}
let schema = "my-message.proto";

let message = MyMessage {
    payload: "foobar".to_owned(),
};

// Demonstrate a message going roundtrip through the validator and the decoder

let validator = ProstValidator::new();
let validated_message = validator.validate(
    Uuid::new_v4(),
    SystemTime::now(),
    schema,
    hedwig::Headers::default(),
    &message,
)?;

let decoder = ProstDecoder::new(
    ExactSchemaMatcher::<MyMessage>::new(schema)
);
let decoded_message = decoder.decode(validated_message)?;

assert_eq!(message, decoded_message);

Structs§

ExactSchemaMatcher
A SchemaMatcher which expects all incoming schemas to match exactly one string for the given message type
ProstDecoder
Validator that decodes data from protobuf payloads using prost.
ProstValidator
Validator that encodes data into protobuf payloads using prost.
ProstValidatorError
Errors that may occur when validating ProtoBuf messages.
SchemaMismatchError
An error indicating that a received message had a schema which did not match the deserialized message type

Enums§

ProstDecodeError
Errors that may occur when decoding ProtoBuf messages.

Traits§

SchemaMatcher
A means of asserting that an incoming message’s schema matches a given message type’s deserialized format.