Skip to content

Commit f7306dd

Browse files
committed
Migrated to jsoncons for serialization
- jsoncons now used for JSON & Msgpack serializations. - Added CBOR serialization support. - Serialization encoder/decoders are now reused by Session. - Don't output warnings by default. - Wrapped long lines in README. - String variants are now output as quoted/escaped JSON. - Fix "Invocation is empty" in coroutine unpackers. - Renamed CodecBuffer to MessageBuffer - Revised Codec type requirements. - Simplified Transport type requirement. - Removed TransportBuffer requirement - Added toString free function for Variant, Array, and Object
1 parent a8cbf09 commit f7306dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3375
-2257
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
v0.9.0
2+
======
3+
Migrated to jsoncons for all serialization.
4+
5+
- Support for CBOR has been added.
6+
- Codecs have been split into encoders and decoders that can be instantiated
7+
and reused for multiple encoding/decoding operations.
8+
- Simplified passing of encoded WAMP messages between Peer and AsioTransport.
9+
- Added `toString` free functions for dumping `Variant`, `Array`, and `Object`
10+
as a JSON-formatted `std::string`.
11+
12+
### Breaking Changes
13+
14+
- The `Codec` type requirements have changed. It affects those who used codecs
15+
to encode/decode variants outside of the `Session` APIs. This also affects
16+
those who have extended CppWAMP to use their own custom codecs.
17+
- The `Transport` type requirements have changed. It affects those who
18+
extended CppWAMP to use their own custom transports.
19+
- Variant instances are output as true JSON via
20+
`operator(ostream&, const Variant&)`. That means strings variants are
21+
now output with quotes. Blob variants are now also output with quotes, along
22+
with a \u0000 prefix, as if they were being transmitted over WAMP.
23+
- Session warnings no longer output to `std::cerr` by default.
24+
`Session::setWarningHandler` must be explicitly called to re-enable this
25+
behavior.
26+
27+
128
v0.8.0
229
======
330
Refactored WAMP message processing.

CMakeLists.txt

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
# cppwamp-core | CppWAMP::core | Yes | Compiled libcppwamp-core library
1515
# cppwamp-core-headers | CppWAMP::core-headers | Yes | Header-only usage requirements
1616
# cppwamp-coro-headers | CppWAMP::coro-headers | Yes | Boost.Coroutine usage requirements
17-
# cppwamp-json | CppWAMP::json | Yes | Compiled libcppwamp-json library for JSON codec support
18-
# cppwmap-json-headers | CppWAMP::json-headers | Yes | Header-only RapidJSON usage requirements
19-
# cppwamp-msgpack | CppWAMP::msgpack | Yes | Compiled libcppwamp-msgpack library for Msgpack codec support
20-
# cppwamp-msgpack-headers | CppWAMP::msgpack-headers | Yes | Header-only Msgpack usage requirements
2117
# cppwamp-doc | <none> | No | Doxygen documentation
2218
# cppwamp-examples | <none> | No | Compiled example programs
2319
# cppwamp-test | <none> | No | Compiled test suite program
@@ -42,7 +38,7 @@ cmake_minimum_required (VERSION 3.12)
4238
include_guard()
4339

4440
project(CppWAMP
45-
VERSION 0.8.0
41+
VERSION 0.9.0
4642
LANGUAGES CXX)
4743

4844
include(ProcessorCount)
@@ -83,14 +79,6 @@ directed by defining <dependency>_ROOT variables. If the dependent targets are \
8379
already imported by a superproject, find_package calls will be skipped."
8480
OFF)
8581

