/* * Copyright 2026 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #ifndef RTC_BASE_SPAN_HELPERS_H_ #define RTC_BASE_SPAN_HELPERS_H_ #include #include #include #include "absl/strings/string_view.h" namespace webrtc { // Converters between std::span and std::span. // These are deliberately not templated; we don't think that we need // more generic versions of these, and the need for them could be a code // smell indicating the need for defining whether variables are intended // to be text (char) or binary blobs (uint8_t). // If there turns out to be a need for many more variants, templates can // be introduced in the future. inline std::span AsWritableCharSpan(std::span span) { return std::span(reinterpret_cast(span.data()), span.size()); } inline std::span AsCharSpan(std::span span) { return std::span(reinterpret_cast(span.data()), span.size()); } inline std::span AsWritableUint8Span(std::span span) { return std::span(reinterpret_cast(span.data()), span.size()); } inline std::span AsUint8Span(std::span span) { return std::span(reinterpret_cast(span.data()), span.size()); } inline std::span AsUint8Span(absl::string_view s) { return std::span(reinterpret_cast(s.data()), s.size()); } inline std::span AsUint8Span(const std::string& s) { return AsUint8Span(absl::string_view(s)); } inline absl::string_view AsStringView(std::span span) { return absl::string_view(reinterpret_cast(span.data()), span.size()); } } // namespace webrtc #endif // RTC_BASE_SPAN_HELPERS_H_