use serde::{Deserialize, Serialize};
use crate::protocol::JsonMessage;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "op", rename = "fetchAsset", rename_all = "camelCase")]
pub struct FetchAsset {
pub request_id: u32,
pub uri: String,
}
impl FetchAsset {
pub fn new(request_id: u32, uri: impl Into<String>) -> Self {
Self {
request_id,
uri: uri.into(),
}
}
}
impl JsonMessage for FetchAsset {}
#[cfg(test)]
mod tests {
use super::*;
fn message() -> FetchAsset {
FetchAsset::new(42, "package://foxglove/example.urdf")
}
#[test]
fn test_encode() {
insta::assert_json_snapshot!(message());
}
#[test]
fn test_roundtrip() {
let orig = message();
let buf = orig.to_string();
let parsed: FetchAsset = serde_json::from_str(&buf).unwrap();
assert_eq!(parsed, orig);
}
}