Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/stephenberry/glaze
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenberry committed Aug 24, 2023
2 parents 76ece7c + c87fa90 commit e4d16e5
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 380 deletions.
14 changes: 7 additions & 7 deletions docs/json-rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ struct glz::meta<bar_result>

namespace rpc = glz::rpc;

auto main(int, char**) -> int {
rpc::server<rpc::server_method_t<"foo", foo_params, foo_result>,
rpc::server_method_t<"bar", bar_params, bar_result>>
int main() {
rpc::server<rpc::method<"foo", foo_params, foo_result>,
rpc::method<"bar", bar_params, bar_result>>
server;
rpc::client<rpc::client_method_t<"foo", foo_params, foo_result>,
rpc::client_method_t<"bar", bar_params, bar_result>>
rpc::client<rpc::method<"foo", foo_params, foo_result>,
rpc::method<"bar", bar_params, bar_result>>
client;

// One long living callback per method for the server
Expand All @@ -72,7 +72,7 @@ auto main(int, char**) -> int {
// params.foo_b
return foo_result{.foo_c = true, .foo_d = "new world"};
// Or return an error:
// return glz::unexpected(rpc::error(rpc::error_e::server_error_lower, "my error"));
// return glz::unexpected(rpc::error{rpc::error_e::server_error_lower, "my error"});
});
server.on<"bar">([](bar_params const& params) -> glz::expected<bar_result, rpc::error> {
return bar_result{.bar_c = true, .bar_d = "new world"};
Expand All @@ -83,7 +83,7 @@ auto main(int, char**) -> int {
auto [request_str, inserted] = client.request<"foo">(
uuid,
foo_params{.foo_a = 1337, .foo_b = "hello world"},
[](glz::expected<foo_result, rpc::error> value, rpc::jsonrpc_id_type id) -> void {
[](glz::expected<foo_result, rpc::error> value, rpc::id_t id) -> void {
// Access to value and/or id
});
// request_str: R"({"jsonrpc":"2.0","method":"foo","params":{"foo_a":1337,"foo_b":"hello world"},"id":"42"})"
Expand Down
16 changes: 8 additions & 8 deletions include/glaze/binary/write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ namespace glz
using Key = typename T::first_type;

constexpr uint8_t type = str_t<Key> ? 0 : (std::is_signed_v<Key> ? 0b000'01'000 : 0b000'10'000);
constexpr uint8_t byte_count = str_t<Key> ? 1 : sizeof(Key);
constexpr uint8_t tag = tag::object | type | (byte_count << 5);
constexpr uint8_t byte_cnt = str_t<Key> ? 1 : sizeof(Key);
constexpr uint8_t tag = tag::object | type | (byte_cnt << 5);
dump_type(tag, args...);

dump_compressed_int<Opts>(1, args...);
Expand All @@ -356,8 +356,8 @@ namespace glz
using Key = typename T::key_type;

constexpr uint8_t type = str_t<Key> ? 0 : (std::is_signed_v<Key> ? 0b000'01'000 : 0b000'10'000);
constexpr uint8_t byte_count = str_t<Key> ? 1 : sizeof(Key);
constexpr uint8_t tag = tag::object | type | (byte_count << 5);
constexpr uint8_t byte_cnt = str_t<Key> ? 1 : sizeof(Key);
constexpr uint8_t tag = tag::object | type | (byte_cnt << 5);
dump_type(tag, args...);

dump_compressed_int<Opts>(value.size(), args...);
Expand Down Expand Up @@ -391,8 +391,8 @@ namespace glz
GLZ_ALWAYS_INLINE static void op(auto&& value, is_context auto&& ctx, Args&&... args) noexcept
{
constexpr uint8_t type = 0;
constexpr uint8_t byte_count = 1;
constexpr uint8_t tag = tag::object | type | (byte_count << 5);
constexpr uint8_t byte_cnt = 1;
constexpr uint8_t tag = tag::object | type | (byte_cnt << 5);
dump_type(tag, args...);

using V = std::decay_t<T>;
Expand Down Expand Up @@ -480,8 +480,8 @@ namespace glz
static constexpr auto N = std::tuple_size_v<std::decay_t<decltype(groups)>>;

constexpr uint8_t type = 0;
constexpr uint8_t byte_count = sizeof(decltype(buffer[0]));
constexpr uint8_t tag = tag::object | type | (byte_count << 5);
constexpr uint8_t byte_cnt = sizeof(decltype(buffer[0]));
constexpr uint8_t tag = tag::object | type | (byte_cnt << 5);
detail::dump_type(tag, buffer);

detail::dump_compressed_int<N>(buffer);
Expand Down
1 change: 1 addition & 0 deletions include/glaze/core/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "glaze/core/meta.hpp"
#include "glaze/util/bit_array.hpp"
#include "glaze/util/expected.hpp"
#include "glaze/util/fixed_string.hpp"
#include "glaze/util/for_each.hpp"
#include "glaze/util/hash_map.hpp"
#include "glaze/util/murmur.hpp"
Expand Down
Loading

0 comments on commit e4d16e5

Please sign in to comment.