Shaka Packager SDK
tag.cc
1 // Copyright 2018 Google LLC. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include <packager/hls/base/tag.h>
8 
9 #include <cinttypes>
10 
11 #include <absl/strings/str_format.h>
12 
13 namespace shaka {
14 namespace hls {
15 
16 Tag::Tag(const std::string& name, std::string* buffer) : buffer_(buffer) {
17  absl::StrAppendFormat(buffer_, "%s:", name.c_str());
18 }
19 
20 void Tag::AddString(const std::string& key, const std::string& value) {
21  NextField();
22  absl::StrAppendFormat(buffer_, "%s=%s", key.c_str(), value.c_str());
23 }
24 
25 void Tag::AddQuotedString(const std::string& key, const std::string& value) {
26  NextField();
27  absl::StrAppendFormat(buffer_, "%s=\"%s\"", key.c_str(), value.c_str());
28 }
29 
30 void Tag::AddNumber(const std::string& key, uint64_t value) {
31  NextField();
32  absl::StrAppendFormat(buffer_, "%s=%" PRIu64, key.c_str(), value);
33 }
34 
35 void Tag::AddFloat(const std::string& key, float value) {
36  NextField();
37  absl::StrAppendFormat(buffer_, "%s=%.3f", key.c_str(), value);
38 }
39 
40 void Tag::AddNumberPair(const std::string& key,
41  uint64_t number1,
42  char separator,
43  uint64_t number2) {
44  NextField();
45  absl::StrAppendFormat(buffer_, "%s=%" PRIu64 "%c%" PRIu64, key.c_str(),
46  number1, separator, number2);
47 }
48 
49 void Tag::AddQuotedNumberPair(const std::string& key,
50  uint64_t number1,
51  char separator,
52  uint64_t number2) {
53  NextField();
54  absl::StrAppendFormat(buffer_, "%s=\"%" PRIu64 "%c%" PRIu64 "\"", key.c_str(),
55  number1, separator, number2);
56 }
57 
58 void Tag::NextField() {
59  if (fields++) {
60  buffer_->append(",");
61  }
62 }
63 
64 } // namespace hls
65 } // namespace shaka
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66