GithubHelp home page GithubHelp logo

abdallah-elshamy / octave-gsoc-json Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 83 KB

JavaScript Object Notation​, in short JSON, is a very common human readable and structured data format. Unfortunately, GNU Octave still lacks builtin support for that data format. Having JSON support, Octave can improve for example it's web service functions, which often exchange JSON data these days.

C++ 50.16% MATLAB 49.84%

octave-gsoc-json's People

Contributors

abdallah-elshamy avatar siko1056 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

octave-gsoc-json's Issues

Merge with Octave: configure.ac

Just as a reminder in extension to our discussion on the Octave maintainers mailing-list I finally figured out a working configure.ac check for RapidJSON, especially for a newer version by checking for the rapidjson/cursorstreamwrapper.h header.

diff -r 652a675c0916 configure.ac
--- a/configure.ac	Mon Aug 03 11:13:26 2020 -0400
+++ b/configure.ac	Wed Aug 12 12:49:26 2020 +0900
@@ -1331,6 +1331,22 @@ OCTAVE_CHECK_LIB(pcre, PCRE,
   ],
   [libpcre], [REQUIRED])

+### Check for RapidJSON header only library.
+
+AC_LANG_PUSH([C++])
+AC_CHECK_HEADER([rapidjson/rapidjson.h], [have_rapidjson=yes], [have_rapidjson=no
+  rapid_json_warning="RapidJSON library not found.  Octave will not be able to read or write JSON files."])
+if test "$have_rapidjson" = yes; then
+  AC_CHECK_HEADER([rapidjson/cursorstreamwrapper.h], [have_rapidjson=yes], [have_rapidjson=no
+    rapid_json_warning="RapidJSON 1.1.0 or older found, but latest development version needed.  Octave will not be able to read or write JSON files."])
+fi
+if test "$have_rapidjson" = yes; then
+  AC_DEFINE(HAVE_RAPIDJSON, 1, [Define to 1 if RapidJSON is available.])
+else
+  OCTAVE_CONFIGURE_WARNING([rapid_json_warning])
+fi
+AC_LANG_POP([C++])
+
 ### Check for readline library.

 OCTAVE_ENABLE_READLINE

Using this patch for merging with the Octave sources, can you wrap the code in the main function of jsondecode.cc and jsonencode.cc with something like this for HAVE_RAPIDJSON

https://hg.savannah.gnu.org/hgweb/octave/file/652a675c0916/libinterp/dldfcn/audioread.cc#l82
https://hg.savannah.gnu.org/hgweb/octave/file/652a675c0916/libinterp/dldfcn/audioread.cc#l192

Folder name "test/json" and document compatibility.

Abdallah,

Sorry for coming late at your code, but I assume, you are also busy with your exams. You did not contribute that much code yet, but there will be more to come after your exams 😉

You introduced the folder "test/json-encode-decode", I would suggest "test/json" to be sufficient.

In the header section of your file:

https://github.com/Abdallah-Elshamy/octave/blob/1538ec5f09f0d78a6b7654238af5a2dd33c711c2/test/json-encode-decode/jsondecodetest.m#L1-L3

I suggest you note, that it should not conform to Octave coding convention to be able to be tested in Matlab, for example see

https://github.com/Abdallah-Elshamy/octave/blob/1538ec5f09f0d78a6b7654238af5a2dd33c711c2/test/classdef/classdef.tst#L29-L30

Maybe you can copy your header from there.

Unit tests ASCII conversion

As we discussed last Friday, we should consider proper treatment of all ASCII characters in both JSON conversion directions. According to Wikipedia this should be all:

\0\a\b\t\n\v\f\r !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

Own experiments with Matlab showed me, that basically escaping with \ happends, e.g. \n becomes \\n, etc.

Please merge the `test-suite` branch into `json`.

@Abdallah-Elshamy Thank you for your continued work on the JSON project. I think the number of branches in your repo should not exceed one. How can I run your test files

  • test/json/jsonXXcodetest.m

together with your work on

  • libinterp/corefcn/jsondecode.cc

My idea for the end of GSoC is, that all your changes are accumulated in a feature branch "json", that is converted into a pull request, that can be exported to be merged into Octave.

jsondecode.cc: Add default branch else-branches

@Abdallah-Elshamy Thank you for your great work on jsondecode.cc. According to your blog you are more than ahead of time "06/7 – 18/7 | 12 days | Implementing jsondecode" 👍

On the maintainers mailing-list Markus added a remark:

Maybe as a feedback I can see some compiler warning. But that should be easy to fix.

jsondecode.cc: In function ‘octave_value decode_number(const Value&)’:
jsondecode.cc:60:1: warning: control reaches end of non-void function
[-Wreturn-type]
   60 | }
      | ^
jsondecode.cc: In function ‘octave_value decode_array(const Value&)’:
jsondecode.cc:218:1: warning: control reaches end of non-void function
[-Wreturn-type]
  218 | }
      | ^
jsondecode.cc: In function ‘octave_value decode(const Value&)’:
jsondecode.cc:235:1: warning: control reaches end of non-void function
[-Wreturn-type]
  235 | }
      | ^

All these instances look like this

https://github.com/Abdallah-Elshamy/octave/blob/933e6ff0b47fb85e7cbe72b30bcd1660eb86deff/libinterp/corefcn/jsondecode.cc#L47-L60

My compiler, gcc 7, did not complain, but maybe Markus uses a newer one. Indeed it is safer to implement some default else-branch with something like

else
  error ("jsondecode.cc: Unidentified type.");

to avoid undefined states.

Otherwise, please take your time document (comment) your work, extend jsondecodetest.m, work on Abdallah-Elshamy/octave#5 or start with jsonencode.cc.

Unit tests

Hi @Abdallah-Elshamy

Thanks for the comprehensive list of unit tests. They highlighted one difference between JSONio and jsonencode/jsondecode (test 22: b = instead of b = ) that I was not aware of.

Concerning the other points mentioned on the maintainers mailing list, for JSONio, I have added some extra options, Indent and ReplacementStyle, defaulting to Matlab. Perhaps a similar approach could be taken for Octave?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.