6 #include <c++utilities/conversion/binaryconversion.h> 7 #include <c++utilities/misc/memory.h> 27 void MatroskaAttachment::parse(
EbmlElement *attachedFileElement)
30 static const string context(
"parsing \"AttachedFile\"-element");
31 m_attachedFileElement = attachedFileElement;
35 switch(subElement->
id()) {
40 addNotification(NotificationType::Warning,
"Multiple \"FileDescription\"-elements found. Surplus elements will be ignored.", context);
47 addNotification(NotificationType::Warning,
"Multiple \"FileName\"-elements found. Surplus elements will be ignored.", context);
51 if(mimeType().empty()) {
54 addNotification(NotificationType::Warning,
"Multiple \"FileMimeType\"-elements found. Surplus elements will be ignored.", context);
59 addNotification(NotificationType::Warning,
"Multiple \"FileData\"-elements found. Surplus elements will be ignored.", context);
61 setData(make_unique<StreamDataBlock>(std::bind(&EbmlElement::stream, subElement), subElement->
dataOffset(), ios_base::beg, subElement->
startOffset() + subElement->
totalSize(), ios_base::beg));
66 addNotification(NotificationType::Warning,
"Multiple \"FileUID\"-elements found. Surplus elements will be ignored.", context);
78 addNotification(NotificationType::Warning,
"Unknown child element \"" + subElement->
idToString() +
"\" found.", context);
91 void MatroskaAttachment::make(std::ostream &stream)
93 if(!data() || !data()->size()) {
94 addNotification(NotificationType::Critical,
"There is no data assigned.",
"making Matroska attachment");
97 prepareMaking().make(stream);
112 m_attachment(attachment)
114 m_attachedFileElementSize = 2 + EbmlElement::calculateSizeDenotationLength(attachment.
name().size()) + attachment.
name().size()
115 + 2 + EbmlElement::calculateSizeDenotationLength(attachment.
mimeType().size()) + attachment.
mimeType().size()
116 + 2 + 1 + EbmlElement::calculateUIntegerLength(attachment.
id());
117 if(
auto dataSize = attachment.
data() ? attachment.
data()->
size() :
static_cast<istream::pos_type
>(0)) {
118 m_attachedFileElementSize += 2 + EbmlElement::calculateSizeDenotationLength(dataSize) + dataSize;
121 m_attachedFileElementSize += 2 + EbmlElement::calculateSizeDenotationLength(attachment.
description().size()) + attachment.
description().size();
127 m_attachedFileElementSize += child->
totalSize();
131 m_totalSize = 2 + EbmlElement::calculateSizeDenotationLength(m_attachedFileElementSize) + m_attachedFileElementSize;
141 void MatroskaAttachmentMaker::make(ostream &stream)
const 145 stream.write(buff, 2);
146 byte len = EbmlElement::makeSizeDenotation(m_attachedFileElementSize, buff);
147 stream.write(buff, len);
155 if(attachment().attachedFileElement()) {
158 if((child = attachment().attachedFileElement()->childById(
id))) {
167 if(attachment().data() && attachment().data()->size()) {
169 stream.write(buff, 2);
170 len = EbmlElement::makeSizeDenotation(attachment().data()->size(), buff);
171 stream.write(buff, len);
176 void MatroskaAttachmentMaker::bufferCurrentAttachments()
179 if(attachment().attachedFileElement()) {
181 if((child = attachment().attachedFileElement()->childById(
id))) {
186 if(attachment().data() && attachment().data()->size() && !attachment().isDataFromFile()) {
Contains utility classes helping to read and write streams.