Expand description
DICOM JSON module
This library provides serialization of DICOM data to JSON and deserialization of JSON to DICOM data, as per the DICOM standard part 18 chapter F.
The easiest path to serialization is in
using the functions readily available to_string and to_value.
Alternatively, DICOM data can be enclosed by a DicomJson value,
which implements serialization and deserialization via Serde.
§Example
To serialize an object to standard DICOM JSON:
let obj = InMemDicomObject::from_element_iter([
InMemElement::new(tags::SERIES_DATE, VR::DA, "20230610"),
InMemElement::new(tags::INSTANCE_NUMBER, VR::IS, "5"),
]);
let json = dicom_json::to_string(&obj)?;
assert_eq!(
json,
r#"{"00080021":{"vr":"DA","Value":["20230610"]},"00200013":{"vr":"IS","Value":["5"]}}"#
);To turn DICOM JSON back into an in-memory object:
let json = r#"{
"00080021": { "vr": "DA", "Value":["20230610"] },
"00200013": { "vr": "IS", "Value":["5"] }
}"#;
let obj: InMemDicomObject = dicom_json::from_str(&json)?;Use the DicomJson wrapper type
for greater control on how to serialize or deserialize data:
let dicom_obj = dicom_json::DicomJson::from(&obj);
let serialized = serde_json::to_value(dicom_obj)?;
assert_eq!(
serialized,
serde_json::json!({
"00080021": {
"vr": "DA",
"Value": [ "20230610" ]
},
"00200013": {
"vr": "IS",
"Value": [ "5" ]
}
}),
);Structs§
Constants§
- INFINITY
- Represents the serialized representation of “inf” (positive infinity) for 32-bit float (FL) and 64-bit float (FD) in DICOM JSON.
- NAN
- Represents the serialized representation of “NaN” (Not a Number) for 32-bit float (FL) and 64-bit float (FD) in DICOM JSON.
- NEG_
INFINITY - Represents the serialized representation of “-inf” (negative infinity) for 32-bit float (FL) and 64-bit float (FD) in DICOM JSON.
Functions§
- from_
reader - Deserialize a piece of DICOM data from a standard byte reader.
- from_
slice - Deserialize a piece of DICOM data from a byte slice.
- from_
str - Deserialize a piece of DICOM data from a string of JSON.
- from_
value - Deserialize a piece of DICOM data from a serde JSON value.
- to_
string - Serialize a piece of DICOM data as a string of JSON.
- to_
string_ pretty - Serialize a piece of DICOM data as a pretty-printed string of JSON.
- to_
value - Serialize a piece of DICOM data as a serde JSON value.
- to_vec
- Serialize a piece of DICOM data to a vector of bytes.
- to_
writer - Serialize a piece of DICOM data to a byte writer.