untested tags rendering routine draft

This commit is contained in:
Frédéric Mangano
2016-03-01 14:37:09 +01:00
parent acbf99d276
commit f469d76e62
3 changed files with 24 additions and 5 deletions

View File

@ -270,5 +270,24 @@ void ogg::Encoder::write_tags(int streamno, const Tags &tags)
std::string ogg::Encoder::render_opustags(const Tags &tags)
{
std::stringbuf s;
uint32_t length;
s.sputn("OpusTags", 8);
length = htole32(tags.vendor.size());
s.sputn(reinterpret_cast<char*>(&length), 4);
s.sputn(tags.vendor.data(), tags.vendor.size());
auto assocs = tags.get_all();
length = htole32(assocs.size());
s.sputn(reinterpret_cast<char*>(&length), 4);
for (auto assoc : assocs) {
length = htole32(assoc.first.size() + 1 + assoc.second.size());
s.sputn(reinterpret_cast<char*>(&length), 4);
s.sputn(assoc.first.data(), assoc.first.size());
s.sputc('=');
s.sputn(assoc.second.data(), assoc.second.size());
}
s.sputn(tags.extra.data(), tags.extra.size());
return s.str();
}

View File

@ -7,7 +7,7 @@ Tags::Tags() : max_index(0)
{
}
const std::vector<std::tuple<std::string, std::string>> Tags::get_all() const
const std::vector<std::pair<std::string, std::string>> Tags::get_all() const
{
std::vector<std::string> keys;
for (const auto &kv : key_to_value)
@ -21,10 +21,10 @@ const std::vector<std::tuple<std::string, std::string>> Tags::get_all() const
return key_to_index.at(a) < key_to_index.at(b);
});
std::vector<std::tuple<std::string, std::string>> result;
std::vector<std::pair<std::string, std::string>> result;
for (const auto &key : keys) {
result.push_back(
std::make_tuple(
std::make_pair(
key, key_to_value.at(key)));
}

View File

@ -2,7 +2,7 @@
#include <map>
#include <vector>
#include <tuple>
#include <utility>
namespace opustags {
@ -12,7 +12,7 @@ namespace opustags {
public:
Tags();
const std::vector<std::tuple<std::string, std::string>> get_all() const;
const std::vector<std::pair<std::string, std::string>> get_all() const;
std::string get(const std::string &key) const;
void set(const std::string &key, const std::string &value);