pub struct PayloadEncoding { /* private fields */ }Expand description
Open identity of the payload representation carried by a native frame.
A payload encoding is identified by up to three components:
registry_id: a numeric id registered with the uProtocol payload encoding registry. Ids1..=8are permanently reserved for the encodings historically expressed by the legacyUPayloadFormatenum (value-compatible with it),9..=0x7FFF_FFFFfor future registered encodings, and0x8000_0000..for vendor/private use.literal_id: a language-neutral literal identity such asup.stable-containerorup.xcdr-v2.content_type: an RFC 6838 media type, optionally with parameters, such asapplication/vnd.uprotocol.xcdr-v2;endianness=little;version=2.
At least one component must be present. Unlike the retired closed
UPayloadFormat enum, new encodings can be introduced without touching
any SDK enum: register a literal id (and optionally a numeric id), or
use a vendor media type.
The projection to and from the legacy enum is explicit and fallible:
PayloadEncoding::try_from_legacy_format and
PayloadEncoding::to_legacy_format.
Implementations§
Source§impl PayloadEncoding
impl PayloadEncoding
Sourcepub const PROTOBUF_WRAPPED_IN_ANY: PayloadEncoding
pub const PROTOBUF_WRAPPED_IN_ANY: PayloadEncoding
Protocol Buffers serialized payload wrapped in google.protobuf.Any.
Sourcepub const PROTOBUF: PayloadEncoding
pub const PROTOBUF: PayloadEncoding
Protocol Buffers serialized payload.
Sourcepub const JSON: PayloadEncoding
pub const JSON: PayloadEncoding
JSON payload.
Sourcepub const SOMEIP: PayloadEncoding
pub const SOMEIP: PayloadEncoding
SOME/IP serialized payload.
Sourcepub const SOMEIP_TLV: PayloadEncoding
pub const SOMEIP_TLV: PayloadEncoding
SOME/IP TLV serialized payload.
Sourcepub const RAW: PayloadEncoding
pub const RAW: PayloadEncoding
Raw binary payload.
Sourcepub const TEXT: PayloadEncoding
pub const TEXT: PayloadEncoding
UTF-8 text payload.
Sourcepub const SHM: PayloadEncoding
pub const SHM: PayloadEncoding
Shared-memory reference payload.
Sourcepub const LEGACY_COMPATIBLE: [PayloadEncoding; 8]
pub const LEGACY_COMPATIBLE: [PayloadEncoding; 8]
All encodings with registry ids permanently reserved for legacy
UPayloadFormat compatibility.
Sourcepub fn custom(
id: impl Into<String>,
content_type: impl Into<String>,
) -> Result<Self, UFrameMetadataError>
pub fn custom( id: impl Into<String>, content_type: impl Into<String>, ) -> Result<Self, UFrameMetadataError>
Creates a validated custom payload encoding from a literal id and a media type.
§Errors
Returns an error when id is empty, content_type is empty, or
content_type is not a valid media type.
Sourcepub fn from_parts(
registry_id: Option<u32>,
literal_id: Option<String>,
content_type: Option<String>,
) -> Result<Self, UFrameMetadataError>
pub fn from_parts( registry_id: Option<u32>, literal_id: Option<String>, content_type: Option<String>, ) -> Result<Self, UFrameMetadataError>
Creates a validated payload encoding from explicit identity components.
§Errors
Returns an error when all components are absent, when a present component is empty, or when the content type is not a valid media type.
Sourcepub fn registry_id(&self) -> Option<u32>
pub fn registry_id(&self) -> Option<u32>
Returns the registered numeric identity, if present.
Sourcepub fn literal_id(&self) -> Option<&str>
pub fn literal_id(&self) -> Option<&str>
Returns the literal identity, if present.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Returns the media type, if present.
Sourcepub fn custom_identity(&self) -> Option<(&str, &str)>
pub fn custom_identity(&self) -> Option<(&str, &str)>
Returns the custom encoding identity (literal_id, content_type) when
both are present.
Sourcepub fn is_compatible_with(&self, expected: &Self) -> bool
pub fn is_compatible_with(&self, expected: &Self) -> bool
Returns whether this encoding can be decoded by a codec expecting expected.
Sourcepub fn try_from_legacy_format(
format: UPayloadFormat,
) -> Result<Self, UFrameMetadataError>
pub fn try_from_legacy_format( format: UPayloadFormat, ) -> Result<Self, UFrameMetadataError>
Projects a legacy UPayloadFormat to its reserved registered encoding.
This is a compatibility projection: the returned encoding is the full registered identity (numeric id, literal id, and media type) reserved for the legacy value.
§Errors
Returns an error for UPayloadFormat::Unspecified, which is not a
concrete payload encoding.
Sourcepub fn to_legacy_format(&self) -> Option<UPayloadFormat>
pub fn to_legacy_format(&self) -> Option<UPayloadFormat>
Projects this encoding to the legacy UPayloadFormat, if it has a
legacy equivalent.
This is a compatibility projection for UMessage-shaped
boundaries. Encodings outside the reserved legacy range return None;
callers must treat that as “not representable”, never as Raw.
Trait Implementations§
Source§impl Clone for PayloadEncoding
impl Clone for PayloadEncoding
Source§fn clone(&self) -> PayloadEncoding
fn clone(&self) -> PayloadEncoding
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more