Skip to content

Commit

Permalink
Group encoding/decoding source code into src/runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Feb 9, 2024
1 parent e189a12 commit 1f54eba
Show file tree
Hide file tree
Showing 69 changed files with 176 additions and 217 deletions.
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ find_package(JSONToolkit REQUIRED)

# Runtime
if(JSONBINPACK_RUNTIME OR JSONBINPACK_CLI OR JSONBINPACK_COMPILER)
add_subdirectory(src/numeric)
add_subdirectory(src/encoding)
add_subdirectory(src/encoder)
add_subdirectory(src/decoder)
add_subdirectory(src/runtime)
endif()

# Compiler
Expand Down Expand Up @@ -67,6 +64,7 @@ if(JSONBINPACK_TESTS)
enable_testing()

if(JSONBINPACK_RUNTIME OR JSONBINPACK_CLI OR JSONBINPACK_COMPILER)
# TODO: Group into a single runtime test module
add_subdirectory(test/numeric)
add_subdirectory(test/encoding)
add_subdirectory(test/encoder)
Expand Down
3 changes: 1 addition & 2 deletions src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsonbinpack
target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsonbinpack::mapper)
target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsonbinpack::parser)
target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsonbinpack::schemas)
target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsonbinpack::encoder)
target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsonbinpack::decoder)
target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsonbinpack::runtime)
target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsontoolkit::json)
target_link_libraries(sourcemeta_jsonbinpack_cli PRIVATE sourcemeta::jsontoolkit::jsonschema)

Expand Down
2 changes: 1 addition & 1 deletion src/cli/command_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "resolver.h"

#include <sourcemeta/jsonbinpack/canonicalizer.h>
#include <sourcemeta/jsonbinpack/decoder.h>
#include <sourcemeta/jsonbinpack/mapper.h>
#include <sourcemeta/jsonbinpack/parser.h>
#include <sourcemeta/jsonbinpack/runtime.h>

#include <sourcemeta/jsontoolkit/json.h>
#include <sourcemeta/jsontoolkit/jsonschema.h>
Expand Down
2 changes: 1 addition & 1 deletion src/cli/command_encode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "resolver.h"

#include <sourcemeta/jsonbinpack/canonicalizer.h>
#include <sourcemeta/jsonbinpack/encoder.h>
#include <sourcemeta/jsonbinpack/mapper.h>
#include <sourcemeta/jsonbinpack/parser.h>
#include <sourcemeta/jsonbinpack/runtime.h>

#include <sourcemeta/jsontoolkit/json.h>
#include <sourcemeta/jsontoolkit/jsonschema.h>
Expand Down
16 changes: 0 additions & 16 deletions src/decoder/CMakeLists.txt

This file was deleted.

16 changes: 0 additions & 16 deletions src/encoder/CMakeLists.txt

This file was deleted.

30 changes: 0 additions & 30 deletions src/encoder/include/sourcemeta/jsonbinpack/encoder_varint.h

This file was deleted.

14 changes: 0 additions & 14 deletions src/encoding/CMakeLists.txt

This file was deleted.

8 changes: 0 additions & 8 deletions src/numeric/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ sourcemeta_jsonbinpack_add_compile_options(PRIVATE sourcemeta_jsonbinpack_parser
target_link_libraries(sourcemeta_jsonbinpack_parser PUBLIC
sourcemeta::jsontoolkit::json)
target_link_libraries(sourcemeta_jsonbinpack_parser PRIVATE
sourcemeta::jsonbinpack::encoding)
sourcemeta::jsonbinpack::runtime)
2 changes: 1 addition & 1 deletion src/parser/include/sourcemeta/jsonbinpack/parser.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SOURCEMETA_JSONBINPACK_PARSER_H_
#define SOURCEMETA_JSONBINPACK_PARSER_H_

#include <sourcemeta/jsonbinpack/encoding.h>
#include <sourcemeta/jsonbinpack/runtime.h>
#include <sourcemeta/jsontoolkit/json.h>

