-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c1c7c9
commit d7e4cc6
Showing
11 changed files
with
183 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* utils.cpp | ||
* | ||
* Created on: Oct 24, 2024 | ||
* Author: mad | ||
*/ | ||
|
||
#include <mmx/utils.h> | ||
|
||
#include <vnx/vnx.h> | ||
|
||
|
||
namespace mmx { | ||
|
||
static bool validate_json(vnx::TypeInput& in, const uint16_t* code, const size_t max_recursion, size_t call_depth) | ||
{ | ||
if(++call_depth > max_recursion) { | ||
return false; | ||
} | ||
switch(code[0]) { | ||
case vnx::CODE_NULL: | ||
case vnx::CODE_BOOL: | ||
case vnx::CODE_UINT8: | ||
case vnx::CODE_UINT16: | ||
case vnx::CODE_UINT32: | ||
case vnx::CODE_UINT64: | ||
case vnx::CODE_INT8: | ||
case vnx::CODE_INT16: | ||
case vnx::CODE_INT32: | ||
case vnx::CODE_INT64: | ||
case vnx::CODE_STRING: | ||
case vnx::CODE_ALT_BOOL: | ||
case vnx::CODE_ALT_UINT8: | ||
case vnx::CODE_ALT_UINT16: | ||
case vnx::CODE_ALT_UINT32: | ||
case vnx::CODE_ALT_UINT64: | ||
case vnx::CODE_ALT_INT8: | ||
case vnx::CODE_ALT_INT16: | ||
case vnx::CODE_ALT_INT32: | ||
case vnx::CODE_ALT_INT64: | ||
case vnx::CODE_ALT_STRING: | ||
vnx::skip(in, nullptr, code); | ||
return true; | ||
case vnx::CODE_LIST: | ||
case vnx::CODE_ALT_LIST: { | ||
switch(code[1]) { | ||
case vnx::CODE_DYNAMIC: | ||
case vnx::CODE_ALT_DYNAMIC: | ||
break; | ||
default: | ||
return false; | ||
} | ||
uint32_t size; | ||
read(in, size); | ||
if(code[0] == vnx::CODE_ALT_LIST) { | ||
size = vnx::flip_bytes(size); | ||
} | ||
for(uint32_t i = 0; i < size; ++i) { | ||
if(!validate_json(in, code + 1, max_recursion, call_depth)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
case vnx::CODE_OBJECT: | ||
case vnx::CODE_ALT_OBJECT: { | ||
uint32_t size; | ||
read(in, size); | ||
if(code[0] == vnx::CODE_ALT_OBJECT) { | ||
size = vnx::flip_bytes(size); | ||
} | ||
for(uint32_t i = 0; i < size; ++i) { | ||
const uint16_t key_code = (code[0] == vnx::CODE_OBJECT ? vnx::CODE_STRING : vnx::CODE_ALT_STRING); | ||
const uint16_t value_code = (code[0] == vnx::CODE_OBJECT ? vnx::CODE_DYNAMIC : vnx::CODE_ALT_DYNAMIC); | ||
vnx::skip(in, nullptr, &key_code); | ||
if(!validate_json(in, &value_code, max_recursion, call_depth)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
case vnx::CODE_DYNAMIC: | ||
case vnx::CODE_ALT_DYNAMIC: { | ||
uint16_t byte_code[VNX_MAX_BYTE_CODE_SIZE]; | ||
vnx::read_byte_code(in, byte_code); | ||
return validate_json(in, byte_code, max_recursion, call_depth); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool is_json(const vnx::Variant& var) | ||
{ | ||
if(var.empty()) { | ||
return true; | ||
} | ||
vnx::VectorInputStream stream(&var.data); | ||
vnx::TypeInput in(&stream); | ||
const uint16_t code = vnx::CODE_DYNAMIC; | ||
return validate_json(in, &code, 100, 0); | ||
} | ||
|
||
|
||
} // mmx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule vnx-base
updated
6 files
+0 −12 | include/vnx/Variant.h | |
+2 −2 | make_debug.sh | |
+2 −2 | make_devel.sh | |
+3 −3 | make_release.sh | |
+0 −63 | src/Variant.cpp | |
+0 −27 | test/test_variant.cpp |