1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

Merge pull request #16997 from aabadie/pr/pkg/corejson

pkg: add support for FreeRTOS coreJSON library
This commit is contained in:
Alexandre Abadie 2021-10-17 19:40:12 +02:00 committed by GitHub
commit 1e1b213439
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 116 additions and 0 deletions

9
pkg/corejson/Kconfig Normal file
View File

@ -0,0 +1,9 @@
# Copyright (c) 2021 Inria
#
# 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_COREJSON
bool "FreeRTOS coreJSON"
depends on TEST_KCONFIG

9
pkg/corejson/Makefile Normal file
View File

@ -0,0 +1,9 @@
PKG_NAME=corejson
PKG_URL=https://github.com/FreeRTOS/coreJSON
PKG_VERSION=caf540ccdb98e8f96a6f557075cb607288384938 # v3.0.2
PKG_LICENSE=MIT
include $(RIOTBASE)/pkg/pkg.mk
all:
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/source -f $(CURDIR)/$(PKG_NAME).mk

View File

@ -0,0 +1 @@
INCLUDES += -I$(PKGDIRBASE)/corejson/source/include

3
pkg/corejson/corejson.mk Normal file
View File

@ -0,0 +1,3 @@
MODULE = corejson
include $(RIOTBASE)/Makefile.base

11
pkg/corejson/doc.txt Normal file
View File

@ -0,0 +1,11 @@
/**
* @defgroup pkg_corejson FreeRTOS coreJSON
* @ingroup pkg
* @brief JSON parser that strictly enforces the ECMA-404 JSON standard
*
* # License
*
* Licensed under MIT.
*
* @see https://github.com/FreeRTOS/coreJSON
*/

View File

@ -0,0 +1,6 @@
include ../Makefile.tests_common
# required packages
USEPKG += corejson
include $(RIOTBASE)/Makefile.include

59
tests/pkg_corejson/main.c Normal file
View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2021 Inria
*
* 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 coreJSON package test application
*
* Adapted to RIOT style from the [reference example](https://github.com/FreeRTOS/coreJSON#reference-example)
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*
* @}
*/
#include <stdio.h>
#include "core_json.h"
int main(void)
{
/* Variables used in this example. */
JSONStatus_t result;
char buffer[] = "{\"foo\":\"abc\",\"bar\":{\"foo\":\"xyz\"}}";
size_t bufferLength = sizeof(buffer) - 1;
char queryKey[] = "bar.foo";
size_t queryKeyLength = sizeof(queryKey) - 1;
char *value;
size_t valueLength;
/* Calling JSON_Validate() is not necessary if the document is guaranteed to be valid. */
result = JSON_Validate(buffer, bufferLength);
if (result == JSONSuccess) {
result = JSON_Search(
buffer, bufferLength, queryKey, queryKeyLength,
&value, &valueLength
);
}
if (result == JSONSuccess) {
/* The pointer "value" will point to a location in the "buffer". */
char save = value[valueLength];
/* After saving the character, set it to a null byte for printing. */
value[valueLength] = '\0';
/* "Found: bar.foo -> xyz" will be printed. */
printf("Found: %s -> %s\n", queryKey, value);
/* Restore the original character. */
value[valueLength] = save;
}
return 0;
}

View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
# Copyright (C) 2021 Inria
#
# 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
def testfunc(child):
child.expect_exact("Found: bar.foo -> xyz")
if __name__ == "__main__":
sys.exit(run(testfunc))