@@ -12,17 +12,60 @@ The PubsubMessage class (generated from protobuf) is based on [Google API](https
12
12
** This is not an officially supported Google product.**
13
13
14
14
# User Guide
15
+ More example use cases are available in header files as comments.
16
+ The only files that you will directly import and use are in ` //v1/protocol_binding/ ` .
17
+
15
18
## Setup
16
- Install Bazel. Instuctions found in [ Bazel documentation] ( https://docs.bazel.build/versions/master/install-ubuntu.html ) .
19
+ ### Install Bazel Build System
20
+ Instuctions found in [ Bazel documentation] ( https://docs.bazel.build/versions/master/install-ubuntu.html ) .
17
21
18
- ## Binding a CloudEvent to a Protocol-Message
19
- ### BinaryContentMode
22
+ ### Import SDK as a Bazel package in WORKSPACE
23
+ In ` //WORKSPACE `
20
24
```
21
- // import the header for the binder of the protocol message you're working with
25
+ # TODO (#63) : Update README to create Bazel target to master repo once merged
26
+
27
+ git_repository(
28
+ name = "cloudevents_cpp_sdk",
29
+ commit = "20c9855c11bc66efcc6e086571477bb69870be1d",
30
+ remote = "https://github.com/michlee1337/cloudevents-sdk-cpp/tree/binder-all.v2",
31
+ )
32
+
33
+ ```
34
+
35
+ ### Set up the build dependencies
36
+ Specify any binders needed as a bazel target dependency.
37
+
38
+ To use PubsubBinder:
39
+ ```
40
+ cc_binary(
41
+ ...
42
+ deps = [
43
+ ...
44
+ "@cloudevents_cpp_sdk/protocol_binding:pubsub_binder_lib",
45
+ ],
46
+ )
47
+ ```
48
+
49
+ To use HttpReqBinder or HttpResBinder:
50
+ ```
51
+ cc_binary(
52
+ ...
53
+ deps = [
54
+ ...
55
+ "@cloudevents_cpp_sdk/protocol_binding:http_binder_lib",
56
+ ],
57
+ )
58
+ ```
59
+
60
+ ## Binding a CloudEvent to a Protocol-Message in Binary-ContentMode
61
+ Import the header file and use XBinder
62
+ ```
63
+ // import the header for the binder
22
64
#include "//v1/protocol_binding/pubsub_binder.h"
23
-
65
+
24
66
using ::google::pubsub::v1::PubsubMessage;
25
- using ::cloudevents::binder::Binder
67
+ using ::cloudevents::binder::PubsubBinder;
68
+ using ::cloudevents_absl::StatusOr;
26
69
27
70
// create a CloudEvent
28
71
CloudEvent my_cloud_event;
@@ -33,23 +76,30 @@ my_cloud_event.set_type("my_type");
33
76
my_cloud_event.set_binary_data("1010");
34
77
35
78
// Initialize the binder
36
- Binder<PubsubMessage> pubsub_binder;
79
+ PubsubBinder pubsub_binder;
37
80
38
81
// Create the Message
39
- PubsubMessage usable_message = pubsub_binder.bind(my_cloud_event);
40
- ```
82
+ StatusOr<PubsubMessage> bind = pubsub_binder.Bind(my_cloud_event);
41
83
42
- ### StructuredContentMode
84
+ // Check no errors
85
+ if (!bind.ok()) {
86
+ std::cerr << bind.status();
87
+ }
88
+
89
+ // unwrap message
90
+ PubsubMessage usable_message = *bind;
43
91
```
44
- // import the header for formats
45
- #include "//v1/event_format/format.h"
46
92
47
- // import the header for the binder of the protocol message you're working with
93
+ ## Binding a CloudEvent to a Protocol-Message in Structured-ContentMode
94
+ Import the header file and use Format and XBinder
95
+ ```
96
+ // import the header for the binder
48
97
#include "//v1/protocol_binding/pubsub_binder.h"
49
98
50
99
using ::google::pubsub::v1::PubsubMessage;
51
- using ::cloudevents::binder::Binder
100
+ using ::cloudevents::binder::PubsubBinder
52
101
using ::cloudevents::format::Format
102
+ using ::cloudevents_absl::StatusOr;
53
103
54
104
// create a CloudEvent
55
105
CloudEvent my_cloud_event;
@@ -59,11 +109,19 @@ my_cloud_event.set_spec_version("1.0");
59
109
my_cloud_event.set_type("my_type");
60
110
my_cloud_event.set_binary_data("1010");
61
111
62
- // Initialize the binder
63
- Binder<PubsubMessage> pubsub_binder;
112
+ // initialize the binder
113
+ PubsubBinder pubsub_binder;
114
+
115
+ // specify the EventFormat to be used and create the Message
116
+ StatusOr<PubsubMessage> bind = pubsub_binder.Bind(my_cloud_event, Format::kJson);
64
117
65
- // Specify the EventFormat to be used and create the Message
66
- PubsubMessage usable_message = pubsub_binder.Bind(my_cloud_event, Format::kJson);
118
+ // check no errors
119
+ if (!bind.ok()) {
120
+ std::cerr << bind.status();
121
+ }
122
+
123
+ // unwrap message
124
+ PubsubMessage usable_message = *bind;
67
125
```
68
126
69
127
## Unbind a CloudEvent from a Protocol-Message
@@ -73,15 +131,24 @@ PubsubMessage usable_message = pubsub_binder.Bind(my_cloud_event, Format::kJson)
73
131
74
132
using ::google::pubsub::v1::PubsubMessage;
75
133
using ::cloudevents::binder::Binder
76
- using ::cloudevents::format::Format
134
+ using ::cloudevents_absl::StatusOr;
77
135
78
- PubsubMessage my_pusub_msg; // how you get this message is out of scope for this SDK
136
+ PubsubMessage my_pusub_msg = ... ; // However you get this message
79
137
80
- // Initialize the binder
81
- Binder<PubsubMessage> pubsub_binder;
138
+ // initialize the binder
139
+ PubsubBinder pubsub_binder;
140
+
141
+ // create the CloudEvent
142
+ StatusOr<CloudEvent> unbind = pubsub_binder.Unbind(my_pusub_msg);
143
+
144
+ // check no errors
145
+ if (!unbind.ok()) {
146
+ std::cerr << unbind.status();
147
+ }
148
+
149
+ // unwrap cloudevent
150
+ CloudEvent cloud_event = *unbind;
82
151
83
- // Create the CloudEvent
84
- CloudEvent my_cloud_event = pubsub_binder.Unbind(my_pusub_msg);
85
152
```
86
153
87
154
# Samples
@@ -97,14 +164,3 @@ Run-able code samples are available in the `/samples` folder.
97
164
All logic related to implementing version 1 of the CloudEvent spec can be found in ` //v1 ` .
98
165
- All logic for [ Protocol Binding] ( https://github.com/cloudevents/spec/blob/master/spec.md#protocol-binding ) s can be found in the subfolder ` //v1/protocol_binding ` .
99
166
- All logic for [ Event Format] ( https://github.com/cloudevents/spec/blob/master/spec.md#event-format ) s can be found in the subfolder ` //v1/event_format ` .
100
-
101
- # Dependencies
102
- ## Json
103
- Using [ Nuxi NL's bazel setup] (https://github.com/NuxiNL/bazel-third-party ) to setup a bazel target for jsoncpp
104
-
105
- ## base64
106
- Using René Nyffenegger's [ base64 encoding/ decoding lib] ( https://github.com/ReneNyffenegger/cpp-base64 ) .
107
-
108
- ## Abseil StatusOr
109
- Copying [ Envoy's Abseil StatusOr setup] ( https://github.com/envoyproxy/envoy/tree/44eedc792ab64bba2358e0294b53294c6bc30526/third_party/statusor ) temporarily until an official abseil release exists.
110
-
0 commit comments