Skip to content

Commit

Permalink
Add json and gtest dependencies
Browse files Browse the repository at this point in the history
Also, add basic definitions and functions
  • Loading branch information
testillano authored and Eduardo Ramos Testillano (eramedu) committed Aug 14, 2023
1 parent 54a2dbf commit 9a417c8
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 9 deletions.
24 changes: 24 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ WORKDIR /code/build
ARG make_procs=4
ARG build_type=Release
ARG ert_logger_ver=v1.1.0
ARG nlohmann_json_ver=v3.10.5
ARG pboettch_jsonschemavalidator_ver=2.1.0
ARG google_test_ver=v1.11.0

RUN apk update && apk add \
build-base cmake wget tar \
Expand All @@ -23,6 +26,27 @@ RUN set -x && \
cd .. && rm -rf * && \
set +x

# nlohmann json
RUN set -x && \
wget https://github.com/nlohmann/json/releases/download/${nlohmann_json_ver}/json.hpp && \
mkdir /usr/local/include/nlohmann && mv json.hpp /usr/local/include/nlohmann && \
set +x

# pboettch json-schema-validator
RUN set -x && \
wget https://github.com/pboettch/json-schema-validator/archive/${pboettch_jsonschemavalidator_ver}.tar.gz && \
tar xvf ${pboettch_jsonschemavalidator_ver}.tar.gz && cd json-schema-validator*/ && mkdir build && cd build && \
cmake .. && make -j${make_procs} && make install && \
cd ../.. && rm -rf * && \
set +x

# google test framework
RUN set -x && \
wget https://github.com/google/googletest/archive/refs/tags/release-$(echo ${google_test_ver} | cut -c2-).tar.gz && \
tar xvf release-$(echo ${google_test_ver} | cut -c2-).tar.gz && cd googletest-release*/ && cmake . && make -j${make_procs} install && \
cd .. && rm -rf * && \
set +x

# Build script
COPY deps/build.sh /var
RUN chmod a+x /var/build.sh
Expand Down
16 changes: 11 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ base_tag__dflt=latest
make_procs__dflt=$(grep processor /proc/cpuinfo -c)
build_type__dflt=Release
ert_logger_ver__dflt=v1.1.0
ert_diametercodec_ver__dflt=v1.0.0
nlohmann_json_ver__dflt=v3.10.5
pboettch_jsonschemavalidator_ver__dflt=2.1.0
google_test_ver__dflt=v1.11.0
registry=ghcr.io/testillano

