chromium/third_party/grpc/src/include/grpc/event_engine/slice.h

// Copyright 2022 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef GRPC_EVENT_ENGINE_SLICE_H
#define GRPC_EVENT_ENGINE_SLICE_H

#include <grpc/support/port_platform.h>

#include <string.h>

#include <cstdint>
#include <string>
#include <utility>

#include "absl/strings/string_view.h"

#include <grpc/event_engine/internal/slice_cast.h>
#include <grpc/slice.h>
#include <grpc/support/log.h>

// This public slice definition largely based of the internal grpc_core::Slice
// implementation. Changes to this implementation might warrant changes to the
// internal grpc_core::Slice type as well.

namespace grpc_event_engine {
namespace experimental {

// Forward declarations
class Slice;
class MutableSlice;

namespace slice_detail {

// Returns an empty slice.
static constexpr grpc_slice EmptySlice() {}

// BaseSlice holds the grpc_slice object, but does not apply refcounting policy.
// It does export immutable access into the slice, such that this can be shared
// by all storage policies.
class BaseSlice {};

inline bool operator==(const BaseSlice& a, const BaseSlice& b) {}

inline bool operator!=(const BaseSlice& a, const BaseSlice& b) {}

inline bool operator==(const BaseSlice& a, absl::string_view b) {}

inline bool operator!=(const BaseSlice& a, absl::string_view b) {}

inline bool operator==(absl::string_view a, const BaseSlice& b) {}

inline bool operator!=(absl::string_view a, const BaseSlice& b) {}

inline bool operator==(const BaseSlice& a, const grpc_slice& b) {}

inline bool operator!=(const BaseSlice& a, const grpc_slice& b) {}

inline bool operator==(const grpc_slice& a, const BaseSlice& b) {}

inline bool operator!=(const grpc_slice& a, const BaseSlice& b) {}

template <typename Out>
struct CopyConstructors {};

}  // namespace slice_detail

class GPR_MSVC_EMPTY_BASE_CLASS_WORKAROUND MutableSlice
    : public slice_detail::BaseSlice,
      public slice_detail::CopyConstructors<MutableSlice> {};

class GPR_MSVC_EMPTY_BASE_CLASS_WORKAROUND Slice
    : public slice_detail::BaseSlice,
      public slice_detail::CopyConstructors<Slice> {};

namespace internal {
template <>
struct SliceCastable<Slice, grpc_slice> {};
template <>
struct SliceCastable<grpc_slice, Slice> {};

template <>
struct SliceCastable<MutableSlice, grpc_slice> {};
template <>
struct SliceCastable<grpc_slice, MutableSlice> {};

template <>
struct SliceCastable<MutableSlice, Slice> {};
template <>
struct SliceCastable<Slice, MutableSlice> {};
}  // namespace internal

}  // namespace experimental
}  // namespace grpc_event_engine

#endif  // GRPC_EVENT_ENGINE_SLICE_H