Skip to content

Commit 6799054

Browse files
committed
REPE conformance for registry errors
1 parent 02586e5 commit 6799054

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

include/glaze/rpc/repe/registry.hpp

+21-8
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,19 @@ namespace glz::repe
109109
if (bool(ctx.error)) {
110110
state.out.header.error = true;
111111
error_ctx ec{ctx.error, ctx.custom_error_message, size_t(b - start), ctx.includer_error};
112-
write_response<Opts>(error_t{error_code::parse_error, format_error(ec, state.in.body)}, state);
112+
113+
auto& in = state.in;
114+
auto& out = state.out;
115+
116+
std::string error_message = format_error(ec, in.body);
117+
const uint32_t n = uint32_t(error_message.size());
118+
out.header.body_length = 8 + n;
119+
out.body.resize(out.header.body_length);
120+
std::memcpy(out.body.data(), &ctx.error, 4);
121+
std::memcpy(out.body.data() + 4, &n, 4);
122+
std::memcpy(out.body.data() + 8, error_message.data(), n);
123+
124+
write_response<Opts>(state);
113125
return 0;
114126
}
115127

@@ -463,14 +475,15 @@ namespace glz::repe
463475
static constexpr error_code code = error_code::method_not_found;
464476
static constexpr sv body{"method not found"};
465477

466-
const auto body_length = 8 + body.size(); // 4 bytes for code, 4 bytes for size, + message
478+
const uint32_t n = uint32_t(body.size());
479+
const auto body_length = 8 + n; // 4 bytes for code, 4 bytes for size, + message
467480

468-
out.body.resize(sizeof(header) + body_length);
469-
header h{.error = true, .body_length = body_length};
470-
std::memcpy(out.body.data(), &h, sizeof(header));
471-
std::memcpy(out.body.data() + sizeof(header), &code, 4);
472-
std::memcpy(out.body.data() + sizeof(header) + 4, &body_length, 4);
473-
std::memcpy(out.body.data() + sizeof(header) + 8, body.data(), body.size());
481+
out.body.resize(body_length);
482+
out.header.error = true;
483+
out.header.body_length = body_length;
484+
std::memcpy(out.body.data(), &code, 4);
485+
std::memcpy(out.body.data() + 4, &n, 4);
486+
std::memcpy(out.body.data() + 8, body.data(), n);
474487
}
475488
}
476489
};

0 commit comments

Comments
 (0)