Data-MessagePack-Stream
view release on metacpan or search on metacpan
msgpack-3.3.0/include/msgpack/v2/parse.hpp view on Meta::CPAN
m_cs = MSGPACK_CS_HEADER;
return PARSE_CONTINUE;
}
parse_return after_visit_proc(bool visit_result, std::size_t& off) {
++m_current;
if (!visit_result) {
off = static_cast<std::size_t>(m_current - m_start);
return PARSE_STOP_VISITOR;
}
parse_return ret = m_stack.consume(holder());
if (ret != PARSE_CONTINUE) {
off = static_cast<std::size_t>(m_current - m_start);
}
m_cs = MSGPACK_CS_HEADER;
return ret;
}
struct array_sv {
array_sv(VisitorHolder& visitor_holder):m_visitor_holder(visitor_holder) {}
bool operator()(uint32_t size) const {
return m_visitor_holder.visitor().start_array(size);
}
msgpack_container_type type() const { return MSGPACK_CT_ARRAY_ITEM; }
private:
VisitorHolder& m_visitor_holder;
};
struct array_ev {
array_ev(VisitorHolder& visitor_holder):m_visitor_holder(visitor_holder) {}
bool operator()() const {
return m_visitor_holder.visitor().end_array();
}
private:
VisitorHolder& m_visitor_holder;
};
struct map_sv {
map_sv(VisitorHolder& visitor_holder):m_visitor_holder(visitor_holder) {}
bool operator()(uint32_t size) const {
return m_visitor_holder.visitor().start_map(size);
}
msgpack_container_type type() const { return MSGPACK_CT_MAP_KEY; }
private:
VisitorHolder& m_visitor_holder;
};
struct map_ev {
map_ev(VisitorHolder& visitor_holder):m_visitor_holder(visitor_holder) {}
bool operator()() const {
return m_visitor_holder.visitor().end_map();
}
private:
VisitorHolder& m_visitor_holder;
};
struct unpack_stack {
struct stack_elem {
stack_elem(msgpack_container_type type, uint32_t rest):m_type(type), m_rest(rest) {}
msgpack_container_type m_type;
uint32_t m_rest;
};
unpack_stack() {
m_stack.reserve(MSGPACK_EMBED_STACK_SIZE);
}
parse_return push(VisitorHolder& visitor_holder, msgpack_container_type type, uint32_t rest) {
m_stack.push_back(stack_elem(type, rest));
switch (type) {
case MSGPACK_CT_ARRAY_ITEM:
return visitor_holder.visitor().start_array_item() ? PARSE_CONTINUE : PARSE_STOP_VISITOR;
case MSGPACK_CT_MAP_KEY:
return visitor_holder.visitor().start_map_key() ? PARSE_CONTINUE : PARSE_STOP_VISITOR;
case MSGPACK_CT_MAP_VALUE:
assert(0);
return PARSE_STOP_VISITOR;
}
assert(0);
return PARSE_STOP_VISITOR;
}
parse_return consume(VisitorHolder& visitor_holder) {
while (!m_stack.empty()) {
stack_elem& e = m_stack.back();
switch (e.m_type) {
case MSGPACK_CT_ARRAY_ITEM:
if (!visitor_holder.visitor().end_array_item()) return PARSE_STOP_VISITOR;
if (--e.m_rest == 0) {
m_stack.pop_back();
if (!visitor_holder.visitor().end_array()) return PARSE_STOP_VISITOR;
}
else {
if (!visitor_holder.visitor().start_array_item()) return PARSE_STOP_VISITOR;
return PARSE_CONTINUE;
}
break;
case MSGPACK_CT_MAP_KEY:
if (!visitor_holder.visitor().end_map_key()) return PARSE_STOP_VISITOR;
if (!visitor_holder.visitor().start_map_value()) return PARSE_STOP_VISITOR;
e.m_type = MSGPACK_CT_MAP_VALUE;
return PARSE_CONTINUE;
case MSGPACK_CT_MAP_VALUE:
if (!visitor_holder.visitor().end_map_value()) return PARSE_STOP_VISITOR;
if (--e.m_rest == 0) {
m_stack.pop_back();
if (!visitor_holder.visitor().end_map()) return PARSE_STOP_VISITOR;
}
else {
e.m_type = MSGPACK_CT_MAP_KEY;
if (!visitor_holder.visitor().start_map_key()) return PARSE_STOP_VISITOR;
return PARSE_CONTINUE;
}
break;
}
}
return PARSE_SUCCESS;
}
bool empty() const { return m_stack.empty(); }
void clear() { m_stack.clear(); }
private:
std::vector<stack_elem> m_stack;
};
char const* m_start;
char const* m_current;
( run in 0.470 second using v1.01-cache-2.11-cpan-5511b514fd6 )