86-
option(CPPWAMP_OPT_WITH_JSON
87-
"Adds the RapidJSON dependency and builds the cppwamp-json library"
88-
ON)
89-
90-
option(CPPWAMP_OPT_WITH_MSGPACK
91-
"Adds the msgpack-c dependency and builds the cppwamp-msgpack library"
92-
ON)
93-
9482
option(CPPWAMP_OPT_WITH_CORO
9583
"Adds the Boost.Coroutine dependency and build tests and examples \
9684
that depend on it"
@@ -145,14 +133,6 @@ cppwamp_resolve_dependencies()
145133

146134
add_subdirectory(cppwamp)
147135

148-
if(CPPWAMP_OPT_WITH_JSON)
149-
add_subdirectory(cppwamp-json)
150-
endif()
151-
152-
if(CPPWAMP_OPT_WITH_MSGPACK)
153-
add_subdirectory(cppwamp-msgpack)
154-
endif()
155-
156136
if(CPPWAMP_OPT_WITH_CORO)
157137
add_subdirectory(cppwamp-coro)
158138
endif()

README.md

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ C++11 client library for the [WAMP][wamp] protocol.
99
- Supports [some advanced WAMP profile features](#advanced)
1010
- Roles: _Caller_, _Callee_, _Subscriber_, _Publisher_
1111
- Transports: TCP and Unix domain raw sockets
12-
- Serializations: JSON and MsgPack
12+
- Serializations: JSON, MsgPack, and CBOR
1313
- Provides both callback and coroutine-based asynchronous APIs
1414
- Easy conversion between static and dynamic types
1515
- RPC and pub/sub event handlers can have static argument types
@@ -20,18 +20,17 @@ C++11 client library for the [WAMP][wamp] protocol.
2020

2121
**Dependencies**:
2222

23-
- [Boost.Asio][boost-asio] for raw socket transport (requires [Boost][boost] 1.74 or greater)
24-
- (optional) [RapidJSON][rapidjson] for JSON serialization
25-
- (optional) [msgpack-c][msgpack-c] for Msgpack serialization
23+
- [Boost.Asio][boost-asio] for raw socket transport
24+
(requires [Boost][boost] 1.74 or greater)
25+
- [jsoncons][jsoncons] for serialization
2626
- (optional) [Boost.Coroutine][boost-coroutine] and
2727
[Boost.Context][boost-context]
2828
- (optional) [CMake][cmake] and the [Catch2][catch2] unit test framework
2929

3030
[wamp]: http://wamp-proto.org/
3131
[boost-asio]: http://www.boost.org/doc/libs/release/doc/html/boost_asio.html
3232
[boost]: http://boost.org
33-
[rapidjson]: https://github.com/Tencent/rapidjson
34-
[msgpack-c]: https://github.com/msgpack/msgpack-c
33+
[jsoncons]: https://github.com/danielaparker/jsoncons
3534
[boost-coroutine]: http://www.boost.org/doc/libs/release/libs/coroutine/doc/html/index.html
3635
[boost-context]: http://www.boost.org/doc/libs/release/libs/context/doc/html/index.html
3736
[cmake]: http://www.cmake.org/
@@ -58,20 +57,24 @@ This library has been tested with:
5857
----------------------------------------------------------
5958

6059
- General: agent identification, feature announcement
61-
- _Callee_: `call_canceling`, `call_timeout`, `caller_identification`, `call_trustlevels`, `pattern_based_registration`, `progressive_call_results`
60+
- _Callee_: `call_canceling`, `call_timeout`, `caller_identification`,
61+
`call_trustlevels`, `pattern_based_registration`,
62+
`progressive_call_results`
6263
- _Caller_: `call_canceling`, `call_timeout`, `caller_identification`
63-
- _Publisher_: `publisher_exclusion`, `publisher_identification`, `subscriber_blackwhite_listing`
64-
- _Subscriber_: `pattern_based_subscription`, `publication_trustlevels`, `publisher_identification`
64+
- _Publisher_: `publisher_exclusion`, `publisher_identification`,
65+
`subscriber_blackwhite_listing`
66+
- _Subscriber_: `pattern_based_subscription`, `publication_trustlevels`,
67+
`publisher_identification`
6568

6669

6770
Roadmap
6871
-------
6972

7073
### v1.0
7174

72-
- Adopt the [jsoncons](https://github.com/danielaparker/jsoncons) library's cursor interface to implement the `wamp::Json` and `wamp::Msgpack` codecs, while retaining `wamp::Variant` as the document type.
7375
- Make `wamp::Session` more thread-safe.
74-
- Remove `wamp::CoroSession` and make it so that `wamp::Session` can accept any completion token (`yield`, `use_future`, etc) supported by Boost.Asio.
76+
- Remove `wamp::CoroSession` and make it so that `wamp::Session` can accept any
77+
completion token (`yield`, `use_future`, etc) supported by Boost.Asio.
7578

7679
### v1.1
7780

@@ -83,7 +86,9 @@ Roadmap
8386

8487
### v2.0 (maybe)
8588

86-
- Migrate from jsoncons to another serialization library currently in development, which features the ability to skip an intermediary variant type and directly encode/decode the network data into C++ data types.
89+
- Migrate from jsoncons to another serialization library currently in
90+
development, which features the ability to skip an intermediary variant type
91+
and directly encode/decode the network data into C++ data types.
8792

8893

8994
Questions, Discussions, and Issues
@@ -102,7 +107,9 @@ For reporting bugs or for suggesting enhancements, please use the GitHub
102107
Usage Examples Using Coroutines
103108
---------------------------------
104109

105-
_For a more comprehensive overview, check out the [Tutorials](https://ecorm.github.io/cppwamp/_tutorial.html) in the wiki._
110+
_For a more comprehensive overview, check out the
111+
[Tutorials](https://ecorm.github.io/cppwamp/_tutorial.html) in the
112+
documentation._
106113

107114
### Establishing a WAMP session
108115
```c++
@@ -338,9 +345,14 @@ session_->publish(wamp::Pub("sensorSampled").withArgs(value));
338345
Header-Only Installation
339346
------------------------
340347

341-
CppWAMP supports header-only usage. You may simply add the include directories of CppWAMP and its dependencies into your project's include search path. On GCC/Clang, this can be done with the `-isystem` compiler flag. You'll also need to link to the necessary Boost libraries.
348+
CppWAMP supports header-only usage. You may simply add the include directories
349+
of CppWAMP and its dependencies into your project's include search path. On
350+
GCC/Clang, this can be done with the `-isystem` compiler flag. You'll also need
351+
to link to the necessary Boost libraries.
342352

343-
You may use CppWAMP's CMake scripts to fetch and build dependencies. The following commands will clone the CppWAMP repository, build the third-party dependencies, and install the headers and CMake package config:
353+
You may use CppWAMP's CMake scripts to fetch and build dependencies. The
354+
following commands will clone the CppWAMP repository, build the third-party
355+
dependencies, and install the headers and CMake package config:
344356

345357
```bash
346358
git clone https://github.com/ecorm/cppwamp
@@ -353,14 +365,14 @@ cmake --install ./_build --prefix ./_stage/cppwamp
353365
Two subdirectories will be generated as a result:
354366

355367
- `_build` will contain intermediary build files and may be deleted.
356-
- `_stage` will contain third-party dependencies, as well as the CppWAMP headers and its CMake package config.
368+
- `_stage` will contain third-party dependencies, as well as the CppWAMP
369+
headers and its CMake package config.
357370

358371
You may then use the following GCC/Clang compiler flags:
359372
```
360373
-isystem path/to/cppwamp/_stage/boost/include
361374
-isystem path/to/cppwamp/_stage/cppwamp/include
362-
-isystem path/to/cppwamp/_stage/msgpack/include
363-
-isystem path/to/cppwamp/_stage/rapidjson/include
375+
-isystem path/to/cppwamp/_stage/jsoncons/include
364376
```
365377

366378
as well as the following GCC/Clang linker flags:
@@ -369,19 +381,22 @@ as well as the following GCC/Clang linker flags:
369381
-lboost_coroutine -lboost_context -lboost_thread -lboost_system
370382
```
371383

372-
Note that that only `-lboost_system` is necessary if you're not using the coroutine API.
384+
Note that only `-lboost_system` is necessary if you're not using the
385+
coroutine API.
373386

374-
You may omit the `-DCPPWAMP_OPT_VENDORIZE` option if you want to use the third-party libraries installed on your system. You may provide hints to their location via the following CMake configuration options:
387+
You may omit the `-DCPPWAMP_OPT_VENDORIZE` option if you want to use the
388+
third-party libraries installed on your system. You may provide hints to their
389+
location via the following CMake configuration options:
375390

376391
- `-DBoost_ROOT=path/to/boost`
377-
- `-DRapidJSON_ROOT=path/to/rapidjson`
378-
- `-DMsgpack_ROOT=path/to/msgpack`
392+
- `-Djsoncons_ROOT=path/to/jsoncons`
379393

380394

381395
Compiling the library, tests, and examples
382396
------------------------------------------
383397

384-
The steps are similar to the above _Header-Only Installation_, except that the `-DCPPWAMP_OPT_HEADERS_ONLY` option is omitted.
398+
The steps are similar to the above _Header-Only Installation_, except that
399+
the `-DCPPWAMP_OPT_HEADERS_ONLY` option is omitted.
385400

386401
```bash
387402
git clone https://github.com/ecorm/cppwamp
@@ -391,25 +406,25 @@ cmake --build ./_build
391406
cmake --install ./_build --prefix ./_stage/cppwamp
392407
```
393408

394-
The necessary compiler flags to use in your project are the same as the above _Header-Only Installation_, with the following extra needed linker flags:
409+
The necessary compiler flags to use in your project are the same as the above
410+
_Header-Only Installation_, with the following extra needed linker flags:
395411

396412
```
397413
-L path/to/cppwamp/_stage/cppwamp/lib
398-
-lcppwamp-json
399-
-lcppwamp-msgpack
400414
-lcppwamp-core
401415
```
402416

403-
where `-lcppwamp-json` or `-lcppwamp-msgpack` may be omitted if your project doesn't use that particular serialization.
417+
Consult the root CMakeLists.txt file for a list of `CPPWAMP_OPT_<option>` cache
418+
variables that control what's included in the build.
404419

405-
Consult the root CMakeLists.txt file for a list of `CPPWAMP_OPT_<option>` cache variables that control what's included in the build.
406420

407421
Integrating CppWAMP into a CMake-based Project
408422
----------------------------------------------
409423

410424
### With add_subdirectory
411425

412-
The following example CMakeLists.txt shows how to include CppWAMP via `add_subdirectory`:
426+
The following example CMakeLists.txt shows how to include CppWAMP via
427+
`add_subdirectory`:
413428

414429
```cmake
415430
cmake_minimum_required (VERSION 3.12)
@@ -419,27 +434,29 @@ if(allow_cppwamp_to_download_and_build_dependencies)
419434
option(CPPWAMP_OPT_VENDORIZE "" ON)
420435
else()
421436
option(CPPWAMP_OPT_VENDORIZE "" OFF)
422-
option(CPPWAMP_OPT_WITH_MSGPACK "" OFF) # Only JSON is needed for
423-
# this example
424437
# If the following are not set, CppWAMP will use the default
425438
# search paths of CMake's find_package() to find its dependencies.
426439
set(Boost_ROOT /path/to/boost)
427-
set(Msgpack_ROOT /path/to/msgpack)
440+
set(jsoncons_ROOT /path/to/jsoncons)
428441
endif()
429442
430443
add_subdirectory(cppwamp)
431444
add_executable(myapp main.cpp)
432445
target_link_libraries(myapp
433-
PRIVATE CppWAMP::json CppWAMP::coro-headers)
446+
PRIVATE CppWAMP::coro-headers)
434447
```
435448

436-
Any of the `CppWAMP::*` targets will automatically add the basic usage requirements of CppWAMP into your app's generated compiler/linker flags. The `CppWAMP::json` target, for example, will add the `libcppwamp-json` library, as well as the RapidJSON include search path.
449+
Any of the `CppWAMP::*` targets will automatically add the basic usage
450+
requirements of CppWAMP into your app's generated compiler/linker flags.
437451

438-
Please consult CppWAMP's root CMakeLists.txt file for a complete list of targets that you may specify for your app's `target_link_libraries`.
452+
Please consult CppWAMP's root CMakeLists.txt file for a complete list of
453+
targets that you may specify for your app's `target_link_libraries`.
439454

440455
### With FetchContent
441456

442-
You can use CMake's FetchContent to download CppWAMP and its dependencies at configuration time from within your project's CMakeLists.txt, as shown in the following example.
457+
You can use CMake's FetchContent to download CppWAMP and its dependencies at
458+
configuration time from within your project's CMakeLists.txt, as shown in the
459+
following example.
443460

444461
```cmake
445462
cmake_minimum_required (VERSION 3.12)
@@ -449,12 +466,10 @@ if(allow_cppwamp_to_download_and_build_dependencies)
449466
option(CPPWAMP_OPT_VENDORIZE "" ON)
450467
else()
451468
option(CPPWAMP_OPT_VENDORIZE "" OFF)
452-
option(CPPWAMP_OPT_WITH_MSGPACK "" OFF) # Only JSON is needed for
453-
# this example
454469
# If the following are not set, CppWAMP will use the default
455470
# search paths of CMake's find_package() to find its dependencies.
456471
set(Boost_ROOT /path/to/boost)
457-
set(RapidJSON_ROOT /path/to/rapidjson)
472+
set(jsoncons_ROOT /path/to/jsoncons)
458473
endif()
459474
460475
include(FetchContent)
@@ -467,12 +482,13 @@ FetchContent_MakeAvailable(cppwamp)
467482
add_executable(myapp main.cpp)
468483
469484
target_link_libraries(myapp
470-
PRIVATE CppWAMP::json CppWAMP::coro-headers)
485+
PRIVATE CppWAMP::coro-headers)
471486
```
472487

473488
### With find_package
474489

475-
If you do not wish to embed CppWAMP as a subdirectory of your project, you may use `find_package` instead:
490+
If you do not wish to embed CppWAMP as a subdirectory of your project, you may
491+
use `find_package` instead:
476492

477493
```cmake
478494
cmake_minimum_required (VERSION 3.12)
@@ -481,21 +497,24 @@ project(MyApp)
481497
# If the following are not set, CppWAMP will use the default
482498
# search paths of CMake's find_package() to find its dependencies.
483499
set(Boost_ROOT /path/to/boost)
484-
set(RapidJSON_ROOT /path/to/rapidjson)
485-
set(Msgpack_ROOT /path/to/msgpack)
500+
set(jsoncons_ROOT /path/to/jsoncons)
486501
487502
find_package(CppWAMP
488-
REQUIRED coro-headers json
503+
REQUIRED coro-headers
489504
CONFIG
490505
PATHS /path/to/cppwamp_installation
491506
NO_DEFAULT_PATH)
492507
493508
add_executable(myapp main.cpp)
494509
target_link_libraries(myapp
495-
PRIVATE CppWAMP::json CppWAMP::coro-headers)
510+
PRIVATE CppWAMP::coro-headers)
496511
```
497512

498-
This method requires that CppWAMP be previously built (either as header-only, or compiled) and installed so that its CMake package config (i.e. `CppWAMPConfig.cmake`) is generated. This can either be done outside of your project or via your project's CMake scripts (for example by using `ExternalProject_add` or `FetchContent`).
513+
This method requires that CppWAMP be previously built (either as header-only,
514+
or compiled) and installed so that its CMake package config
515+
(i.e. `CppWAMPConfig.cmake`) is generated. This can either be done outside of
516+
your project or via your project's CMake scripts (for example by using
517+
`ExternalProject_add` or `FetchContent`).
499518

500519

501520
License

0 commit comments

Comments
 (0)