Common Media Client Data (CMCD -- CTA-5004)
This cmcd crate provides functionality and types to read CMCD data from HTTP Header, Query Strings and JSON payloads, as specified by CTA-5004.
All you really need to checkout is the [Info] type. The following examples are taken from its documentation.
Example 1: Header Map
For now HTTP Headers are expected to be Key-Value String pairs. Check out the Planned Features if that may not satisfy your needs right now.
let header: = from;
let info = from_header_map.unwrap;
Example 2: Query String
Query parsing requires you to extract the query value from the query key CMCD and then pass it to either [Info::from_query_string] if the string is URL encoded or to [Info::from_raw_query_string] if it wasn't encoded.
let query: String =
Stringfrom;
let info = from_raw_query_string.unwrap;
// or with an URL encoded query
let encoded = encode;
let info = from_query_string.unwrap;
Example 3: JSON
JSON payloads can be parsed from either string with [Info::from_json] or from bytes with [Info::from_json_bytes].
let json = json!
.to_string;
let info = from_json.unwrap;
Planned Features
Here is a list of additions I intend to add to this crate in the future:
- Support for specific HTTP framework type, like
- Provide a builder pattern for creating new [Info] data
I am open to any other feature request and naturally contributions to the code base.