Skip to content

Commit

Permalink
Merge pull request #90 from Biglup/feat/add-json-writer
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelCastilloB authored Dec 7, 2024
2 parents af708e7 + b954b0c commit 57fa800
Show file tree
Hide file tree
Showing 18 changed files with 5,311 additions and 4 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Next
Next (V1.1.0)
---------------------
- First release of cardano-c
- Added `cardano_json_writer_t` to write JSON to a buffer.

V1.0.0
---------------------
- First release of cardano-c
- Address Parsing & Generation
- Ed25519 Cryptography
- Transaction Serialization & Deserialization
- Powerful Transaction Builder
- Full Conway era support, including registering DReps, voting on proposals, and submitting proposals.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ ELSE ()
SET (CARDANO_C_COLLECTION_GROW_FACTOR 1.5) # See http://groups.google.com/group/comp.lang.c++.moderated/msg/ba558b4924758e2e
ENDIF ()

IF (DEFINED MAX_JSON_DEPTH )
SET (CARDANO_C_MAX_JSON_DEPTH ${MAX_JSON_DEPTH})
ELSE ()
SET (CARDANO_C_MAX_JSON_DEPTH 256)
ENDIF ()


SET (CARDANO_C_VERSION "${CARDANO_C_VERSION_MAJOR}.${CARDANO_C_VERSION_MINOR}.${CARDANO_C_VERSION_PATCH}")

FIND_PROGRAM (CLANG_TIDY_EXE NAMES "clang-tidy")
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION_MAJOR=1
VERSION_MINOR=0
VERSION_MINOR=1
VERSION_PATCH=0
15 changes: 15 additions & 0 deletions doc/src/sections/api/json/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
JSON
==========================

JavaScript Object Notation (`JSON`_) is a text-based data serialization format that is widely used for its simplicity and readability. JSON's design is particularly suited for applications where human-readable structured data is required, making it a preferred choice for data interchange and configuration formats.

This section of the documentation provides detailed information on each function offered by this library to both generate and parse `JSON`_ encoded data:

.. toctree::
:maxdepth: 1

./json_writer
./json_context
./json_format

.. _JSON: https://www.json.org
4 changes: 4 additions & 0 deletions doc/src/sections/api/json/json_context.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
JSON Context
==========================

.. doxygenenum:: cardano_json_context_t
4 changes: 4 additions & 0 deletions doc/src/sections/api/json/json_format.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
JSON Format
==========================

.. doxygenenum:: cardano_json_format_t
100 changes: 100 additions & 0 deletions doc/src/sections/api/json/json_writer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
JSON Writer
==========================

.. doxygentypedef:: cardano_json_writer_t

------------

.. doxygenfunction:: cardano_json_writer_new

------------

.. doxygenfunction:: cardano_json_writer_write_property_name

------------

.. doxygenfunction:: cardano_json_writer_write_bool

------------

.. doxygenfunction:: cardano_json_writer_write_null

------------

.. doxygenfunction:: cardano_json_writer_write_bigint

------------

.. doxygenfunction:: cardano_json_writer_write_start_array

------------

.. doxygenfunction:: cardano_json_writer_write_end_array

------------

.. doxygenfunction:: cardano_json_writer_write_start_object

------------

.. doxygenfunction:: cardano_json_writer_write_end_object

------------

.. doxygenfunction:: cardano_json_writer_write_raw_value

------------

.. doxygenfunction:: cardano_json_writer_write_uint

------------

.. doxygenfunction:: cardano_json_writer_write_signed_int

------------

.. doxygenfunction:: cardano_json_writer_write_double

------------

.. doxygenfunction:: cardano_json_writer_write_string

------------

.. doxygenfunction:: cardano_json_writer_get_context

------------

.. doxygenfunction:: cardano_json_writer_get_encoded_size

------------

.. doxygenfunction:: cardano_json_writer_encode

------------

.. doxygenfunction:: cardano_json_writer_encode_in_buffer

