NFC: Add get_record_size in common types.

pull/7822/head
Vincent Coubard 2018-08-28 17:43:43 +01:00
parent b6e604338e
commit cffc0221cc
6 changed files with 76 additions and 0 deletions

View File

@ -112,6 +112,13 @@ public:
bool is_last_record = false
);
/**
* Compute the size of this Mime object in a ndef record.
*
* @return The size of the ndef record required to store this object.
*/
size_t get_record_size() const;
private:
friend class MimeParser;

View File

@ -128,6 +128,13 @@ public:
bool is_last_record = false
);
/**
* Compute the size of this object in a ndef record.
*
* @return The size of the ndef record required to store this object.
*/
size_t get_record_size() const;
private:
friend class TextParser;

View File

@ -150,6 +150,13 @@ public:
bool is_last_record = false
);
/**
* Compute the size of this object in a ndef record.
*
* @return The size of the ndef record required to store this object.
*/
size_t get_record_size() const;
/**
* Equal operator between two URIs
* @param lhs The URI on the left hand side

View File

@ -106,6 +106,21 @@ bool Mime::append_as_record(
get_mime_content(),
is_last_record
);
size_t Mime::get_record_size() const
{
return MessageBuilder::compute_record_size(
Record(
RecordType(
RecordType::media_type,
get_mime_type()
),
get_mime_content(),
RecordID(),
/* chunk */ false,
/* last record */ false
)
);
}
void Mime::move_data(

View File

@ -149,6 +149,26 @@ bool Text::append_as_record(
return message_builder.append_record(type, payload, is_last_record);
}
size_t Text::get_record_size() const
{
if (!_text_record) {
return 0;
}
return MessageBuilder::compute_record_size(
Record(
RecordType(
RecordType::well_known_type,
text_record_type_value
),
RecordPayload(_text_record, _text_record_size),
RecordID(),
/* chunk */ false,
/* last record */ false
)
);
}
bool TextParser::do_parse(const Record &record, Text &text)
{
if (record.type.tnf != RecordType::well_known_type) {

View File

@ -129,6 +129,26 @@ bool URI::append_as_record(MessageBuilder &message_builder, bool is_last_record)
return message_builder.append_record(type, payload, is_last_record);
}
size_t URI::get_record_size() const
{
if (!_uri) {
return 0;
}
return MessageBuilder::compute_record_size(
Record(
RecordType(
RecordType::well_known_type,
uri_record_type_value
),
RecordPayload(_uri, _uri_size),
RecordID(),
/* chunk */ false,
/* last record */ false
)
);
}
void URI::move_data(uint8_t *new_uri, size_t new_uri_size)
{
delete[] _uri;