Skip to content

Commit b267e0b

Browse files
committed
user guide: bazel dependencies + details
1 parent de42b9e commit b267e0b

File tree

1 file changed

+91
-35
lines changed

1 file changed

+91
-35
lines changed

README.md

+91-35
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,60 @@ The PubsubMessage class (generated from protobuf) is based on [Google API](https
1212
**This is not an officially supported Google product.**
1313

1414
# 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+
1518
## 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).
1721

18-
## Binding a CloudEvent to a Protocol-Message
19-
### BinaryContentMode
22+
### Import SDK as a Bazel package in WORKSPACE
23+
In `//WORKSPACE`
2024
```
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
2264
#include "//v1/protocol_binding/pubsub_binder.h"
23-
65+
2466
using ::google::pubsub::v1::PubsubMessage;
25-
using ::cloudevents::binder::Binder
67+
using ::cloudevents::binder::PubsubBinder;
68+
using ::cloudevents_absl::StatusOr;
2669
2770
// create a CloudEvent
2871
CloudEvent my_cloud_event;
@@ -33,23 +76,30 @@ my_cloud_event.set_type("my_type");
3376
my_cloud_event.set_binary_data("1010");
3477
3578
// Initialize the binder
36-
Binder<PubsubMessage> pubsub_binder;
79+
PubsubBinder pubsub_binder;
3780
3881
// Create the Message
39-
PubsubMessage usable_message = pubsub_binder.bind(my_cloud_event);
40-
```
82+
StatusOr<PubsubMessage> bind = pubsub_binder.Bind(my_cloud_event);
4183
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;
4391
```
44-
// import the header for formats
45-
#include "//v1/event_format/format.h"
4692

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
4897
#include "//v1/protocol_binding/pubsub_binder.h"
4998
5099
using ::google::pubsub::v1::PubsubMessage;
51-
using ::cloudevents::binder::Binder
100+
using ::cloudevents::binder::PubsubBinder
52101
using ::cloudevents::format::Format
102+
using ::cloudevents_absl::StatusOr;
53103
54104
// create a CloudEvent
55105
CloudEvent my_cloud_event;
@@ -59,11 +109,19 @@ my_cloud_event.set_spec_version("1.0");
59109
my_cloud_event.set_type("my_type");
60110
my_cloud_event.set_binary_data("1010");
61111
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);
64117
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;
67125
```
68126

69127
## Unbind a CloudEvent from a Protocol-Message
@@ -73,15 +131,24 @@ PubsubMessage usable_message = pubsub_binder.Bind(my_cloud_event, Format::kJson)
73131
74132
using ::google::pubsub::v1::PubsubMessage;
75133
using ::cloudevents::binder::Binder
76-
using ::cloudevents::format::Format
134+
using ::cloudevents_absl::StatusOr;
77135
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
79137
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;
82151
83-
// Create the CloudEvent
84-
CloudEvent my_cloud_event = pubsub_binder.Unbind(my_pusub_msg);
85152
```
86153

87154
# Samples
@@ -97,14 +164,3 @@ Run-able code samples are available in the `/samples` folder.
97164
All logic related to implementing version 1 of the CloudEvent spec can be found in `//v1`.
98165
- 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`.
99166
- 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

Comments
 (0)