Only pass CommitRequest to begin_streaming_parse
This commit is contained in:
@@ -453,8 +453,8 @@ bool JsonCommitRequestParser::parse(CommitRequest &request, char *data,
|
||||
if (!begin_streaming_parse(request)) {
|
||||
return false;
|
||||
}
|
||||
parse_chunk(request, data, len);
|
||||
finish_streaming_parse(request);
|
||||
parse_chunk(data, len);
|
||||
finish_streaming_parse();
|
||||
|
||||
return !has_parse_error() && !request.leader_id().empty() &&
|
||||
parser_context_->has_read_version_been_set;
|
||||
@@ -481,8 +481,7 @@ bool JsonCommitRequestParser::begin_streaming_parse(CommitRequest &request) {
|
||||
}
|
||||
|
||||
JsonCommitRequestParser::ParseStatus
|
||||
JsonCommitRequestParser::parse_chunk(CommitRequest &request, char *data,
|
||||
size_t len) {
|
||||
JsonCommitRequestParser::parse_chunk(char *data, size_t len) {
|
||||
if (!json_parser_ || !parser_context_) {
|
||||
return ParseStatus::Error;
|
||||
}
|
||||
@@ -495,7 +494,6 @@ JsonCommitRequestParser::parse_chunk(CommitRequest &request, char *data,
|
||||
return ParseStatus::Complete;
|
||||
}
|
||||
|
||||
current_request_ = &request;
|
||||
WeaselJsonStatus status = WeaselJsonParser_parse(json_parser_, data, len);
|
||||
|
||||
switch (status) {
|
||||
@@ -514,7 +512,7 @@ JsonCommitRequestParser::parse_chunk(CommitRequest &request, char *data,
|
||||
}
|
||||
|
||||
JsonCommitRequestParser::ParseStatus
|
||||
JsonCommitRequestParser::finish_streaming_parse(CommitRequest &request) {
|
||||
JsonCommitRequestParser::finish_streaming_parse() {
|
||||
if (!json_parser_ || !parser_context_) {
|
||||
return ParseStatus::Error;
|
||||
}
|
||||
@@ -523,15 +521,13 @@ JsonCommitRequestParser::finish_streaming_parse(CommitRequest &request) {
|
||||
return ParseStatus::Error;
|
||||
}
|
||||
|
||||
current_request_ = &request;
|
||||
|
||||
// Signal end of input
|
||||
WeaselJsonStatus status = WeaselJsonParser_parse(json_parser_, nullptr, 0);
|
||||
|
||||
if (status == WeaselJson_OK && parser_context_->parse_complete &&
|
||||
!parser_context_->parse_error) {
|
||||
// Clear the memory used only during parsing
|
||||
parser_context_->reset_arena_memory(&request.arena());
|
||||
parser_context_->reset_arena_memory(¤t_request_->arena());
|
||||
return ParseStatus::Complete;
|
||||
} else {
|
||||
parser_context_->parse_error =
|
||||
|
||||
@@ -116,9 +116,8 @@ public:
|
||||
// CommitRequestParser interface implementation
|
||||
bool parse(CommitRequest &request, char *data, size_t len) override;
|
||||
bool begin_streaming_parse(CommitRequest &request) override;
|
||||
ParseStatus parse_chunk(CommitRequest &request, char *data,
|
||||
size_t len) override;
|
||||
ParseStatus finish_streaming_parse(CommitRequest &request) override;
|
||||
ParseStatus parse_chunk(char *data, size_t len) override;
|
||||
ParseStatus finish_streaming_parse() override;
|
||||
bool has_parse_error() const override;
|
||||
const char *get_parse_error() const override;
|
||||
|
||||
|
||||
@@ -122,15 +122,15 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// Need mutable data for weaseljson
|
||||
std::string mutable_chunk = chunk;
|
||||
status = streaming_parser.parse_chunk(
|
||||
streaming_request, mutable_chunk.data(), mutable_chunk.size());
|
||||
status = streaming_parser.parse_chunk(mutable_chunk.data(),
|
||||
mutable_chunk.size());
|
||||
|
||||
offset += len;
|
||||
}
|
||||
|
||||
if (status == CommitRequestParser::ParseStatus::Incomplete) {
|
||||
std::cout << " Finalizing parse..." << std::endl;
|
||||
status = streaming_parser.finish_streaming_parse(streaming_request);
|
||||
status = streaming_parser.finish_streaming_parse();
|
||||
}
|
||||
|
||||
if (status == CommitRequestParser::ParseStatus::Complete) {
|
||||
|
||||
@@ -37,20 +37,17 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Parse additional data incrementally.
|
||||
* @param request The CommitRequest object to populate
|
||||
* @param data Pointer to the data buffer
|
||||
* @param len Length of the data
|
||||
* @return ParseStatus indicating current parse state
|
||||
*/
|
||||
virtual ParseStatus parse_chunk(CommitRequest &request, char *data,
|
||||
size_t len) = 0;
|
||||
virtual ParseStatus parse_chunk(char *data, size_t len) = 0;
|
||||
|
||||
/**
|
||||
* @brief Finish streaming parse (call when no more data is available).
|
||||
* @param request The CommitRequest object to populate
|
||||
* @return ParseStatus indicating final parse result
|
||||
*/
|
||||
virtual ParseStatus finish_streaming_parse(CommitRequest &request) = 0;
|
||||
virtual ParseStatus finish_streaming_parse() = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if there was a parse error.
|
||||
|
||||
Reference in New Issue
Block a user