6 #include <c++utilities/conversion/binaryconversion.h> 7 #include <c++utilities/conversion/stringbuilder.h> 29 void MatroskaAttachment::parse(
EbmlElement *attachedFileElement)
32 static const string context(
"parsing \"AttachedFile\"-element");
33 m_attachedFileElement = attachedFileElement;
37 switch(subElement->
id()) {
42 addNotification(NotificationType::Warning,
"Multiple \"FileDescription\"-elements found. Surplus elements will be ignored.", context);
49 addNotification(NotificationType::Warning,
"Multiple \"FileName\"-elements found. Surplus elements will be ignored.", context);
53 if(mimeType().empty()) {
56 addNotification(NotificationType::Warning,
"Multiple \"FileMimeType\"-elements found. Surplus elements will be ignored.", context);
61 addNotification(NotificationType::Warning,
"Multiple \"FileData\"-elements found. Surplus elements will be ignored.", context);
63 setData(make_unique<StreamDataBlock>(std::bind(&EbmlElement::stream, subElement), subElement->
dataOffset(), ios_base::beg, subElement->
startOffset() + subElement->
totalSize(), ios_base::beg));
68 addNotification(NotificationType::Warning,
"Multiple \"FileUID\"-elements found. Surplus elements will be ignored.", context);
80 addNotification(NotificationType::Warning,
"Unknown child element \"" % subElement->
idToString() +
"\" found.", context);
93 void MatroskaAttachment::make(std::ostream &stream)
95 if(!data() || !data()->size()) {
96 addNotification(NotificationType::Critical,
"There is no data assigned.",
"making Matroska attachment");
99 prepareMaking().make(stream);
114 m_attachment(attachment)
116 m_attachedFileElementSize = 2 + EbmlElement::calculateSizeDenotationLength(attachment.
name().size()) + attachment.
name().size()
117 + 2 + EbmlElement::calculateSizeDenotationLength(attachment.
mimeType().size()) + attachment.
mimeType().size()
118 + 2 + 1 + EbmlElement::calculateUIntegerLength(attachment.
id());
119 if(
auto dataSize = attachment.
data() ? attachment.
data()->
size() :
static_cast<istream::pos_type
>(0)) {
120 m_attachedFileElementSize += 2 + EbmlElement::calculateSizeDenotationLength(dataSize) + dataSize;
123 m_attachedFileElementSize += 2 + EbmlElement::calculateSizeDenotationLength(attachment.
description().size()) + attachment.
description().size();
129 m_attachedFileElementSize += child->
totalSize();
133 m_totalSize = 2 + EbmlElement::calculateSizeDenotationLength(m_attachedFileElementSize) + m_attachedFileElementSize;
143 void MatroskaAttachmentMaker::make(ostream &stream)
const 147 stream.write(buff, 2);
148 byte len = EbmlElement::makeSizeDenotation(m_attachedFileElementSize, buff);
149 stream.write(buff, len);
157 if(attachment().attachedFileElement()) {
160 if((child = attachment().attachedFileElement()->childById(
id))) {
169 if(attachment().data() && attachment().data()->size()) {
171 stream.write(buff, 2);
172 len = EbmlElement::makeSizeDenotation(attachment().data()->size(), buff);
173 stream.write(buff, len);
178 void MatroskaAttachmentMaker::bufferCurrentAttachments()
181 if(attachment().attachedFileElement()) {
183 if((child = attachment().attachedFileElement()->childById(
id))) {
188 if(attachment().data() && attachment().data()->size() && !attachment().isDataFromFile()) {
Contains utility classes helping to read and write streams.