use oracledb_protocol::oson::OsonValue;
#[derive(Debug, Clone, Default)]
pub struct SodaDocument {
pub key: Option<String>,
pub content_bytes: Option<Vec<u8>>,
pub content_oson: Option<OsonValue>,
pub media_type: String,
pub version: Option<String>,
pub created_on: Option<String>,
pub last_modified: Option<String>,
}
impl SodaDocument {
pub fn from_bytes(content: Vec<u8>, key: Option<String>, media_type: Option<String>) -> Self {
SodaDocument {
key,
content_bytes: Some(content),
content_oson: None,
media_type: media_type.unwrap_or_else(|| "application/json".to_string()),
version: None,
created_on: None,
last_modified: None,
}
}
pub fn from_oson(content: OsonValue, key: Option<String>) -> Self {
SodaDocument {
key,
content_bytes: None,
content_oson: Some(content),
media_type: "application/json".to_string(),
version: None,
created_on: None,
last_modified: None,
}
}
pub fn content_as_bytes(&self) -> Option<&[u8]> {
self.content_bytes.as_deref()
}
pub fn content_as_oson(&self) -> Option<&OsonValue> {
self.content_oson.as_ref()
}
pub fn has_content(&self) -> bool {
self.content_bytes.is_some() || self.content_oson.is_some()
}
}