Shaka Packager SDK
Loading...
Searching...
No Matches
hex_parser.cc
1// Copyright 2022 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/utils/hex_parser.h>
8
9#include <absl/strings/escaping.h>
10#include <absl/types/span.h>
11
12namespace shaka {
13
14bool ValidHexStringToBytes(const std::string& hex,
15 std::vector<uint8_t>* bytes) {
16 std::string raw;
17 if (!ValidHexStringToBytes(hex, &raw))
18 return false;
19
20 absl::string_view str_view(raw);
21 absl::Span<const uint8_t> span(
22 reinterpret_cast<const uint8_t*>(str_view.data()), str_view.size());
23 *bytes = std::vector<uint8_t>(span.begin(), span.end());
24 return true;
25}
26
27bool ValidHexStringToBytes(const std::string& hex, std::string* bytes) {
28 // absl::HexStringToBytes validates the input during processing and
29 // aborts on invalid data, leaving "bytes" in an unspecified state.
30 return absl::HexStringToBytes(hex, bytes);
31}
32
33} // namespace shaka
All the methods that are virtual are virtual for mocking.