CBOR: Adjust for DECTRIS stream2 compatibility:
* date/time tag * initial tag self-described CBOR * series ID * fixes to typed array header in case of compression
This commit is contained in:
@@ -19,6 +19,15 @@ inline void CBOR_ENC(CborEncoder &encoder, const char* key, const std::string &v
|
||||
cborErr(cbor_encode_text_stringz(&encoder, value.c_str()));
|
||||
}
|
||||
|
||||
inline void CBOR_ENC_DATE(CborEncoder &encoder, const char* key, const std::string &value) {
|
||||
cborErr(cbor_encode_text_stringz(&encoder, key));
|
||||
cbor_encode_tag(&encoder, CborDateTimeStringTag);
|
||||
if (value.empty())
|
||||
cborErr(cbor_encode_text_stringz(&encoder, "."));
|
||||
else
|
||||
cborErr(cbor_encode_text_stringz(&encoder, value.c_str()));
|
||||
}
|
||||
|
||||
inline void CBOR_ENC(CborEncoder &encoder, const char* key, float value) {
|
||||
cborErr(cbor_encode_text_stringz(&encoder, key));
|
||||
cborErr(cbor_encode_float(&encoder, value));
|
||||
@@ -88,28 +97,25 @@ inline void CBOR_ENC_MULTIDIM_TYPED_ARRAY(CborEncoder &encoder, const char* key,
|
||||
cborErr(cbor_encoder_close_container(&arrayEncoder, &arrayEncoder_2));
|
||||
|
||||
CborTag typed_array_tag;
|
||||
if (algorithm != CompressionAlgorithm::NO_COMPRESSION)
|
||||
typed_array_tag = TagUnsignedInt8Bit;
|
||||
else {
|
||||
if (elem_sign) {
|
||||
if (elem_size == 4)
|
||||
typed_array_tag = TagSignedInt32BitLE;
|
||||
else if (elem_size == 2)
|
||||
typed_array_tag = TagSignedInt16BitLE;
|
||||
else if (elem_size == 1)
|
||||
typed_array_tag = TagSignedInt8Bit;
|
||||
else
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Array size not supported");
|
||||
} else {
|
||||
if (elem_size == 4)
|
||||
typed_array_tag = TagUnsignedInt32BitLE;
|
||||
else if (elem_size == 2)
|
||||
typed_array_tag = TagUnsignedInt16BitLE;
|
||||
else if (elem_size == 1)
|
||||
typed_array_tag = TagUnsignedInt8Bit;
|
||||
else
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Array size not supported");
|
||||
}
|
||||
|
||||
if (elem_sign) {
|
||||
if (elem_size == 4)
|
||||
typed_array_tag = TagSignedInt32BitLE;
|
||||
else if (elem_size == 2)
|
||||
typed_array_tag = TagSignedInt16BitLE;
|
||||
else if (elem_size == 1)
|
||||
typed_array_tag = TagSignedInt8Bit;
|
||||
else
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Array size not supported");
|
||||
} else {
|
||||
if (elem_size == 4)
|
||||
typed_array_tag = TagUnsignedInt32BitLE;
|
||||
else if (elem_size == 2)
|
||||
typed_array_tag = TagUnsignedInt16BitLE;
|
||||
else if (elem_size == 1)
|
||||
typed_array_tag = TagUnsignedInt8Bit;
|
||||
else
|
||||
throw JFJochException(JFJochExceptionCategory::CBORError, "Array size not supported");
|
||||
}
|
||||
|
||||
cbor_encode_tag(&arrayEncoder, typed_array_tag);
|
||||
@@ -295,7 +301,7 @@ void JFJochFrameSerializer::SerializeSequenceStart(const StartMessage& message)
|
||||
CborEncoder encoder, mapEncoder;
|
||||
|
||||
cbor_encoder_init(&encoder, buffer.data(), buffer.size(), 0);
|
||||
cborErr(cbor_encode_tag(&encoder, SelfDescribedCBOR ));
|
||||
cborErr(cbor_encode_tag(&encoder, CborSignatureTag ));
|
||||
size_t elements = 27;
|
||||
|
||||
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, elements));
|
||||
@@ -306,8 +312,8 @@ void JFJochFrameSerializer::SerializeSequenceStart(const StartMessage& message)
|
||||
CBOR_ENC(mapEncoder, "beam_center_y", message.beam_center_y);
|
||||
|
||||
CBOR_ENC(mapEncoder, "number_of_images", message.number_of_images);
|
||||
CBOR_ENC(mapEncoder, "xpixel", message.image_size_x);
|
||||
CBOR_ENC(mapEncoder, "ypixel", message.image_size_y);
|
||||
CBOR_ENC(mapEncoder, "image_size_x", message.image_size_x);
|
||||
CBOR_ENC(mapEncoder, "image_size_y", message.image_size_y);
|
||||
|
||||
CBOR_ENC(mapEncoder, "incident_energy", message.incident_energy);
|
||||
CBOR_ENC(mapEncoder, "incident_wavelength", message.incident_wavelength);
|
||||
@@ -321,7 +327,7 @@ void JFJochFrameSerializer::SerializeSequenceStart(const StartMessage& message)
|
||||
CBOR_ENC(mapEncoder, "pixel_size_y", message.pixel_size_y);
|
||||
CBOR_ENC(mapEncoder, "sensor_thickness", message.sensor_thickness);
|
||||
CBOR_ENC(mapEncoder, "sensor_material", message.sensor_material);
|
||||
CBOR_ENC(mapEncoder, "arm_date", message.arm_date);
|
||||
CBOR_ENC_DATE(mapEncoder, "arm_date", message.arm_date);
|
||||
CBOR_ENC(mapEncoder, "pixel_mask_enabled", message.pixel_mask_enabled);
|
||||
CBOR_ENC(mapEncoder, "detector_description", message.detector_description);
|
||||
CBOR_ENC(mapEncoder, "detector_serial_number", message.detector_serial_number);
|
||||
@@ -345,11 +351,12 @@ void JFJochFrameSerializer::SerializeSequenceEnd(const EndMessage& message) {
|
||||
|
||||
CborEncoder encoder, mapEncoder;
|
||||
cbor_encoder_init(&encoder, buffer.data(), buffer.size(), 0);
|
||||
cborErr(cbor_encode_tag(&encoder, SelfDescribedCBOR ));
|
||||
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, 6));
|
||||
cborErr(cbor_encode_tag(&encoder,CborSignatureTag ));
|
||||
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, 8));
|
||||
|
||||
CBOR_ENC(mapEncoder, "type", "end");
|
||||
|
||||
CBOR_ENC(mapEncoder, "series_unique_id", message.series_unique_id);
|
||||
CBOR_ENC(mapEncoder, "series_id", message.series_id);
|
||||
CBOR_ENC(mapEncoder, "number_of_images", message.number_of_images);
|
||||
CBOR_ENC(mapEncoder, "max_receiver_delay", message.max_receiver_delay);
|
||||
CBOR_ENC(mapEncoder, "receiver_efficiency", message.efficiency);
|
||||
@@ -367,10 +374,12 @@ void JFJochFrameSerializer::SerializeImage(const DataMessage& message) {
|
||||
CborEncoder encoder, mapEncoder, userDataMapEncoder;
|
||||
cbor_encoder_init(&encoder, buffer.data(), buffer.size(), 0);
|
||||
|
||||
cborErr(cbor_encode_tag(&encoder, SelfDescribedCBOR ));
|
||||
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, 4));
|
||||
cborErr(cbor_encode_tag(&encoder, CborSignatureTag ));
|
||||
cborErr(cbor_encoder_create_map(&encoder, &mapEncoder, 6));
|
||||
|
||||
CBOR_ENC(mapEncoder, "type", "image");
|
||||
CBOR_ENC(mapEncoder, "series_unique_id", message.series_unique_id);
|
||||
CBOR_ENC(mapEncoder, "series_id", message.series_id);
|
||||
CBOR_ENC(mapEncoder, "image_id", message.number);
|
||||
CBOR_ENC(mapEncoder, "data", message.image);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user