Skip to content

Commit 20e58e7

Browse files
authored
Remove unnecessary VariableBinding templatation. (#100)
VariableBinding is a first class concept for path matcher and doesn't need to be templated. In addition, add a few developer tools. * Clang format * Makefile
1 parent 8b7e71c commit 20e58e7

21 files changed

+220
-210
lines changed

.clang-format

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google
4+
---
5+
Language: Proto
6+
BasedOnStyle: Google
7+
---
8+
Language: TextProto
9+
BasedOnStyle: Google
10+
...

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/bazel-out
55
/bazel-testlogs
66

7-
# CLion bazel plugin
8-
/.clwb
9-
# Intellij bazel plugin
10-
/.ilwb
7+
# IDE
8+
.clwb/
9+
.ijwb/
10+
.idea/

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CPP_PROTO_FILES = $(shell find . -type f \
2+
-regex "./\(src\|api\)/.*[.]\(h\|cc\|proto\)" \
3+
-not -path "./vendor/*")
4+
5+
.PHONY: build
6+
build: clang-format
7+
bazelisk build //...
8+
9+
.PHONY: test
10+
test: clang-format
11+
bazelisk test //...
12+
13+
.PHONY: clang-format
14+
clang-format:
15+
@echo "--> formatting code with 'clang-format' tool"
16+
@echo $(CPP_PROTO_FILES) | xargs clang-format-14 -i

src/http_template.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
//
1515
////////////////////////////////////////////////////////////////////////////////
1616
//
17+
#include "grpc_transcoding/http_template.h"
18+
1719
#include <cassert>
1820
#include <string>
1921
#include <vector>
2022

21-
#include "grpc_transcoding/http_template.h"
22-
2323
namespace google {
2424
namespace grpc {
2525
namespace transcoding {

src/include/grpc_transcoding/http_template.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ class HttpTemplate {
6666
std::vector<Variable> variables_;
6767
};
6868

69+
/**
70+
* VariableBinding specifies a value for a single field in the request message.
71+
* When transcoding HTTP/REST/JSON to gRPC/proto the request message is
72+
* constructed using the HTTP body and the variable bindings (specified through
73+
* request url).
74+
* See
75+
* https://github.com/googleapis/googleapis/blob/master/google/api/http.proto
76+
* for details of variable binding.
77+
*/
78+
struct VariableBinding {
79+
// The location of the field in the protobuf message, where the value
80+
// needs to be inserted, e.g. "shelf.theme" would mean the "theme" field
81+
// of the nested "shelf" message of the request protobuf message.
82+
std::vector<std::string> field_path;
83+
// The value to be inserted.
84+
std::string value;
85+
};
86+
6987
} // namespace transcoding
7088
} // namespace grpc
7189
} // namespace google

src/include/grpc_transcoding/internal/protobuf_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#ifndef GRPC_TRANSCODING_INTERNAL_PROTOBUF_TYPES_H_
1616
#define GRPC_TRANSCODING_INTERNAL_PROTOBUF_TYPES_H_
1717

18-
1918
namespace google {
2019
namespace grpc {
2120
namespace transcoding {

src/include/grpc_transcoding/message_reader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
#include <memory>
1919

20-
#include "transcoder_input_stream.h"
2120
#include "absl/status/status.h"
21+
#include "transcoder_input_stream.h"
2222

2323
namespace google {
2424
namespace grpc {

src/include/grpc_transcoding/message_stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#include <memory>
1919
#include <string>
2020

21+
#include "absl/status/status.h"
2122
#include "google/protobuf/io/zero_copy_stream.h"
2223
#include "transcoder_input_stream.h"
23-
#include "absl/status/status.h"
2424

2525
namespace google {
2626
namespace grpc {

src/include/grpc_transcoding/path_matcher.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
#include <unordered_map>
2323
#include <unordered_set>
2424

25+
#include "absl/strings/str_split.h"
2526
#include "http_template.h"
2627
#include "path_matcher_node.h"
2728
#include "percent_encoding.h"
28-
#include "absl/strings/str_split.h"
2929

3030
namespace google {
3131
namespace grpc {
@@ -56,8 +56,6 @@ class PathMatcher {
5656
public:
5757
~PathMatcher(){};
5858

59-
// TODO: Do not template VariableBinding
60-
template <class VariableBinding>
6159
Method Lookup(const std::string& http_method, const std::string& path,
6260
const std::string& query_params,
6361
std::vector<VariableBinding>* variable_bindings,
@@ -173,7 +171,6 @@ class PathMatcherBuilder {
173171

174172
namespace {
175173

176-
template <class VariableBinding>
177174
void ExtractBindingsFromPath(const std::vector<HttpTemplate::Variable>& vars,
178175
const std::vector<std::string>& parts,
179176
UrlUnescapeSpec unescape_spec,
@@ -210,7 +207,6 @@ void ExtractBindingsFromPath(const std::vector<HttpTemplate::Variable>& vars,
210207
}
211208
}
212209

213-
template <class VariableBinding>
214210
void ExtractBindingsFromQueryParameters(
215211
const std::string& query_params,
216212
const std::unordered_set<std::string>& system_params,
@@ -325,7 +321,6 @@ PathMatcher<Method>::PathMatcher(PathMatcherBuilder<Method>&& builder)
325321
// TODO: cache results by adding get/put methods here (if profiling reveals
326322
// benefit)
327323
template <class Method>
328-
template <class VariableBinding>
329324
Method PathMatcher<Method>::Lookup(
330325
const std::string& http_method, const std::string& path,
331326
const std::string& query_params,

src/include/grpc_transcoding/percent_encoding.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define GRPC_TRANSCODING_PERCENT_ENCODING_H_
1717

1818
#include <string>
19+
1920
#include "absl/strings/string_view.h"
2021

2122
namespace google {

0 commit comments

Comments
 (0)