mirror of
https://gitee.com/zyjblog/oatpp.git
synced 2024-12-22 22:16:37 +08:00
Better ObjectMapping
This commit is contained in:
parent
6effe7ae30
commit
204e8cce2a
@ -60,7 +60,7 @@ public:
|
||||
virtual void write(const std::shared_ptr<oatpp::data::stream::OutputStream>& stream,
|
||||
const type::AbstractObjectWrapper& variant) const = 0;
|
||||
|
||||
virtual type::AbstractObjectWrapper read(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
virtual type::AbstractObjectWrapper read(oatpp::parser::ParsingCaret& caret,
|
||||
const type::Type* const type) const = 0;
|
||||
|
||||
oatpp::String writeToString(const type::AbstractObjectWrapper& variant) const {
|
||||
@ -70,7 +70,7 @@ public:
|
||||
}
|
||||
|
||||
template<class Class>
|
||||
typename Class::ObjectWrapper readFromCaret(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret) const {
|
||||
typename Class::ObjectWrapper readFromCaret(oatpp::parser::ParsingCaret& caret) const {
|
||||
auto type = Class::ObjectWrapper::Class::getType();
|
||||
return oatpp::data::mapping::type::static_wrapper_cast<typename Class::ObjectWrapper::ObjectType>(read(caret, type));
|
||||
}
|
||||
@ -78,7 +78,7 @@ public:
|
||||
template<class Class>
|
||||
typename Class::ObjectWrapper readFromString(const oatpp::String& str) const {
|
||||
auto type = Class::ObjectWrapper::Class::getType();
|
||||
auto caret = oatpp::parser::ParsingCaret::createShared(str.getPtr());
|
||||
oatpp::parser::ParsingCaret caret(str);
|
||||
return oatpp::data::mapping::type::static_wrapper_cast<typename Class::ObjectWrapper::ObjectType>(read(caret, type));
|
||||
}
|
||||
|
||||
|
@ -113,11 +113,6 @@ public:
|
||||
return empty;
|
||||
}
|
||||
|
||||
/* bool equals(const String& other) const {
|
||||
return m_ptr->equals(other.get());
|
||||
}
|
||||
*/
|
||||
|
||||
bool operator==(const String &other) const {
|
||||
return m_ptr->equals(other.get());
|
||||
}
|
||||
|
@ -355,14 +355,14 @@ std::string Utils::unescapeStringToStdString(p_char8 data, v_int32 size,
|
||||
return result;
|
||||
}
|
||||
|
||||
p_char8 Utils::preparseString(const std::shared_ptr<ParsingCaret>& caret, v_int32& size){
|
||||
p_char8 Utils::preparseString(ParsingCaret& caret, v_int32& size){
|
||||
|
||||
if(caret->canContinueAtChar('"', 1)){
|
||||
if(caret.canContinueAtChar('"', 1)){
|
||||
|
||||
const p_char8 data = caret->getData();
|
||||
v_int32 pos = caret->getPosition();
|
||||
const p_char8 data = caret.getData();
|
||||
v_int32 pos = caret.getPosition();
|
||||
v_int32 pos0 = pos;
|
||||
v_int32 length = caret->getSize();
|
||||
v_int32 length = caret.getSize();
|
||||
|
||||
while (pos < length) {
|
||||
v_char8 a = data[pos];
|
||||
@ -375,33 +375,33 @@ p_char8 Utils::preparseString(const std::shared_ptr<ParsingCaret>& caret, v_int3
|
||||
pos ++;
|
||||
}
|
||||
}
|
||||
caret->setPosition(caret->getSize());
|
||||
caret->setError(ERROR_PARSER_QUOTE_EXPECTED);
|
||||
caret.setPosition(caret.getSize());
|
||||
caret.setError(ERROR_PARSER_QUOTE_EXPECTED);
|
||||
} else {
|
||||
caret->setError(ERROR_PARSER_QUOTE_EXPECTED);
|
||||
caret.setError(ERROR_PARSER_QUOTE_EXPECTED);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
oatpp::String Utils::parseString(const std::shared_ptr<ParsingCaret>& caret) {
|
||||
oatpp::String Utils::parseString(ParsingCaret& caret) {
|
||||
|
||||
v_int32 size;
|
||||
p_char8 data = preparseString(caret, size);
|
||||
|
||||
if(data != nullptr) {
|
||||
|
||||
v_int32 pos = caret->getPosition();
|
||||
v_int32 pos = caret.getPosition();
|
||||
|
||||
const char* error;
|
||||
v_int32 errorPosition;
|
||||
auto result = unescapeString(data, size, error, errorPosition);
|
||||
if(error != nullptr){
|
||||
caret->setError(error);
|
||||
caret->setPosition(pos + errorPosition);
|
||||
caret.setError(error);
|
||||
caret.setPosition(pos + errorPosition);
|
||||
} else {
|
||||
caret->setPosition(pos + size + 1);
|
||||
caret.setPosition(pos + size + 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -412,23 +412,23 @@ oatpp::String Utils::parseString(const std::shared_ptr<ParsingCaret>& caret) {
|
||||
|
||||
}
|
||||
|
||||
std::string Utils::parseStringToStdString(const std::shared_ptr<ParsingCaret>& caret){
|
||||
std::string Utils::parseStringToStdString(ParsingCaret& caret){
|
||||
|
||||
v_int32 size;
|
||||
p_char8 data = preparseString(caret, size);
|
||||
|
||||
if(data != nullptr) {
|
||||
|
||||
v_int32 pos = caret->getPosition();
|
||||
v_int32 pos = caret.getPosition();
|
||||
|
||||
const char* error;
|
||||
v_int32 errorPosition;
|
||||
const std::string& result = unescapeStringToStdString(data, size, error, errorPosition);
|
||||
if(error != nullptr){
|
||||
caret->setError(error);
|
||||
caret->setPosition(pos + errorPosition);
|
||||
caret.setError(error);
|
||||
caret.setPosition(pos + errorPosition);
|
||||
} else {
|
||||
caret->setPosition(pos + size + 1);
|
||||
caret.setPosition(pos + size + 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -46,7 +46,7 @@ private:
|
||||
static v_int32 calcEscapedStringSize(p_char8 data, v_int32 size, v_int32& safeSize);
|
||||
static v_int32 calcUnescapedStringSize(p_char8 data, v_int32 size, const char* & error, v_int32& errorPosition);
|
||||
static void unescapeStringToBuffer(p_char8 data, v_int32 size, p_char8 resultData);
|
||||
static p_char8 preparseString(const std::shared_ptr<ParsingCaret>& caret, v_int32& size);
|
||||
static p_char8 preparseString(ParsingCaret& caret, v_int32& size);
|
||||
public:
|
||||
|
||||
static String escapeString(p_char8 data, v_int32 size);
|
||||
@ -54,8 +54,8 @@ public:
|
||||
static std::string unescapeStringToStdString(p_char8 data, v_int32 size,
|
||||
const char* & error, v_int32& errorPosition);
|
||||
|
||||
static String parseString(const std::shared_ptr<ParsingCaret>& caret);
|
||||
static std::string parseStringToStdString(const std::shared_ptr<ParsingCaret>& caret);
|
||||
static String parseString(ParsingCaret& caret);
|
||||
static std::string parseStringToStdString(ParsingCaret& caret);
|
||||
|
||||
};
|
||||
|
||||
|
@ -36,11 +36,11 @@ const char* const Deserializer::ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING = "':' -
|
||||
const char* const Deserializer::ERROR_PARSER_ARRAY_SCOPE_OPEN = "'[' - expected";
|
||||
const char* const Deserializer::ERROR_PARSER_ARRAY_SCOPE_CLOSE = "']' - expected";
|
||||
|
||||
void Deserializer::skipScope(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret, v_char8 charOpen, v_char8 charClose){
|
||||
void Deserializer::skipScope(oatpp::parser::ParsingCaret& caret, v_char8 charOpen, v_char8 charClose){
|
||||
|
||||
p_char8 data = caret->getData();
|
||||
v_int32 size = caret->getSize();
|
||||
v_int32 pos = caret->getPosition();
|
||||
p_char8 data = caret.getData();
|
||||
v_int32 size = caret.getSize();
|
||||
v_int32 pos = caret.getPosition();
|
||||
v_int32 scopeCounter = 0;
|
||||
|
||||
bool isInString = false;
|
||||
@ -55,7 +55,7 @@ void Deserializer::skipScope(const std::shared_ptr<oatpp::parser::ParsingCaret>&
|
||||
if(!isInString){
|
||||
scopeCounter --;
|
||||
if(scopeCounter == 0){
|
||||
caret->setPosition(pos + 1);
|
||||
caret.setPosition(pos + 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -70,17 +70,17 @@ void Deserializer::skipScope(const std::shared_ptr<oatpp::parser::ParsingCaret>&
|
||||
}
|
||||
}
|
||||
|
||||
void Deserializer::skipString(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
|
||||
p_char8 data = caret->getData();
|
||||
v_int32 size = caret->getSize();
|
||||
v_int32 pos = caret->getPosition();
|
||||
void Deserializer::skipString(oatpp::parser::ParsingCaret& caret){
|
||||
p_char8 data = caret.getData();
|
||||
v_int32 size = caret.getSize();
|
||||
v_int32 pos = caret.getPosition();
|
||||
v_int32 scopeCounter = 0;
|
||||
while(pos < size){
|
||||
v_char8 a = data[pos];
|
||||
if(a == '"'){
|
||||
scopeCounter ++;
|
||||
if(scopeCounter == 2) {
|
||||
caret->setPosition(pos + 1);
|
||||
caret.setPosition(pos + 1);
|
||||
return;
|
||||
}
|
||||
} else if(a == '\\'){
|
||||
@ -90,85 +90,85 @@ void Deserializer::skipString(const std::shared_ptr<oatpp::parser::ParsingCaret>
|
||||
}
|
||||
}
|
||||
|
||||
void Deserializer::skipToken(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
|
||||
p_char8 data = caret->getData();
|
||||
v_int32 size = caret->getSize();
|
||||
v_int32 pos = caret->getPosition();
|
||||
void Deserializer::skipToken(oatpp::parser::ParsingCaret& caret){
|
||||
p_char8 data = caret.getData();
|
||||
v_int32 size = caret.getSize();
|
||||
v_int32 pos = caret.getPosition();
|
||||
while(pos < size){
|
||||
v_char8 a = data[pos];
|
||||
if(a == ' ' || a == '\t' || a == '\n' || a == '\r' || a == '\b' || a == '\f' ||
|
||||
a == '}' || a == ',' || a == ']') {
|
||||
caret->setPosition(pos);
|
||||
caret.setPosition(pos);
|
||||
return;
|
||||
}
|
||||
pos ++;
|
||||
}
|
||||
}
|
||||
|
||||
void Deserializer::skipValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
|
||||
if(caret->isAtChar('{')){
|
||||
void Deserializer::skipValue(oatpp::parser::ParsingCaret& caret){
|
||||
if(caret.isAtChar('{')){
|
||||
skipScope(caret, '{', '}');
|
||||
} else if(caret->isAtChar('[')){
|
||||
} else if(caret.isAtChar('[')){
|
||||
skipScope(caret, '[', ']');
|
||||
} else if(caret->isAtChar('"')){
|
||||
} else if(caret.isAtChar('"')){
|
||||
skipString(caret);
|
||||
} else {
|
||||
skipToken(caret);
|
||||
}
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readStringValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
|
||||
if(caret->proceedIfFollowsText("null")){
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readStringValue(oatpp::parser::ParsingCaret& caret){
|
||||
if(caret.proceedIfFollowsText("null")){
|
||||
return AbstractObjectWrapper(String::Class::getType());
|
||||
} else {
|
||||
return AbstractObjectWrapper(oatpp::parser::json::Utils::parseString(caret).getPtr(), String::Class::getType());
|
||||
}
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readInt32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
|
||||
if(caret->proceedIfFollowsText("null")){
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readInt32Value(oatpp::parser::ParsingCaret& caret){
|
||||
if(caret.proceedIfFollowsText("null")){
|
||||
return AbstractObjectWrapper(Int32::ObjectWrapper::Class::getType());
|
||||
} else {
|
||||
return AbstractObjectWrapper(Int32::ObjectType::createAbstract(caret->parseInt32()), Int32::ObjectWrapper::Class::getType());
|
||||
return AbstractObjectWrapper(Int32::ObjectType::createAbstract(caret.parseInt32()), Int32::ObjectWrapper::Class::getType());
|
||||
}
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readInt64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
|
||||
if(caret->proceedIfFollowsText("null")){
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readInt64Value(oatpp::parser::ParsingCaret& caret){
|
||||
if(caret.proceedIfFollowsText("null")){
|
||||
return AbstractObjectWrapper(Int64::ObjectWrapper::Class::getType());
|
||||
} else {
|
||||
return AbstractObjectWrapper(Int64::ObjectType::createAbstract(caret->parseInt64()), Int64::ObjectWrapper::Class::getType());
|
||||
return AbstractObjectWrapper(Int64::ObjectType::createAbstract(caret.parseInt64()), Int64::ObjectWrapper::Class::getType());
|
||||
}
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readFloat32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
|
||||
if(caret->proceedIfFollowsText("null")){
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readFloat32Value(oatpp::parser::ParsingCaret& caret){
|
||||
if(caret.proceedIfFollowsText("null")){
|
||||
return AbstractObjectWrapper(Float32::ObjectWrapper::Class::getType());
|
||||
} else {
|
||||
return AbstractObjectWrapper(Float32::ObjectType::createAbstract(caret->parseFloat32()), Float32::ObjectWrapper::Class::getType());
|
||||
return AbstractObjectWrapper(Float32::ObjectType::createAbstract(caret.parseFloat32()), Float32::ObjectWrapper::Class::getType());
|
||||
}
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readFloat64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
|
||||
if(caret->proceedIfFollowsText("null")){
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readFloat64Value(oatpp::parser::ParsingCaret& caret){
|
||||
if(caret.proceedIfFollowsText("null")){
|
||||
return AbstractObjectWrapper(Float64::ObjectWrapper::Class::getType());
|
||||
} else {
|
||||
return AbstractObjectWrapper(Float64::ObjectType::createAbstract(caret->parseFloat64()), Float64::ObjectWrapper::Class::getType());
|
||||
return AbstractObjectWrapper(Float64::ObjectType::createAbstract(caret.parseFloat64()), Float64::ObjectWrapper::Class::getType());
|
||||
}
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readBooleanValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret){
|
||||
if(caret->proceedIfFollowsText("null")){
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readBooleanValue(oatpp::parser::ParsingCaret& caret){
|
||||
if(caret.proceedIfFollowsText("null")){
|
||||
return AbstractObjectWrapper(Boolean::ObjectWrapper::Class::getType());
|
||||
} else {
|
||||
return AbstractObjectWrapper(Boolean::ObjectType::createAbstract(caret->parseBoolean("true", "false")), Boolean::ObjectWrapper::Class::getType());
|
||||
return AbstractObjectWrapper(Boolean::ObjectType::createAbstract(caret.parseBoolean("true", "false")), Boolean::ObjectWrapper::Class::getType());
|
||||
}
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readObjectValue(const Type* const type,
|
||||
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config){
|
||||
if(caret->proceedIfFollowsText("null")){
|
||||
if(caret.proceedIfFollowsText("null")){
|
||||
return AbstractObjectWrapper::empty();
|
||||
} else {
|
||||
return readObject(type, caret, config);
|
||||
@ -176,9 +176,9 @@ Deserializer::AbstractObjectWrapper Deserializer::readObjectValue(const Type* co
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readListValue(const Type* const type,
|
||||
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config){
|
||||
if(caret->proceedIfFollowsText("null")){
|
||||
if(caret.proceedIfFollowsText("null")){
|
||||
return AbstractObjectWrapper::empty();
|
||||
} else {
|
||||
return readList(type, caret, config);
|
||||
@ -186,7 +186,7 @@ Deserializer::AbstractObjectWrapper Deserializer::readListValue(const Type* cons
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readValue(const Type* const type,
|
||||
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config){
|
||||
|
||||
auto typeName = type->name;
|
||||
@ -215,10 +215,10 @@ Deserializer::AbstractObjectWrapper Deserializer::readValue(const Type* const ty
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readList(const Type* type,
|
||||
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config){
|
||||
|
||||
if(caret->canContinueAtChar('[', 1)) {
|
||||
if(caret.canContinueAtChar('[', 1)) {
|
||||
|
||||
auto listWrapper = type->creator();
|
||||
oatpp::data::mapping::type::PolymorphicWrapper<AbstractList>
|
||||
@ -226,88 +226,88 @@ Deserializer::AbstractObjectWrapper Deserializer::readList(const Type* type,
|
||||
|
||||
Type* itemType = *type->params.begin();
|
||||
|
||||
while(!caret->isAtChar(']') && caret->canContinue()){
|
||||
while(!caret.isAtChar(']') && caret.canContinue()){
|
||||
|
||||
caret->findNotBlankChar();
|
||||
caret.findNotBlankChar();
|
||||
auto item = readValue(itemType, caret, config);
|
||||
if(caret->hasError()){
|
||||
if(caret.hasError()){
|
||||
return AbstractObjectWrapper::empty();
|
||||
}
|
||||
|
||||
list->addPolymorphicItem(item);
|
||||
caret->findNotBlankChar();
|
||||
caret.findNotBlankChar();
|
||||
|
||||
caret->canContinueAtChar(',', 1);
|
||||
caret.canContinueAtChar(',', 1);
|
||||
|
||||
}
|
||||
|
||||
if(!caret->canContinueAtChar(']', 1)){
|
||||
if(!caret->hasError()){
|
||||
caret->setError(ERROR_PARSER_ARRAY_SCOPE_CLOSE);
|
||||
if(!caret.canContinueAtChar(']', 1)){
|
||||
if(!caret.hasError()){
|
||||
caret.setError(ERROR_PARSER_ARRAY_SCOPE_CLOSE);
|
||||
}
|
||||
return AbstractObjectWrapper::empty();
|
||||
};
|
||||
|
||||
return AbstractObjectWrapper(list.getPtr(), list.valueType);
|
||||
} else {
|
||||
caret->setError(ERROR_PARSER_ARRAY_SCOPE_OPEN);
|
||||
caret.setError(ERROR_PARSER_ARRAY_SCOPE_OPEN);
|
||||
return AbstractObjectWrapper::empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
|
||||
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config){
|
||||
|
||||
if(caret->canContinueAtChar('{', 1)) {
|
||||
if(caret.canContinueAtChar('{', 1)) {
|
||||
|
||||
auto object = type->creator();
|
||||
auto fieldsMap = type->properties;
|
||||
|
||||
while (!caret->isAtChar('}') && caret->canContinue()) {
|
||||
while (!caret.isAtChar('}') && caret.canContinue()) {
|
||||
|
||||
caret->findNotBlankChar();
|
||||
caret.findNotBlankChar();
|
||||
auto key = Utils::parseStringToStdString(caret);
|
||||
if(caret->hasError()){
|
||||
if(caret.hasError()){
|
||||
return AbstractObjectWrapper::empty();
|
||||
}
|
||||
|
||||
auto fieldIterator = fieldsMap->find(key);
|
||||
if(fieldIterator != fieldsMap->end()){
|
||||
|
||||
caret->findNotBlankChar();
|
||||
if(!caret->canContinueAtChar(':', 1)){
|
||||
caret->setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING);
|
||||
caret.findNotBlankChar();
|
||||
if(!caret.canContinueAtChar(':', 1)){
|
||||
caret.setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING);
|
||||
return AbstractObjectWrapper::empty();
|
||||
}
|
||||
|
||||
caret->findNotBlankChar();
|
||||
caret.findNotBlankChar();
|
||||
|
||||
auto field = fieldIterator->second;
|
||||
field->set(object.get(), readValue(field->type, caret, config));
|
||||
|
||||
} else if (config->allowUnknownFields) {
|
||||
caret->findNotBlankChar();
|
||||
if(!caret->canContinueAtChar(':', 1)){
|
||||
caret->setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING);
|
||||
caret.findNotBlankChar();
|
||||
if(!caret.canContinueAtChar(':', 1)){
|
||||
caret.setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING);
|
||||
return AbstractObjectWrapper::empty();
|
||||
}
|
||||
caret->findNotBlankChar();
|
||||
caret.findNotBlankChar();
|
||||
skipValue(caret);
|
||||
} else {
|
||||
caret->setError(ERROR_PARSER_OBJECT_SCOPE_UNKNOWN_FIELD);
|
||||
caret.setError(ERROR_PARSER_OBJECT_SCOPE_UNKNOWN_FIELD);
|
||||
return AbstractObjectWrapper::empty();
|
||||
}
|
||||
|
||||
caret->findNotBlankChar();
|
||||
caret->canContinueAtChar(',', 1);
|
||||
caret.findNotBlankChar();
|
||||
caret.canContinueAtChar(',', 1);
|
||||
|
||||
};
|
||||
|
||||
if(!caret->canContinueAtChar('}', 1)){
|
||||
if(!caret->hasError()){
|
||||
caret->setError(ERROR_PARSER_OBJECT_SCOPE_CLOSE);
|
||||
if(!caret.canContinueAtChar('}', 1)){
|
||||
if(!caret.hasError()){
|
||||
caret.setError(ERROR_PARSER_OBJECT_SCOPE_CLOSE);
|
||||
}
|
||||
return AbstractObjectWrapper::empty();
|
||||
}
|
||||
@ -315,7 +315,7 @@ Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
|
||||
return object;
|
||||
|
||||
} else {
|
||||
caret->setError(ERROR_PARSER_OBJECT_SCOPE_OPEN);
|
||||
caret.setError(ERROR_PARSER_OBJECT_SCOPE_OPEN);
|
||||
}
|
||||
|
||||
return AbstractObjectWrapper::empty();
|
||||
|
@ -81,39 +81,39 @@ public:
|
||||
static const char* const ERROR_PARSER_ARRAY_SCOPE_CLOSE;
|
||||
private:
|
||||
|
||||
static void skipScope(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret, v_char8 charOpen, v_char8 charClose);
|
||||
static void skipString(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
|
||||
static void skipToken(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
|
||||
static void skipValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
|
||||
static void skipScope(oatpp::parser::ParsingCaret& caret, v_char8 charOpen, v_char8 charClose);
|
||||
static void skipString(oatpp::parser::ParsingCaret& caret);
|
||||
static void skipToken(oatpp::parser::ParsingCaret& caret);
|
||||
static void skipValue(oatpp::parser::ParsingCaret& caret);
|
||||
|
||||
static AbstractObjectWrapper readStringValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
|
||||
static AbstractObjectWrapper readInt32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
|
||||
static AbstractObjectWrapper readInt64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
|
||||
static AbstractObjectWrapper readFloat32Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
|
||||
static AbstractObjectWrapper readFloat64Value(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
|
||||
static AbstractObjectWrapper readBooleanValue(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret);
|
||||
static AbstractObjectWrapper readStringValue(oatpp::parser::ParsingCaret& caret);
|
||||
static AbstractObjectWrapper readInt32Value(oatpp::parser::ParsingCaret& caret);
|
||||
static AbstractObjectWrapper readInt64Value(oatpp::parser::ParsingCaret& caret);
|
||||
static AbstractObjectWrapper readFloat32Value(oatpp::parser::ParsingCaret& caret);
|
||||
static AbstractObjectWrapper readFloat64Value(oatpp::parser::ParsingCaret& caret);
|
||||
static AbstractObjectWrapper readBooleanValue(oatpp::parser::ParsingCaret& caret);
|
||||
static AbstractObjectWrapper readObjectValue(const Type* const type,
|
||||
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config);
|
||||
static AbstractObjectWrapper readListValue(const Type* const type,
|
||||
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config);
|
||||
|
||||
static AbstractObjectWrapper readValue(const Type* const type,
|
||||
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config);
|
||||
|
||||
static AbstractObjectWrapper readList(const Type* const type,
|
||||
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config);
|
||||
|
||||
static AbstractObjectWrapper readObject(const Type* const type,
|
||||
const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config);
|
||||
|
||||
public:
|
||||
|
||||
static AbstractObjectWrapper deserialize(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
static AbstractObjectWrapper deserialize(oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config,
|
||||
const Type* const type) {
|
||||
if(type->name == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME){
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
}
|
||||
|
||||
oatpp::data::mapping::type::AbstractObjectWrapper
|
||||
read(const std::shared_ptr<oatpp::parser::ParsingCaret>& caret,
|
||||
read(oatpp::parser::ParsingCaret& caret,
|
||||
const oatpp::data::mapping::type::Type* const type) const override {
|
||||
return Deserializer::deserialize(caret, deserializerConfig, type);
|
||||
}
|
||||
|
@ -83,9 +83,9 @@ bool DTOMapperPerfTest::onRun() {
|
||||
|
||||
{
|
||||
PerformanceChecker checker("Deserializer");
|
||||
auto caret = oatpp::parser::ParsingCaret::createShared(test1_Text);
|
||||
oatpp::parser::ParsingCaret caret(test1_Text);
|
||||
for(v_int32 i = 0; i < numIterations; i ++) {
|
||||
caret->setPosition(0);
|
||||
caret.setPosition(0);
|
||||
mapper->readFromCaret<Test1>(caret);
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ bool DTOMapperTest::onRun(){
|
||||
OATPP_LOGD(TAG, "...");
|
||||
|
||||
auto config = oatpp::parser::json::mapping::Deserializer::Config::createShared();
|
||||
auto caret = oatpp::parser::ParsingCaret::createShared(result);
|
||||
oatpp::parser::ParsingCaret caret(result);
|
||||
auto obj = mapper->readFromCaret<Test>(caret);
|
||||
|
||||
OATPP_ASSERT(obj->_string);
|
||||
|
@ -79,7 +79,12 @@ private:
|
||||
}
|
||||
|
||||
oatpp::async::Action onDecoded() {
|
||||
auto dto = m_objectMapper->readFromString<Type>(m_chunkedBuffer->toString());
|
||||
auto body = m_chunkedBuffer->toString();
|
||||
oatpp::parser::ParsingCaret caret(body);
|
||||
auto dto = m_objectMapper->readFromCaret<Type>(caret);
|
||||
if(caret.hasError()) {
|
||||
return this->error(caret.getError());
|
||||
}
|
||||
return this->_return(dto);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user