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