namespace sourcemeta::jsonbinpack {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/v1_any.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SOURCEMETA_JSONBINPACK_PARSER_V1_ANY_H_
#define SOURCEMETA_JSONBINPACK_PARSER_V1_ANY_H_

#include <sourcemeta/jsonbinpack/encoding.h>
#include <sourcemeta/jsonbinpack/runtime.h>
#include <sourcemeta/jsontoolkit/json.h>

namespace sourcemeta::jsonbinpack::parser::v1 {
Expand Down
3 changes: 1 addition & 2 deletions src/parser/v1_array.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef SOURCEMETA_JSONBINPACK_PARSER_V1_ARRAY_H_
#define SOURCEMETA_JSONBINPACK_PARSER_V1_ARRAY_H_

#include <sourcemeta/jsonbinpack/encoding.h>
#include <sourcemeta/jsonbinpack/encoding_wrap.h>
#include <sourcemeta/jsonbinpack/parser.h>
#include <sourcemeta/jsonbinpack/runtime.h>
#include <sourcemeta/jsontoolkit/json.h>

#include <algorithm> // std::transform
Expand Down
2 changes: 1 addition & 1 deletion src/parser/v1_enum.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SOURCEMETA_JSONBINPACK_PARSER_V1_ENUM_H_
#define SOURCEMETA_JSONBINPACK_PARSER_V1_ENUM_H_

#include <sourcemeta/jsonbinpack/encoding.h>
#include <sourcemeta/jsonbinpack/runtime.h>
#include <sourcemeta/jsontoolkit/json.h>

#include <cassert> // assert
Expand Down
2 changes: 1 addition & 1 deletion src/parser/v1_integer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SOURCEMETA_JSONBINPACK_PARSER_V1_INTEGER_H_
#define SOURCEMETA_JSONBINPACK_PARSER_V1_INTEGER_H_

#include <sourcemeta/jsonbinpack/encoding.h>
#include <sourcemeta/jsonbinpack/runtime.h>
#include <sourcemeta/jsontoolkit/json.h>

#include <cassert> // assert
Expand Down
2 changes: 1 addition & 1 deletion src/parser/v1_number.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SOURCEMETA_JSONBINPACK_PARSER_V1_NUMBER_H_
#define SOURCEMETA_JSONBINPACK_PARSER_V1_NUMBER_H_

#include <sourcemeta/jsonbinpack/encoding.h>
#include <sourcemeta/jsonbinpack/runtime.h>
#include <sourcemeta/jsontoolkit/json.h>

namespace sourcemeta::jsonbinpack::parser::v1 {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/v1_string.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SOURCEMETA_JSONBINPACK_PARSER_V1_STRING_H_
#define SOURCEMETA_JSONBINPACK_PARSER_V1_STRING_H_

#include <sourcemeta/jsonbinpack/encoding.h>
#include <sourcemeta/jsonbinpack/runtime.h>
#include <sourcemeta/jsontoolkit/json.h>

#include <cassert> // assert
Expand Down
25 changes: 25 additions & 0 deletions src/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
noa_library(NAMESPACE sourcemeta PROJECT jsonbinpack NAME runtime
FOLDER "JSON BinPack/Runtime"
PRIVATE_HEADERS
decoder.h
decoder_basic.h
decoder_zigzag.h
encoder.h
encoder_basic.h
encoder_context.h
encoder_real.h
encoder_zigzag.h
encoding.h
encoding_tag.h
encoding_wrap.h
varint.h
numeric.h)

if(JSONBINPACK_INSTALL)
noa_library_install(NAMESPACE sourcemeta PROJECT jsonbinpack NAME runtime)
endif()

sourcemeta_jsonbinpack_add_compile_options(INTERFACE sourcemeta_jsonbinpack_runtime)

target_link_libraries(sourcemeta_jsonbinpack_runtime INTERFACE
sourcemeta::jsontoolkit::json)
8 changes: 8 additions & 0 deletions src/runtime/include/sourcemeta/jsonbinpack/runtime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_H_
#define SOURCEMETA_JSONBINPACK_RUNTIME_H_

#include <sourcemeta/jsonbinpack/runtime_decoder.h>
#include <sourcemeta/jsonbinpack/runtime_encoder.h>
#include <sourcemeta/jsonbinpack/runtime_encoding.h>

#endif
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#ifndef SOURCEMETA_JSONBINPACK_DECODER_H_
#define SOURCEMETA_JSONBINPACK_DECODER_H_
#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_H_
#define SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_H_

/// @defgroup decoder Decoder
/// @brief A set of procedures to deserialize a bit-string given a Encoding
/// Schema

#include <sourcemeta/jsonbinpack/decoder_basic.h>
#include <sourcemeta/jsonbinpack/encoding.h>
#include <sourcemeta/jsonbinpack/encoding_tag.h>
#include <sourcemeta/jsonbinpack/encoding_wrap.h>
#include <sourcemeta/jsonbinpack/numeric.h>
#include <sourcemeta/jsonbinpack/runtime_decoder_basic.h>
#include <sourcemeta/jsonbinpack/runtime_encoding.h>
#include <sourcemeta/jsonbinpack/runtime_encoding_tag.h>
#include <sourcemeta/jsonbinpack/runtime_encoding_wrap.h>
#include <sourcemeta/jsonbinpack/runtime_numeric.h>

#include <sourcemeta/jsontoolkit/json.h>

#include <cassert> // assert
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef SOURCEMETA_JSONBINPACK_DECODER_BASIC_H_
#define SOURCEMETA_JSONBINPACK_DECODER_BASIC_H_
#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_BASIC_H_
#define SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_BASIC_H_

#include <sourcemeta/jsonbinpack/decoder_varint.h>
#include <sourcemeta/jsonbinpack/decoder_zigzag.h>
#include <sourcemeta/jsonbinpack/runtime_decoder_zigzag.h>
#include <sourcemeta/jsonbinpack/runtime_varint.h>

#include <cassert> // assert
#include <cmath> // std::ceil
Expand Down Expand Up @@ -55,12 +55,10 @@ template <typename CharT, typename Traits> class BasicDecoder {
return word;
}

inline auto get_varint() -> std::uint64_t {
return decoder::varint(this->stream);
}
inline auto get_varint() -> std::uint64_t { return varint(this->stream); }

inline auto get_varint_zigzag() -> std::int64_t {
const std::uint64_t value = decoder::varint(this->stream);
const std::uint64_t value = varint(this->stream);
return decoder::zigzag(value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SOURCEMETA_JSONBINPACK_DECODER_ZIGZAG_H_
#define SOURCEMETA_JSONBINPACK_DECODER_ZIGZAG_H_
#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_ZIGZAG_H_
#define SOURCEMETA_JSONBINPACK_RUNTIME_DECODER_ZIGZAG_H_

#include <cstdint> // std::uint64_t, std::int64_t

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#ifndef SOURCEMETA_JSONBINPACK_ENCODER_H_
#define SOURCEMETA_JSONBINPACK_ENCODER_H_
#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_H_
#define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_H_

/// @defgroup encoder Encoder
/// @brief A set of procedures to serialize a JSON document given a Encoding
/// Schema

#include <sourcemeta/jsonbinpack/encoder_basic.h>
#include <sourcemeta/jsonbinpack/encoder_real.h>
#include <sourcemeta/jsonbinpack/encoding.h>
#include <sourcemeta/jsonbinpack/encoding_tag.h>
#include <sourcemeta/jsonbinpack/encoding_wrap.h>
#include <sourcemeta/jsonbinpack/numeric.h>
#include <sourcemeta/jsonbinpack/runtime_encoder_basic.h>
#include <sourcemeta/jsonbinpack/runtime_encoder_real.h>
#include <sourcemeta/jsonbinpack/runtime_encoding.h>
#include <sourcemeta/jsonbinpack/runtime_encoding_tag.h>
#include <sourcemeta/jsonbinpack/runtime_encoding_wrap.h>
#include <sourcemeta/jsonbinpack/runtime_numeric.h>

#include <sourcemeta/jsontoolkit/json.h>

#include <cmath> // std::abs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef SOURCEMETA_JSONBINPACK_ENCODER_BASIC_H_
#define SOURCEMETA_JSONBINPACK_ENCODER_BASIC_H_
#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_BASIC_H_
#define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_BASIC_H_

#include <sourcemeta/jsonbinpack/encoder_context.h>
#include <sourcemeta/jsonbinpack/encoder_varint.h>
#include <sourcemeta/jsonbinpack/encoder_zigzag.h>
#include <sourcemeta/jsonbinpack/runtime_encoder_context.h>
#include <sourcemeta/jsonbinpack/runtime_encoder_zigzag.h>
#include <sourcemeta/jsonbinpack/runtime_varint.h>

#include <algorithm> // std::find_if
#include <cassert> // assert
Expand Down Expand Up @@ -40,11 +40,11 @@ template <typename CharT, typename Traits> class BasicEncoder {
}

inline auto put_varint(const std::uint64_t value) -> void {
encoder::varint(this->stream, value);
varint(this->stream, value);
}

inline auto put_varint_zigzag(const std::int64_t value) -> void {
encoder::varint(this->stream, encoder::zigzag(value));
varint(this->stream, encoder::zigzag(value));
}

inline auto put_string_utf8(const std::basic_string<CharT> &string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SOURCEMETA_JSONBINPACK_ENCODER_CONTEXT_H_
#define SOURCEMETA_JSONBINPACK_ENCODER_CONTEXT_H_
#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_CONTEXT_H_
#define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_CONTEXT_H_

#include <cassert> // assert
#include <iterator> // std::cbegin, std::cend
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SOURCEMETA_JSONBINPACK_ENCODER_REAL_H_
#define SOURCEMETA_JSONBINPACK_ENCODER_REAL_H_
#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_REAL_H_
#define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_REAL_H_

#include <cassert> // assert
#include <cmath> // std::modf, std::floor, std::isfinite
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SOURCEMETA_JSONBINPACK_ENCODER_ZIGZAG_H_
#define SOURCEMETA_JSONBINPACK_ENCODER_ZIGZAG_H_
#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_ZIGZAG_H_
#define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODER_ZIGZAG_H_

#include <cmath> // std::abs
#include <cstdint> // std::uint64_t, std::int64_t
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SOURCEMETA_JSONBINPACK_ENCODING_H_
#define SOURCEMETA_JSONBINPACK_ENCODING_H_
#ifndef SOURCEMETA_JSONBINPACK_RUNTIME_ENCODING_H_
#define SOURCEMETA_JSONBINPACK_RUNTIME_ENCODING_H_

/// @defgroup encoding Encodings
///
Expand Down
Loading

0 comments on commit 1f54eba

Please sign in to comment.