Merge branch 'master' into release

Change-Id: I56ea2217899e92bdd9d6cb56797ac9895e194fff
This commit is contained in:
Alexey Polyudov
2020-06-24 11:01:46 -07:00
147 changed files with 8642 additions and 1214 deletions
+20 -5
View File
@@ -15,10 +15,11 @@
#ifndef PLATFORM_V2_BASE_BYTE_ARRAY_H_
#define PLATFORM_V2_BASE_BYTE_ARRAY_H_
#include <array>
#include <cstdint>
#include <string>
#include "absl/strings/string_view.h"
#include <type_traits>
#include <utility>
namespace location {
namespace nearby {
@@ -27,13 +28,22 @@ class ByteArray {
public:
// Create an empty ByteArray
ByteArray() = default;
template <size_t N>
explicit ByteArray(const std::array<char, N>& data) {
SetData(data.data(), data.size());
}
ByteArray(const ByteArray&) = default;
ByteArray& operator=(const ByteArray&) = default;
ByteArray(ByteArray&&) = default;
ByteArray& operator=(ByteArray&&) = default;
// Create ByteArray from string.
explicit ByteArray(absl::string_view source) {
// Moves string out of temporary, allowing for a zero-copy constructions.
// This is an optimization for very large strings.
explicit ByteArray(std::string&& source) : data_(std::move(source)) {}
// Create ByteArray by copy of a std::string. This can't be a string_view,
// because it will conflict with std::string&& version of constructor.
explicit ByteArray(const std::string& source) {
SetData(source.data(), source.size());
}
@@ -73,7 +83,12 @@ class ByteArray {
friend bool operator!=(const ByteArray& lhs, const ByteArray& rhs);
friend bool operator<(const ByteArray& lhs, const ByteArray& rhs);
explicit operator std::string() const { return data_; }
// Returns a copy of internal representation as std::string.
explicit operator std::string() const& { return data_; }
// Moves string out of temporary ByteArray, allowing for a zero-copy
// operation.
explicit operator std::string() const&& { return std::move(data_); }
private:
std::string data_;