-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/dummy type serialization (#136)
# Description Module **types_proto** provides mapping of **types** data structures to proto IDL. ## Detailed description Protobuf is used to serialize all data. Protobuf files are human readable, and export to JSON is supported out of the box. This allows to dump data into files and read it back later in a human readable format. ### Goals * proto IDL files for a type are feature complete, i.e. serializing and deserializing leads to the exact same data structure * provide generic helper functions for serialization ### Non-goals * similar to module **types**, **types_proto** is meant to be generic, and project specific (non-generalizable) methods shall not be added ### Requirements * Types are independent of their serialization method, but the module **types_proto** depends on module **types**. ## Type of change - New feature (non-breaking change which adds functionality) ## Checklist before requesting a review - [x] I have performed a self-review of my code. - [x] If it is a core feature, I have added thorough tests. - [ ] If this is a new component I have added examples. - [x] I updated the README and related documentation. --------- Co-authored-by: Filippo Brizzi <[email protected]> Co-authored-by: Florian Tschopp <[email protected]>
- Loading branch information
1 parent
76d596a
commit 6257f1e
Showing
14 changed files
with
364 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# ================================================================================================= | ||
# Copyright (C) 2023-2024 HEPHAESTUS Contributors | ||
# ================================================================================================= | ||
|
||
declare_module( | ||
NAME types_proto | ||
DEPENDS_ON_MODULES random serdes types | ||
DEPENDS_ON_EXTERNAL_PROJECTS "" | ||
) | ||
|
||
add_subdirectory(proto) | ||
|
||
# library sources | ||
set(SOURCES src/dummy_type.cpp README.md include/hephaestus/types_proto/dummy_type.h) | ||
|
||
# library target | ||
define_module_library( | ||
NAME types_proto | ||
PUBLIC_LINK_LIBS hephaestus::random hephaestus::serdes hephaestus::types hephaestus::types_gen_proto | ||
PRIVATE_LINK_LIBS "" | ||
SOURCES ${SOURCES} | ||
PUBLIC_INCLUDE_PATHS $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> | ||
PRIVATE_INCLUDE_PATHS "" | ||
SYSTEM_PRIVATE_INCLUDE_PATHS "" | ||
) | ||
|
||
# Subprojects | ||
add_subdirectory(tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# README: types_protobuf | ||
|
||
## Brief | ||
|
||
Module **types_protobuf** provides mapping of **types** data structures to proto IDL. | ||
|
||
## Detailed description | ||
|
||
Protobuf is used to serialize all data. Protobuf files are human readable, and export to JSON is supported out of the box. This allows to dump data into files and read it back later in a human readable format. | ||
|
||
### Goals | ||
* proto IDL files for a type are feature complete, i.e. serializing and deserializing leads to the exact same data structure | ||
* provide generic helper functions for serialization (e.g for `std::chrono::time_point`) | ||
|
||
### Non-goals | ||
* similar to module **types**, **types_protobuf** is meant to be generic, and project specific (non-generalizable) methods shall not be added | ||
|
||
### Requirements | ||
* Types are independent of their serialization method, but the module **types_protobuf** depends on module **types**. |
31 changes: 31 additions & 0 deletions
31
modules/types_proto/include/hephaestus/types_proto/dummy_type.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//================================================================================================= | ||
// Copyright (C) 2023-2024 HEPHAESTUS Contributors | ||
//================================================================================================= | ||
|
||
#pragma once | ||
|
||
#include "hephaestus/serdes/protobuf/concepts.h" | ||
#include "hephaestus/types/dummy_type.h" | ||
#include "hephaestus/types/proto/dummy_type.pb.h" | ||
|
||
namespace heph::serdes::protobuf { | ||
template <> | ||
struct ProtoAssociation<types::DummyPrimitivesType> { | ||
using Type = types::proto::DummyPrimitivesType; | ||
}; | ||
|
||
template <> | ||
struct ProtoAssociation<types::DummyType> { | ||
using Type = types::proto::DummyType; | ||
}; | ||
} // namespace heph::serdes::protobuf | ||
|
||
namespace heph::types { | ||
auto toProto(proto::DummyPrimitivesType& proto_dummy_primitives_type, | ||
const DummyPrimitivesType& dummy_primitives_type) -> void; | ||
auto fromProto(const proto::DummyPrimitivesType& proto_dummy_primitives_type, | ||
DummyPrimitivesType& dummy_primitives_type) -> void; | ||
|
||
auto toProto(proto::DummyType& proto_dummy_type, const DummyType& dummy_type) -> void; | ||
auto fromProto(const proto::DummyType& proto_dummy_type, DummyType& dummy_type) -> void; | ||
} // namespace heph::types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ================================================================================================= | ||
# Copyright (C) 2023-2024 HEPHAESTUS Contributors | ||
# ================================================================================================= | ||
|
||
set(SOURCES | ||
hephaestus/types/proto/dummy_type.proto | ||
) | ||
|
||
define_module_proto_library(NAME types_gen_proto SOURCES ${SOURCES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: v1 | ||
breaking: | ||
use: | ||
- FILE | ||
except: | ||
# https://docs.buf.build/breaking/rules#file_no_delete | ||
# hephaestus is monorepo, build system will fail the build if this file is used. | ||
- FILE_NO_DELETE | ||
lint: | ||
use: | ||
- DEFAULT | ||
except: | ||
- PACKAGE_VERSION_SUFFIX |
43 changes: 43 additions & 0 deletions
43
modules/types_proto/proto/hephaestus/types/proto/dummy_type.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//================================================================================================= | ||
// Copyright (C) 2023-2024 HEPHAESTUS Contributors | ||
//================================================================================================= | ||
|
||
syntax = "proto3"; | ||
|
||
package heph.types.proto; | ||
|
||
enum DummyTypeDummyEnum { | ||
A = 0; | ||
B = 1; | ||
C = 2; | ||
D = 3; | ||
E = 4; | ||
F = 5; | ||
G = 6; | ||
} | ||
|
||
message DummyPrimitivesType { | ||
bool dummy_bool = 1; | ||
|
||
int32 dummy_int8_t = 2; | ||
int32 dummy_int16_t = 3; | ||
int32 dummy_int32_t = 4; | ||
int64 dummy_int64_t = 5; | ||
|
||
uint32 dummy_uint8_t = 6; | ||
uint32 dummy_uint16_t = 7; | ||
uint32 dummy_uint32_t = 8; | ||
uint64 dummy_uint64_t = 9; | ||
|
||
float dummy_float = 10; | ||
double dummy_double = 11; | ||
} | ||
|
||
message DummyType { | ||
DummyPrimitivesType dummy_primitives_type = 1; | ||
|
||
DummyTypeDummyEnum dummy_enum = 2; | ||
|
||
string dummy_string = 3; | ||
repeated int32 dummy_vector = 4; | ||
} |
Oops, something went wrong.