[metadata] Move hooks into grpc_base, separate build some (#32781)

When using this internally, we noticed that it's impossible to use
custom_metadata.h without creating a dependency cycle between
:custom_metadata and :grpc_base.

A full build refactoring is too large right now, so merge that header
into :grpc_base for the time being.

Also, separate `SimpleSliceBasedMetadata` into its own file, so that it
can be reused in custom_metadata.h.




<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->

---------

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/32792/head
Craig Tiller 2 years ago committed by GitHub
parent 93b802d02e
commit 7fae3dec0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      BUILD
  2. 4
      build_autogenerated.yaml
  3. 2
      gRPC-C++.podspec
  4. 2
      gRPC-Core.podspec
  5. 1
      grpc.gemspec
  6. 1
      package.xml
  7. 17
      src/core/lib/transport/metadata_batch.h
  8. 48
      src/core/lib/transport/simple_slice_based_metadata.h
  9. 1
      tools/doxygen/Doxyfile.c++.internal
  10. 1
      tools/doxygen/Doxyfile.core.internal

10
BUILD

@ -1394,9 +1394,11 @@ grpc_cc_library(
"//src/core:lib/surface/server.h", "//src/core:lib/surface/server.h",
"//src/core:lib/surface/validate_metadata.h", "//src/core:lib/surface/validate_metadata.h",
"//src/core:lib/transport/connectivity_state.h", "//src/core:lib/transport/connectivity_state.h",
"//src/core:lib/transport/custom_metadata.h",
"//src/core:lib/transport/error_utils.h", "//src/core:lib/transport/error_utils.h",
"//src/core:lib/transport/metadata_batch.h", "//src/core:lib/transport/metadata_batch.h",
"//src/core:lib/transport/parsed_metadata.h", "//src/core:lib/transport/parsed_metadata.h",
"//src/core:lib/transport/simple_slice_based_metadata.h",
"//src/core:lib/transport/status_conversion.h", "//src/core:lib/transport/status_conversion.h",
"//src/core:lib/transport/timeout_encoding.h", "//src/core:lib/transport/timeout_encoding.h",
"//src/core:lib/transport/transport.h", "//src/core:lib/transport/transport.h",
@ -1445,7 +1447,6 @@ grpc_cc_library(
"config", "config",
"config_vars", "config_vars",
"cpp_impl_of", "cpp_impl_of",
"custom_metadata",
"debug_location", "debug_location",
"exec_ctx", "exec_ctx",
"gpr", "gpr",
@ -1539,13 +1540,6 @@ grpc_cc_library(
], ],
) )
grpc_cc_library(
name = "custom_metadata",
hdrs = [
"//src/core:lib/transport/custom_metadata.h",
],
)
grpc_cc_library( grpc_cc_library(
name = "lb_load_data_store", name = "lb_load_data_store",
srcs = [ srcs = [

@ -1078,6 +1078,7 @@ libs:
- src/core/lib/transport/metadata_batch.h - src/core/lib/transport/metadata_batch.h
- src/core/lib/transport/parsed_metadata.h - src/core/lib/transport/parsed_metadata.h
- src/core/lib/transport/pid_controller.h - src/core/lib/transport/pid_controller.h
- src/core/lib/transport/simple_slice_based_metadata.h
- src/core/lib/transport/status_conversion.h - src/core/lib/transport/status_conversion.h
- src/core/lib/transport/tcp_connect_handshaker.h - src/core/lib/transport/tcp_connect_handshaker.h
- src/core/lib/transport/timeout_encoding.h - src/core/lib/transport/timeout_encoding.h
@ -2395,6 +2396,7 @@ libs:
- src/core/lib/transport/metadata_batch.h - src/core/lib/transport/metadata_batch.h
- src/core/lib/transport/parsed_metadata.h - src/core/lib/transport/parsed_metadata.h
- src/core/lib/transport/pid_controller.h - src/core/lib/transport/pid_controller.h
- src/core/lib/transport/simple_slice_based_metadata.h
- src/core/lib/transport/status_conversion.h - src/core/lib/transport/status_conversion.h
- src/core/lib/transport/tcp_connect_handshaker.h - src/core/lib/transport/tcp_connect_handshaker.h
- src/core/lib/transport/timeout_encoding.h - src/core/lib/transport/timeout_encoding.h
@ -3859,6 +3861,7 @@ libs:
- src/core/lib/transport/http2_errors.h - src/core/lib/transport/http2_errors.h
- src/core/lib/transport/metadata_batch.h - src/core/lib/transport/metadata_batch.h
- src/core/lib/transport/parsed_metadata.h - src/core/lib/transport/parsed_metadata.h
- src/core/lib/transport/simple_slice_based_metadata.h
- src/core/lib/transport/status_conversion.h - src/core/lib/transport/status_conversion.h
- src/core/lib/transport/timeout_encoding.h - src/core/lib/transport/timeout_encoding.h
- src/core/lib/transport/transport.h - src/core/lib/transport/transport.h
@ -7673,6 +7676,7 @@ targets:
- src/core/lib/transport/http2_errors.h - src/core/lib/transport/http2_errors.h
- src/core/lib/transport/metadata_batch.h - src/core/lib/transport/metadata_batch.h
- src/core/lib/transport/parsed_metadata.h - src/core/lib/transport/parsed_metadata.h
- src/core/lib/transport/simple_slice_based_metadata.h
- src/core/lib/transport/status_conversion.h - src/core/lib/transport/status_conversion.h
- src/core/lib/transport/timeout_encoding.h - src/core/lib/transport/timeout_encoding.h
- src/core/lib/transport/transport.h - src/core/lib/transport/transport.h

2
gRPC-C++.podspec generated

@ -1045,6 +1045,7 @@ Pod::Spec.new do |s|
'src/core/lib/transport/metadata_batch.h', 'src/core/lib/transport/metadata_batch.h',
'src/core/lib/transport/parsed_metadata.h', 'src/core/lib/transport/parsed_metadata.h',
'src/core/lib/transport/pid_controller.h', 'src/core/lib/transport/pid_controller.h',
'src/core/lib/transport/simple_slice_based_metadata.h',
'src/core/lib/transport/status_conversion.h', 'src/core/lib/transport/status_conversion.h',
'src/core/lib/transport/tcp_connect_handshaker.h', 'src/core/lib/transport/tcp_connect_handshaker.h',
'src/core/lib/transport/timeout_encoding.h', 'src/core/lib/transport/timeout_encoding.h',
@ -1985,6 +1986,7 @@ Pod::Spec.new do |s|
'src/core/lib/transport/metadata_batch.h', 'src/core/lib/transport/metadata_batch.h',
'src/core/lib/transport/parsed_metadata.h', 'src/core/lib/transport/parsed_metadata.h',
'src/core/lib/transport/pid_controller.h', 'src/core/lib/transport/pid_controller.h',
'src/core/lib/transport/simple_slice_based_metadata.h',
'src/core/lib/transport/status_conversion.h', 'src/core/lib/transport/status_conversion.h',
'src/core/lib/transport/tcp_connect_handshaker.h', 'src/core/lib/transport/tcp_connect_handshaker.h',
'src/core/lib/transport/timeout_encoding.h', 'src/core/lib/transport/timeout_encoding.h',

2
gRPC-Core.podspec generated

@ -1735,6 +1735,7 @@ Pod::Spec.new do |s|
'src/core/lib/transport/parsed_metadata.h', 'src/core/lib/transport/parsed_metadata.h',
'src/core/lib/transport/pid_controller.cc', 'src/core/lib/transport/pid_controller.cc',
'src/core/lib/transport/pid_controller.h', 'src/core/lib/transport/pid_controller.h',
'src/core/lib/transport/simple_slice_based_metadata.h',
'src/core/lib/transport/status_conversion.cc', 'src/core/lib/transport/status_conversion.cc',
'src/core/lib/transport/status_conversion.h', 'src/core/lib/transport/status_conversion.h',
'src/core/lib/transport/tcp_connect_handshaker.cc', 'src/core/lib/transport/tcp_connect_handshaker.cc',
@ -2675,6 +2676,7 @@ Pod::Spec.new do |s|
'src/core/lib/transport/metadata_batch.h', 'src/core/lib/transport/metadata_batch.h',
'src/core/lib/transport/parsed_metadata.h', 'src/core/lib/transport/parsed_metadata.h',
'src/core/lib/transport/pid_controller.h', 'src/core/lib/transport/pid_controller.h',
'src/core/lib/transport/simple_slice_based_metadata.h',
'src/core/lib/transport/status_conversion.h', 'src/core/lib/transport/status_conversion.h',
'src/core/lib/transport/tcp_connect_handshaker.h', 'src/core/lib/transport/tcp_connect_handshaker.h',
'src/core/lib/transport/timeout_encoding.h', 'src/core/lib/transport/timeout_encoding.h',

1
grpc.gemspec generated

@ -1642,6 +1642,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/transport/parsed_metadata.h ) s.files += %w( src/core/lib/transport/parsed_metadata.h )
s.files += %w( src/core/lib/transport/pid_controller.cc ) s.files += %w( src/core/lib/transport/pid_controller.cc )
s.files += %w( src/core/lib/transport/pid_controller.h ) s.files += %w( src/core/lib/transport/pid_controller.h )
s.files += %w( src/core/lib/transport/simple_slice_based_metadata.h )
s.files += %w( src/core/lib/transport/status_conversion.cc ) s.files += %w( src/core/lib/transport/status_conversion.cc )
s.files += %w( src/core/lib/transport/status_conversion.h ) s.files += %w( src/core/lib/transport/status_conversion.h )
s.files += %w( src/core/lib/transport/tcp_connect_handshaker.cc ) s.files += %w( src/core/lib/transport/tcp_connect_handshaker.cc )

1
package.xml generated

@ -1624,6 +1624,7 @@
<file baseinstalldir="/" name="src/core/lib/transport/parsed_metadata.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/transport/parsed_metadata.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/transport/pid_controller.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/transport/pid_controller.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/transport/pid_controller.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/transport/pid_controller.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/transport/simple_slice_based_metadata.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/transport/status_conversion.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/transport/status_conversion.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/transport/status_conversion.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/transport/status_conversion.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/transport/tcp_connect_handshaker.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/transport/tcp_connect_handshaker.cc" role="src" />

@ -47,6 +47,7 @@
#include "src/core/lib/slice/slice.h" #include "src/core/lib/slice/slice.h"
#include "src/core/lib/transport/custom_metadata.h" #include "src/core/lib/transport/custom_metadata.h"
#include "src/core/lib/transport/parsed_metadata.h" #include "src/core/lib/transport/parsed_metadata.h"
#include "src/core/lib/transport/simple_slice_based_metadata.h"
namespace grpc_core { namespace grpc_core {
@ -229,22 +230,6 @@ struct GrpcAcceptEncodingMetadata {
} }
}; };
struct SimpleSliceBasedMetadata {
using ValueType = Slice;
using MementoType = Slice;
static MementoType ParseMemento(Slice value, MetadataParseErrorFn) {
return value.TakeOwned();
}
static ValueType MementoToValue(MementoType value) { return value; }
static Slice Encode(const ValueType& x) { return x.Ref(); }
static absl::string_view DisplayValue(const ValueType& value) {
return value.as_string_view();
}
static absl::string_view DisplayMemento(const MementoType& value) {
return value.as_string_view();
}
};
// user-agent metadata trait. // user-agent metadata trait.
struct UserAgentMetadata : public SimpleSliceBasedMetadata { struct UserAgentMetadata : public SimpleSliceBasedMetadata {
static constexpr bool kRepeatable = false; static constexpr bool kRepeatable = false;

@ -0,0 +1,48 @@
// Copyright 2023 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_SRC_CORE_LIB_TRANSPORT_SIMPLE_SLICE_BASED_METADATA_H
#define GRPC_SRC_CORE_LIB_TRANSPORT_SIMPLE_SLICE_BASED_METADATA_H
#include <grpc/support/port_platform.h>
#include "absl/strings/string_view.h"
#include "src/core/lib/slice/slice.h"
#include "src/core/lib/transport/parsed_metadata.h"
namespace grpc_core {
// Models grpc metadata (as per the rules for MetadataMap) for a metadata
// element that consists of a Slice.
// Use by deriving from this class and adding `kRepeatable` and `key()`.
struct SimpleSliceBasedMetadata {
using ValueType = Slice;
using MementoType = Slice;
static MementoType ParseMemento(Slice value, MetadataParseErrorFn) {
return value.TakeOwned();
}
static ValueType MementoToValue(MementoType value) { return value; }
static Slice Encode(const ValueType& x) { return x.Ref(); }
static absl::string_view DisplayValue(const ValueType& value) {
return value.as_string_view();
}
static absl::string_view DisplayMemento(const MementoType& value) {
return value.as_string_view();
}
};
} // namespace grpc_core
#endif // GRPC_SRC_CORE_LIB_TRANSPORT_SIMPLE_SLICE_BASED_METADATA_H

@ -2637,6 +2637,7 @@ src/core/lib/transport/parsed_metadata.cc \
src/core/lib/transport/parsed_metadata.h \ src/core/lib/transport/parsed_metadata.h \
src/core/lib/transport/pid_controller.cc \ src/core/lib/transport/pid_controller.cc \
src/core/lib/transport/pid_controller.h \ src/core/lib/transport/pid_controller.h \
src/core/lib/transport/simple_slice_based_metadata.h \
src/core/lib/transport/status_conversion.cc \ src/core/lib/transport/status_conversion.cc \
src/core/lib/transport/status_conversion.h \ src/core/lib/transport/status_conversion.h \
src/core/lib/transport/tcp_connect_handshaker.cc \ src/core/lib/transport/tcp_connect_handshaker.cc \

@ -2420,6 +2420,7 @@ src/core/lib/transport/parsed_metadata.cc \
src/core/lib/transport/parsed_metadata.h \ src/core/lib/transport/parsed_metadata.h \
src/core/lib/transport/pid_controller.cc \ src/core/lib/transport/pid_controller.cc \
src/core/lib/transport/pid_controller.h \ src/core/lib/transport/pid_controller.h \
src/core/lib/transport/simple_slice_based_metadata.h \
src/core/lib/transport/status_conversion.cc \ src/core/lib/transport/status_conversion.cc \
src/core/lib/transport/status_conversion.h \ src/core/lib/transport/status_conversion.h \
src/core/lib/transport/tcp_connect_handshaker.cc \ src/core/lib/transport/tcp_connect_handshaker.cc \

Loading…
Cancel
Save