#############
Expand All @@ -30,7 +32,7 @@ usage() {
For headless mode you may prepend or export asked/environment variables for the corresponding
docker procedure:
--builder-image: image_tag, base_os, base_tag (nghttp2), make_procs, build_type, ert_logger_ver, ert_diametercodec_ver
--builder-image: image_tag, base_os, base_tag (nghttp2), make_procs, build_type, ert_logger_ver, nlohmann_json_ver, pboettch_jsonschemavalidator_ver, google_test_ver
--project: make_procs, build_type, base_tag (diametercodec_builder)
--project-image: image_tag, base_tag (diametercodec_builder), make_procs, build_type
--auto: any of the variables above
Expand Down Expand Up @@ -77,14 +79,18 @@ build_builder_image() {
_read make_procs
_read build_type
_read ert_logger_ver
_read ert_diametercodec_ver
_read nlohmann_json_ver
_read pboettch_jsonschemavalidator_ver
_read google_test_ver

bargs="--build-arg base_os=${base_os}"
bargs+=" --build-arg base_tag=${base_tag}"
bargs+=" --build-arg make_procs=${make_procs}"
bargs+=" --build-arg build_type=${build_type}"
bargs+=" --build-arg ert_logger_ver=${ert_logger_ver}"
bargs+=" --build-arg ert_diametercodec_ver=${ert_diametercodec_ver}"
bargs+=" --build-arg nlohmann_json_ver=${nlohmann_json_ver}"
bargs+=" --build-arg pboettch_jsonschemavalidator_ver=${pboettch_jsonschemavalidator_ver}"
bargs+=" --build-arg google_test_ver=${google_test_ver}"

set -x
rm -f CMakeCache.txt
Expand All @@ -99,7 +105,7 @@ build_project() {
echo
sources=$(find . -name "*.hpp" -o -name "*.cpp")
echo "TEMPORARY: no source !"
#docker run -i --rm -v $PWD:/data frankwolf/astyle ${sources}
docker run -i --rm -v $PWD:/data frankwolf/astyle ${sources}

echo
echo "=== Build diametercodec project ==="
Expand Down
98 changes: 98 additions & 0 deletions include/ert/diametercodec/defines.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
________________________________________________________________________
| |
| _ _ _ _ |
| | (_) | | | | |
| __| |_ __ _ _ __ ___ ___| |_ ___ _ __ ___ ___ __| | ___ ___ |
| / _` | |/ _` | '_ ` _ \ / _ \ __/ _ \ '__/ __/ _ \ / _` |/ _ \/ __| |
| | (_| | | (_| | | | | | | __/ || __/ | | (_| (_) | (_| | __/ (__ |
| \__,_|_|\__,_|_| |_| |_|\___|\__\___|_| \___\___/ \__,_|\___|\___| |
| |
|________________________________________________________________________|
C++ CODEC FOR DIAMETER PROTOCOL (RFC 6733)
Version 0.0.z
https://github.com/testillano/diametercodec
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2021 Eduardo Ramos
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#pragma once

// Standard
#include <cstdint>
#include <utility> // std::pair

// Project


namespace ert
{
namespace diametercodec
{

// Basic types
// TYPE BITS (bytes) Format
// ----------------------- ------------------ ---------------------------
// unsigned long int 32/64 (4/8) lu
// long int 32/64 (4/8) ld
//
// unsigned long long int 64 (8) llu
// long long int 64 (8) lld
//
// float 32 (4) f
// double 64 (8) lf
// long double 80 (10) Lf
//
// pointer = S.O. word 32/64 p
typedef unsigned char U8;
typedef char S8;
typedef uint16_t U16;
typedef int16_t S16;
typedef uint32_t U32;
typedef int32_t S32;
typedef uint64_t U64;
typedef int64_t S64;
typedef float F32;
typedef double F64;
typedef long double F80;
typedef U32 U24;

// pares
typedef std::pair < S32/*code*/, S32/*vendor-id*/ > AvpId;
typedef std::pair < U24/*code*/, bool/*request indicator*/ > CommandId;

//typedef std::pair<_avpId_t, U16> par_idAVP_ocurrencia_t;

typedef unsigned int ApplicationId;

// The Hop-by-Hop Identifier is an unsigned 32-bit integer field (in
// network byte order) and aids in matching requests and replies.
typedef unsigned int HopByHop;

typedef unsigned int EndToEnd;

}
}


21 changes: 20 additions & 1 deletion include/ert/diametercodec/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,33 @@ SOFTWARE.
#include <string>

// Project
#include <ert/diametercodec/defines.hpp>


namespace ert
{
namespace diametercodec
{

void dummy();
struct functions {

/**
* Returns Avp identification as string:
* <pre>
* '(<code>,<vendorId>)'
* </pre>
*/
static std::string avpIdAsPairString(const AvpId & avpId);


/**
* Returns Command identification as string:
* <pre>
* '(<code>,request|answer)'
* </pre>
*/
static std::string commandIdAsPairString(const CommandId & commandId);
};

}
}
Expand Down
21 changes: 18 additions & 3 deletions src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ SOFTWARE.
*/


//#include <ert/tracing/Logger.hpp>

// Project
#include <ert/diametercodec/functions.hpp>

Expand All @@ -49,8 +47,25 @@ namespace ert
namespace diametercodec
{

void dummy() {
std::string functions::avpIdAsPairString(const AvpId & avpId) {
std::string result;
result = "(";
result += std::to_string(avpId.first);
result += ",";
result += std::to_string(avpId.second);
result += ")";
return (result);
}


std::string functions::commandIdAsPairString(const CommandId & commandId) {
std::string result;
result = "(";
result += std::to_string(commandId.first);
result += ",";
result += (commandId.second ? "request" : "answer");
result += ")";
return (result);
}

}
Expand Down

0 comments on commit 9a417c8

Please sign in to comment.