------------

.. doxygenfunction:: cardano_json_writer_reset

------------

.. doxygenfunction:: cardano_json_writer_unref

------------

.. doxygenfunction:: cardano_json_writer_ref

------------

.. doxygenfunction:: cardano_json_writer_refcount

------------

.. doxygenfunction:: cardano_json_writer_set_last_error

------------

.. doxygenfunction:: cardano_json_writer_get_last_error
1 change: 1 addition & 0 deletions doc/src/sections/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The following configuration options will also be defined as macros [#]_ in ``con
Option Meaning Default Possible values
-------------------------- ------------------------------------------------------- ---------------------- ---------------------------------------------------------------------------------------------------------------------
``COLLECTION_GROW_FACTOR`` Factor for buffer growth & shrinking ``1.5`` Decimals > 1
``MAX_JSON_DEPTH`` Maximum depth of JSON objects ``256`` Integers > 0
========================== ======================================================= ====================== =====================================================================================================================

.. [#] ``ON`` & ``OFF`` will be translated to ``1`` and ``0`` using `cmakedefine <https://cmake.org/cmake/help/v3.2/command/configure_file.html?highlight=cmakedefine>`_.
Expand Down
1 change: 1 addition & 0 deletions doc/src/sections/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ See `APACHE LICENSE, VERSION 2.0`_
api/cryptography/index
api/cbor/index
api/encoding/index
api/json/index
api/key_handlers/index
api/plutus_data/index
api/pool_params/index
Expand Down
64 changes: 64 additions & 0 deletions lib/include/cardano/json/json_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* \file json_context.h
*
* \author angel.castillo
* \date Dec 06, 2024
*
* Copyright 2024 Biglup Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef BIGLUP_LABS_INCLUDE_CARDANO_JSON_CONTEXT_H
#define BIGLUP_LABS_INCLUDE_CARDANO_JSON_CONTEXT_H

/* INCLUDES ******************************************************************/

#include <cardano/export.h>

/* DECLARATIONS **************************************************************/

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
* \brief Enum representing the current context of the JSON writer.
*
* This enum defines the possible states of the JSON writer, indicating
* whether it is at the root level, inside an object, or inside an array.
*/
typedef enum
{
/**
* \brief The writer is at the root level (no context set).
*/
CARDANO_JSON_CONTEXT_ROOT = 0,

/**
* \brief The writer is inside an object context.
*/
CARDANO_JSON_CONTEXT_OBJECT = 1,

/**
* \brief The writer is inside an array context.
*/
CARDANO_JSON_CONTEXT_ARRAY = 2

} cardano_json_context_t;

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif // BIGLUP_LABS_INCLUDE_CARDANO_JSON_CONTEXT_H
60 changes: 60 additions & 0 deletions lib/include/cardano/json/json_format.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* \file json_format.h
*
* \author angel.castillo
* \date Dec 06, 2024
*
* Copyright 2024 Biglup Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef BIGLUP_LABS_INCLUDE_CARDANO_JSON_FORMAT_H
#define BIGLUP_LABS_INCLUDE_CARDANO_JSON_FORMAT_H

/* INCLUDES ******************************************************************/

#include <cardano/export.h>

/* DECLARATIONS **************************************************************/

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
* \brief Enum representing the format of the JSON output.
*
* This enum defines the possible formats for the JSON output, indicating
* whether it should be compact (no extra spaces or line breaks) or pretty
* (extra spaces and line breaks for readability).
*/
typedef enum
{
/**
* \brief Compact JSON format (no extra spaces or line breaks).
*/
CARDANO_JSON_FORMAT_COMPACT,

/**
* \brief Pretty JSON format (extra spaces and line breaks for readability).
*/
CARDANO_JSON_FORMAT_PRETTY

} cardano_json_format_t;

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif // BIGLUP_LABS_INCLUDE_CARDANO_JSON_FORMAT_H
Loading

0 comments on commit 57fa800

Please sign in to comment.