Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cross language demo]go language deserialize demo #128

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

helintongh
Copy link
Contributor

Why

struct_pack support other language.

What is changing

simple_serialize.cpp will serialize a struct named person and create a file which content is serialized string and it's name is example.txt.It also a demo which deserialize string to c language.

go_deserialize.go is a demo that reads this file(example.txt) , which deserializes the string assignment into the struct.

Example

in build/example dirent, use bin cross_language_demo,generate a binary file example.txt. use go run o_deserialize.go.

File use:
simple_serialize.cpp will serialize struct person and create a file which content is serialized string and it's name is example.txt.It also a demo which deserialize string to c language.

go_deserialize.go is a demo that reads this file(example.txt)
, which deserializes the string assignment into the struct.
@CLAassistant
Copy link

CLAassistant commented Dec 17, 2022

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

Code Coverage Report
for detail, goto summary download Artifacts

Filename                                       Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
asio_util/asio_coro_util.hpp                          36                 2    94.44%         166                 2    98.80%           0                 0         -
asio_util/asio_util.hpp                                4                 1    75.00%          22                 5    77.27%           0                 0         -
asio_util/io_context_pool.hpp                          8                 3    62.50%          51                12    76.47%          12                 1    91.67%
coro_rpc/coro_rpc/async_connection.hpp                35                 1    97.14%         384                22    94.27%          60                 7    88.33%
coro_rpc/coro_rpc/async_rpc_server.hpp                16                 2    87.50%         211                28    86.73%          52                17    67.31%
coro_rpc/coro_rpc/common_service.hpp                   3                 0   100.00%          55                 0   100.00%          10                 0   100.00%
coro_rpc/coro_rpc/connection.hpp                       4                 0   100.00%          63                 1    98.41%           6                 0   100.00%
coro_rpc/coro_rpc/coro_connection.hpp                 24                 1    95.83%         326                31    90.49%          76                10    86.84%
coro_rpc/coro_rpc/coro_rpc_client.hpp                 28                 3    89.29%         438                50    88.58%          80                15    81.25%
coro_rpc/coro_rpc/coro_rpc_server.hpp                 20                 1    95.00%         222                21    90.54%          48                16    66.67%
coro_rpc/coro_rpc/remote.hpp                          10                 1    90.00%         103                13    87.38%          10                 4    60.00%
coro_rpc/coro_rpc/router_impl.hpp                     10                 0   100.00%         310                 8    97.42%          12                 1    91.67%
logging/easylog.hpp                                   15                 4    73.33%         131                78    40.46%          22                 7    68.18%
struct_pack/struct_pack.hpp                           11                 3    72.73%          87                25    71.26%          22                 9    59.09%
struct_pack/struct_pack/error_code.h                   3                 3     0.00%          22                22     0.00%           0                 0         -
struct_pack/struct_pack/md5_constexpr.hpp             20                20     0.00%         163               163     0.00%           0                 0         -
struct_pack/struct_pack/reflection.h                   1                 0   100.00%         536                12    97.76%           0                 0         -
struct_pack/struct_pack/struct_pack_impl.hpp          32                 9    71.88%         782               174    77.75%          86                42    51.16%
struct_pack/struct_pack/tuple.hpp                      1                 1     0.00%           1                 1     0.00%           0                 0         -
util/expected.hpp                                     61                 6    90.16%         171                25    85.38%          28                 6    78.57%
util/magic_names.hpp                                   1                 1     0.00%          11                11     0.00%           0                 0         -
util/meta_string.hpp                                   3                 3     0.00%           8                 8     0.00%           0                 0         -
util/string_finder.hpp                                 2                 2     0.00%          11                11     0.00%           0                 0         -
util/type_traits.h                                     1                 0   100.00%           9                 0   100.00%           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                349                67    80.80%        4283               723    83.12%         524               135    74.24%

…file deserialize to struct

go_deserialize will create a file named golang_serialize.txt.
read_from_other which source code is deserialize_from_other_language.cpp will read serialized string and deserialize string to cpp struct.

the struct person meta json is following:

{
   "hash_code": 2242444774,
   "struct_name": "person",
   "fileds": [
      {
         "field_name": "age",
         "field_type": "int32"
      },
      {
         "field_name": "name",
         "field_type": "string"
      }
   ]
}
@github-actions
Copy link

Code Coverage Report
for detail, goto summary download Artifacts

Filename                                       Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
asio_util/asio_coro_util.hpp                          36                 2    94.44%         166                 2    98.80%           0                 0         -
asio_util/asio_util.hpp                                4                 1    75.00%          22                 5    77.27%           0                 0         -
asio_util/io_context_pool.hpp                          8                 3    62.50%          51                12    76.47%          12                 1    91.67%
coro_rpc/coro_rpc/async_connection.hpp                35                 1    97.14%         384                22    94.27%          60                 7    88.33%
coro_rpc/coro_rpc/async_rpc_server.hpp                16                 2    87.50%         211                28    86.73%          52                17    67.31%
coro_rpc/coro_rpc/common_service.hpp                   3                 0   100.00%          55                 0   100.00%          10                 0   100.00%
coro_rpc/coro_rpc/connection.hpp                       4                 0   100.00%          63                 1    98.41%           6                 0   100.00%
coro_rpc/coro_rpc/coro_connection.hpp                 24                 1    95.83%         326                33    89.88%          76                11    85.53%
coro_rpc/coro_rpc/coro_rpc_client.hpp                 28                 3    89.29%         438                50    88.58%          80                15    81.25%
coro_rpc/coro_rpc/coro_rpc_server.hpp                 20                 1    95.00%         222                21    90.54%          48                16    66.67%
coro_rpc/coro_rpc/remote.hpp                          10                 1    90.00%         103                13    87.38%          10                 4    60.00%
coro_rpc/coro_rpc/router_impl.hpp                     10                 0   100.00%         310                 8    97.42%          12                 1    91.67%
logging/easylog.hpp                                   15                 4    73.33%         131                78    40.46%          22                 7    68.18%
struct_pack/struct_pack.hpp                           11                 3    72.73%          87                25    71.26%          22                 9    59.09%
struct_pack/struct_pack/error_code.h                   3                 3     0.00%          22                22     0.00%           0                 0         -
struct_pack/struct_pack/md5_constexpr.hpp             20                20     0.00%         163               163     0.00%           0                 0         -
struct_pack/struct_pack/reflection.h                   1                 0   100.00%         536                12    97.76%           0                 0         -
struct_pack/struct_pack/struct_pack_impl.hpp          32                 9    71.88%         782               174    77.75%          86                42    51.16%
struct_pack/struct_pack/tuple.hpp                      1                 1     0.00%           1                 1     0.00%           0                 0         -
util/expected.hpp                                     61                 6    90.16%         171                25    85.38%          28                 6    78.57%
util/magic_names.hpp                                   1                 1     0.00%          11                11     0.00%           0                 0         -
util/meta_string.hpp                                   3                 3     0.00%           8                 8     0.00%           0                 0         -
util/string_finder.hpp                                 2                 2     0.00%          11                11     0.00%           0                 0         -
util/type_traits.h                                     1                 0   100.00%           9                 0   100.00%           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                349                67    80.80%        4283               725    83.07%         524               136    74.05%

@PikachuHyA
Copy link
Collaborator

please sign CLA

@@ -0,0 +1,80 @@
package main
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add ci for this demo is better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,I will change package name and add test for this demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants