-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mjson: Initial include of package #20129
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2023 Koen Zandberg | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
|
||
config PACKAGE_MJSON | ||
bool "mjson" | ||
depends on TEST_KCONFIG |
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,10 @@ | ||
PKG_NAME=mjson | ||
PKG_URL=https://github.com/cesanta/mjson | ||
# v1.2.7 | ||
PKG_VERSION=032a2eaca1a989e56d88218f2a3cb91a68afebe8 | ||
PKG_LICENSE=MIT | ||
|
||
include $(RIOTBASE)/pkg/pkg.mk | ||
|
||
all: | ||
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/src -f $(CURDIR)/$(PKG_NAME).mk |
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 @@ | ||
INCLUDES += -I$(PKGDIRBASE)/mjson/src |
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,16 @@ | ||
/** | ||
* @defgroup pkg_mjson mjson | ||
* @ingroup pkg | ||
* @brief mjson - a JSON parser + emitter + JSON-RPC engine | ||
* | ||
* # Introduction | ||
* | ||
* mjson is a small, embedded-friendly JSON parser, emitter and JSON-RPC | ||
* engine. | ||
* | ||
* # License | ||
* | ||
* Licensed under MIT. | ||
* | ||
* @see https://github.com/cesanta/mjson | ||
*/ |
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,7 @@ | ||
MODULE = mjson | ||
|
||
# The mjson_merge function requires an alloca implementation, disabled to | ||
# prevent stack memory allocations | ||
CFLAGS += -DMJSON_ENABLE_MERGE=0 | ||
|
||
include $(RIOTBASE)/Makefile.base |
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,6 @@ | ||
include ../Makefile.pkg_common | ||
|
||
USEMODULE += embunit | ||
USEPKG += mjson | ||
|
||
include $(RIOTBASE)/Makefile.include |
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,6 @@ | ||
BOARD_INSUFFICIENT_MEMORY := \ | ||
atmega8 \ | ||
nucleo-l011k4 \ | ||
samd10-xmini \ | ||
stm32f030f4-demo \ | ||
# |
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,2 @@ | ||
CONFIG_MODULE_EMBUNIT=y | ||
CONFIG_PACKAGE_MJSON=y |
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,80 @@ | ||
/* | ||
* Copyright (C) 2023 Koen Zandberg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief Test application for mjson | ||
* | ||
* @author Koen Zandberg <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include "embUnit.h" | ||
#include "mjson.h" | ||
|
||
void test_mjson_encode(void) | ||
{ | ||
/* Print into a statically allocated buffer */ | ||
char buf[100]; | ||
mjson_snprintf(buf, sizeof(buf), "{%Q:%d}", "a", 123); | ||
|
||
static const char expected[] = "{\"a\":123}"; | ||
|
||
TEST_ASSERT_EQUAL_INT(0, strcmp(expected, buf)); | ||
} | ||
|
||
void test_mjson_decode(void) | ||
{ | ||
static const char input[] = "{\"a\":1,\"b\":[2,false]}"; /* {"a":1,"b":[2,false]} */ | ||
|
||
double dval = 0; | ||
int res = mjson_get_number(input, strlen(input), "$.a", &dval); | ||
TEST_ASSERT_EQUAL_INT(1, res); | ||
TEST_ASSERT_EQUAL_INT(1, dval); | ||
|
||
const char *buf; | ||
int buf_len; | ||
res = mjson_find(input, strlen(input), "$.b", &buf, &buf_len); | ||
TEST_ASSERT_EQUAL_INT(91, res); | ||
TEST_ASSERT_EQUAL_INT(0, memcmp(buf, "[2,false]", buf_len)); | ||
|
||
res = mjson_get_number(input, strlen(input), "$.b[0]", &dval); | ||
TEST_ASSERT_EQUAL_INT(1, res); | ||
TEST_ASSERT_EQUAL_INT(2, dval); | ||
|
||
int ival = 0; | ||
res = mjson_get_bool(input, strlen(input), "$.b[1]", &ival); | ||
TEST_ASSERT_EQUAL_INT(1, res); | ||
TEST_ASSERT_EQUAL_INT(0, ival); | ||
|
||
} | ||
|
||
Test *tests_mjson(void) | ||
{ | ||
EMB_UNIT_TESTFIXTURES(fixtures) { | ||
new_TestFixture(test_mjson_encode), | ||
new_TestFixture(test_mjson_decode), | ||
}; | ||
|
||
EMB_UNIT_TESTCALLER(mjson_tests, NULL, NULL, fixtures); | ||
return (Test*)&mjson_tests; | ||
} | ||
|
||
int main(void) | ||
{ | ||
TESTS_START(); | ||
TESTS_RUN(tests_mjson()); | ||
TESTS_END(); | ||
|
||
return 0; | ||
} |
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,14 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2023 Koen Zandberg | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
|
||
import sys | ||
from testrunner import run_check_unittests | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(run_check_unittests()) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment as to why this option is chosen - you can squash directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Squashed in a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually do provide it (well, newlib/picolibc does) but it's a bad idea to use it with our small stacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. On the mjson side an include for alloca is missing, that's why it didn't compile for me. I've rephrased the comment a bit to clarify