Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » A new set of JSON tools as external functions
A new set of JSON tools as external functions [message #1792932] Thu, 26 July 2018 07:10
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 807
Registered: January 2015
Senior Member
Dear all,

we have interfaced Niels Lohmann's excellent C++ JSON library to TTCN-3,
allowing access to some of the tools defined there.

Please look into https://github.com/eclipse/titan.Libraries.TCCUsefulFunctions

The relevant files are:

-the C++ library itself:


titan.Libraries.TCCUsefulFunctions/src/json.hpp

 
 __ _____ _____ _____
 __|  |   __|     |   | |  JSON for Modern C++
|  |  |__   |  |  | | | |  version 3.1.2
|_____|_____|_____|_|___|  https://github.com/nlohmann/json
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2013-2018 Niels Lohmann <http://nlohmann.me>.

- the C++ wrappers:

titan.Libraries.TCCUsefulFunctions/src/TCC_JSON.cc

- the external function declarations

titan.Libraries.TCCUsefulFunctions/src/TCC_JSON_Functions.ttcn


This could be also a good example to follow when interfacing other C++ libraries to Titan TTCN-3.

So far , the following functions have been implemented:

-JSON to CBOR/CBOR to JSON conversion
 
external function JSON_to_CBOR(in universal charstring pl_json_str) return octetstring
external function CBOR_to_JSON(in octetstring pl_cbor_str) return universal charstring

Note: Titan already has a built in JSON to CBOR/CBOR to JSON conversion function that works in a similar manner.

-JSON to MessagePack/MessagePack to JSON conversion
 
external function JSON_to_MessagePack(in universal charstring pl_json_str) return octetstring
external function MessagePack_to_JSON(in octetstring pl_msgpack_str) return universal charstring

-UBJSON to CBOR/CBOR to UBJSON conversion
 
external function JSON_to_UBJSON(in universal charstring pl_json_str,
                                 in boolean pl_use_size := false,
                                 in boolean pl_use_type := false) return octetstring
								 
external function UBJSON_to_JSON(in octetstring pl_ubjson_str) return universal charstring


The input of the encoding functions is a serialized JSON document, the output being the corresponding binary representation.


-Flatten/unflatten JSON
 
external function flatten_JSON(in universal charstring pl_json_str) return universal charstring
external function unflatten_JSON(in universal charstring pl_json_str) return universal charstring


Note: Any projects using this module must be built with C++11 or newer (e.g.: g++ compiler option '-std=c++11').

This means setting the flag as below in the Makefile:
 
# Flags for the C++ compiler:
CXXFLAGS = -std=c++11  

Of course other functions exposed by the library can be interfaced in a similar manner:

see https://nlohmann.github.io/json/ fort details.


Best regards
Elemer
Previous Topic:Test Performance in TITAN using Timestamps
Next Topic:Error in function generation
Goto Forum:
  


Current Time: Sat Sep 22 19:39:30 GMT 2018

Powered by FUDForum. Page generated in 0.01830 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top