Export media_cas_proxy_sdk
This commit is contained in:
34
strings/BUILD
Normal file
34
strings/BUILD
Normal file
@@ -0,0 +1,34 @@
|
||||
################################################################################
|
||||
# Copyright 2017 Google LLC.
|
||||
#
|
||||
# This software is licensed under the terms defined in the Widevine Master
|
||||
# License Agreement. For a copy of this agreement, please contact
|
||||
# widevine-licensing@google.com.
|
||||
################################################################################
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "strings",
|
||||
srcs = [
|
||||
"serialize.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"serialize.h",
|
||||
],
|
||||
deps = [
|
||||
"//base",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "serialize_test",
|
||||
srcs = ["serialize_test.cc"],
|
||||
deps = [
|
||||
":strings",
|
||||
"//base",
|
||||
"//testing:gunit_main",
|
||||
],
|
||||
)
|
||||
33
strings/serialize.cc
Normal file
33
strings/serialize.cc
Normal file
@@ -0,0 +1,33 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2017 Google LLC.
|
||||
//
|
||||
// This software is licensed under the terms defined in the Widevine Master
|
||||
// License Agreement. For a copy of this agreement, please contact
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "strings/serialize.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
namespace widevine {
|
||||
namespace strings {
|
||||
|
||||
uint32_t KeyToUint32(const std::string& key) {
|
||||
CHECK_GE(key.size(), 4);
|
||||
return static_cast<uint8_t>(key[0]) << 24 |
|
||||
static_cast<uint8_t>(key[1]) << 16 |
|
||||
static_cast<uint8_t>(key[2]) << 8 | static_cast<uint8_t>(key[3]);
|
||||
}
|
||||
|
||||
std::string EncodeUint64(uint64_t value) {
|
||||
std::string s;
|
||||
s.resize(sizeof(value));
|
||||
memcpy(&s[0], &value, sizeof(value));
|
||||
return s;
|
||||
}
|
||||
|
||||
} // namespace strings
|
||||
} // namespace widevine
|
||||
25
strings/serialize.h
Normal file
25
strings/serialize.h
Normal file
@@ -0,0 +1,25 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2017 Google LLC.
|
||||
//
|
||||
// This software is licensed under the terms defined in the Widevine Master
|
||||
// License Agreement. For a copy of this agreement, please contact
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef STRINGS_SERIALIZE_H_
|
||||
#define STRINGS_SERIALIZE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace widevine {
|
||||
namespace strings {
|
||||
|
||||
// Convert a 4-byte key in network byte order to uint32_t
|
||||
uint32_t KeyToUint32(const std::string& key);
|
||||
// Encode a unit64 value to a string.
|
||||
std::string EncodeUint64(uint64_t value);
|
||||
|
||||
} // namespace strings
|
||||
} // namespace widevine
|
||||
|
||||
#endif // STRINGS_SERIALIZE_H_
|
||||
32
strings/serialize_test.cc
Normal file
32
strings/serialize_test.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2017 Google LLC.
|
||||
//
|
||||
// This software is licensed under the terms defined in the Widevine Master
|
||||
// License Agreement. For a copy of this agreement, please contact
|
||||
// widevine-licensing@google.com.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Contains the test cases for EncodeUint64 and KeyToUint32.
|
||||
|
||||
#include "strings/serialize.h"
|
||||
|
||||
#include "testing/gunit.h"
|
||||
|
||||
namespace widevine {
|
||||
namespace strings {
|
||||
|
||||
TEST(SerializeTest, KeyToUint32) {
|
||||
std::string val = "\x12\x34\x56\x78";
|
||||
EXPECT_EQ(0x12345678, KeyToUint32(val));
|
||||
val = "\x87\x65\x43\x21";
|
||||
EXPECT_EQ(0x87654321, KeyToUint32(val));
|
||||
}
|
||||
|
||||
TEST(SerializeTest, EncodeUint64) {
|
||||
uint64_t q1 = 0x4142434441424344;
|
||||
std::string uint64_str = EncodeUint64(q1);
|
||||
EXPECT_TRUE(uint64_str == "DCBADCBA" || uint64_str == "ABCDABCD");
|
||||
}
|
||||
|
||||
} // namespace strings
|
||||
} // namespace widevine
|
||||
Reference in New Issue
Block a user