{"id":21462032,"url":"https://github.com/philip-murray/cereal-raw-pointer-support-crps","last_synced_at":"2025-10-13T20:38:21.050Z","repository":{"id":250548415,"uuid":"565157788","full_name":"philip-murray/cereal-raw-pointer-support-CRPS","owner":"philip-murray","description":"CRPS - cereal raw pointer support. Enables serialization of non-owning pointers which point to objects that are co-serialized by the cereal graph traversal. ","archived":false,"fork":false,"pushed_at":"2022-11-18T23:06:36.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T04:51:22.544Z","etag":null,"topics":["c-plus-plus","cereal","pointers-in-c","serialization"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/philip-murray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-12T14:19:48.000Z","updated_at":"2024-08-31T18:44:55.000Z","dependencies_parsed_at":"2024-07-28T11:41:58.798Z","dependency_job_id":null,"html_url":"https://github.com/philip-murray/cereal-raw-pointer-support-CRPS","commit_stats":null,"previous_names":["philip-murray/cereal-raw-pointer-support-crps"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/philip-murray/cereal-raw-pointer-support-CRPS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philip-murray%2Fcereal-raw-pointer-support-CRPS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philip-murray%2Fcereal-raw-pointer-support-CRPS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philip-murray%2Fcereal-raw-pointer-support-CRPS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philip-murray%2Fcereal-raw-pointer-support-CRPS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/philip-murray","download_url":"https://codeload.github.com/philip-murray/cereal-raw-pointer-support-CRPS/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philip-murray%2Fcereal-raw-pointer-support-CRPS/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279016932,"owners_count":26085910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","cereal","pointers-in-c","serialization"],"created_at":"2024-11-23T07:12:18.677Z","updated_at":"2025-10-13T20:38:21.036Z","avatar_url":"https://github.com/philip-murray.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"CRPS - Cereal Raw Pointer Support (Experimental)\n==========================================\n\nCRPS enables serialization of raw pointers which point to objects that are co-serialized by the graph traversal. This allows for references to be taken to a struct's members without allocating the members seperately with a std::shared_ptr. CRPS was intented for cases where a class is allocated with a std::shared_ptr, but a reference to one it's members must persist as well. \n\u003cbr\u003e\u003c/br\u003e\n\n## Usage\n\nTo use CRPS, construct an archive as normal, and then place the archive into the constructor of either ```crps::CRPSOutputArchive\u003cArchiveType\u003e``` or ```crps::CRPSInputArchive\u003cArchiveType\u003e```. All serialization calls must be done through the CRPSArchive class instead of the ArchiveType archive. To finish serialization, the CRPSArchive's destructor must execute, or alternatively the CRPSArchive complete() method may be called. \n\nA class may serialize a ```T*``` by passing it into ```crps::make_raw_ptr(T*)``` before the archive call. Alternatively, ```crps::raw_ptr\u003cT\u003e``` may be used in place of ```T*```. For STL types, ```std::vector\u003cT*\u003e``` does not compile, but ```std::vector\u003craw_ptr\u003cT\u003e\u003e``` does.\n\u003cbr\u003e\u003c/br\u003e\n\n**Example 1:** \n\n```cpp\n#include \u003ccereal/archives/binary.hpp\u003e\n#include \u003ccrps/crps.hpp\u003e\n#include \u003cfstream\u003e\n\nint main() {\n\n    int x = 4;\n    int* y = \u0026x;\n    {\n        std::ofstream os(\"save.out\", std::ios::binary);\n        cereal::BinaryOutputArchive oarchive(os);\n        crps::CRPSOutputArchive\u003ccereal::BinaryOutputArchive\u003e crps_oarchive(oarchive);\n\n        crps_oarchive(x, crps::make_raw_ptr(y));\n    }\n\n    int x_load;\n    int* y_load;\n    {\n        std::ifstream is(\"save.out\", std::ios::binary);\n        cereal::BinaryInputArchive iarchive(is);\n        crps::CRPSInputArchive\u003ccereal::BinaryInputArchive\u003e crps_iarchive(iarchive);\n\n        crps_iarchive(x_load, crps::make_raw_ptr(y_load));\n    }\n\n    std::cout \u003c\u003c *y_load \u003c\u003c std::endl; //4\n\n}\n```    \n\u003cbr\u003e\u003c/br\u003e\n**Example 2:** In this example, instead of a graph with vertex-to-vertex connections, a vertex connects to a target within another vertex. Therefore, the edge class cannot just store two shared_ptrs without also keeping track of a local target index within the second vertex. With CRPS, the Edge class can store a raw pointer to the target within the second vertex.\n\n```cpp\nstruct Vertex {\n\n    float targetA;\n    float targetB;\n\n    template\u003cclass Archive\u003e\n    void serialize(Archive\u0026 ar)\n    { ar(targetA, targetB); }\n\n};\n\nstruct Edge {\n    \n    std::shared_ptr\u003cVertex\u003e vertex;\n    crps::raw_ptr\u003cfloat\u003e target; //can either point to a vertex's targetA or targetB\n\n    template\u003cclass Archive\u003e\n    void serialize(Archive\u0026 ar)\n    { ar(vertex, target); }\n\n};\n\nint main() {\n\n    std::shared_ptr\u003cVertex\u003e v1 = std::make_shared\u003cVertex\u003e(Vertex{ 1, 2 });\n    std::shared_ptr\u003cVertex\u003e v2 = std::make_shared\u003cVertex\u003e(Vertex{ 4, 5 });\n\n    Edge e1{ v1, \u0026v1-\u003etargetB }; //v1 connects to it's own targetB\n    Edge e2{ v1, \u0026v2-\u003etargetA }; //v1 connects to v2's targetA\n\n\n    std::vector\u003cstd::shared_ptr\u003cVertex\u003e\u003e vertices{ v1, v2 };\n    std::vector\u003cEdge\u003e edges{ e1, e2 };\n    {\n        std::ofstream os(\"out.txt\", std::ios::binary);\n        cereal::BinaryOutputArchive oarchive(os);\n        crps::CRPSOutputArchive\u003ccereal::BinaryOutputArchive\u003e crps_oarchive(oarchive);\n\n        crps_oarchive(vertices, edges);\n    }\n\n\n    std::vector\u003cstd::shared_ptr\u003cVertex\u003e\u003e vertices_load;\n    std::vector\u003cEdge\u003e edges_load;\n    {\n        std::ifstream is(\"out.txt\", std::ios::binary);\n        cereal::BinaryInputArchive iarchive(is);\n        crps::CRPSInputArchive\u003ccereal::BinaryInputArchive\u003e crps_iarchive(iarchive);\n\n        crps_iarchive(vertices_load, edges_load);\n    }\n\n    std::cout \u003c\u003c *edges_load[0].target \u003c\u003c std::endl; //2\n    std::cout \u003c\u003c *edges_load[1].target \u003c\u003c std::endl; //4\n\n}\n```\n\u003cbr\u003e\u003c/br\u003e\n\n## this-pointer support\n\nCRPS allows for serialization of pointers to class types which are co-serialized by the graph traversal.\nTo do this, the class type must pass a ```crps::this_ptr(this)``` into the archive of its member serialize method. \n\n**Example 3:**\n\n```cpp\nstruct Point {\n    \n    float x, y;\n    template\u003cclass Archive\u003e\n    void serialize(Archive\u0026 ar)\n    {\n        ar(x, y, crps::this_ptr(this));\n    }\n};\n\nint main() {\n\n    {\n        Point point{ 3, 4 };\n        Point* p = \u0026point;\n        float* x = \u0026point.x;\n        float* y = \u0026point.y;\n\n        std::ofstream os(\"save.out\", std::ios::binary);\n        cereal::BinaryOutputArchive oarchive(os);\n        crps::CRPSOutputArchive\u003ccereal::BinaryOutputArchive\u003e crps_oarchive(oarchive);\n\n        crps_oarchive(crps::make_raw_ptr(p), crps::make_raw_ptr(x), crps::make_raw_ptr(y), point);\n    }\n\n\n    Point point;\n    Point* p;\n    float* x;\n    float* y;\n    {\n        std::ifstream is(\"save.out\", std::ios::binary);\n        cereal::BinaryInputArchive iarchive(is);\n        crps::CRPSInputArchive\u003ccereal::BinaryInputArchive\u003e crps_iarchive(iarchive);\n\n        crps_iarchive(crps::make_raw_ptr(p), crps::make_raw_ptr(x), crps::make_raw_ptr(y), point);\n    }\n\n    std::cout \u003c\u003c \u0026point \u003c\u003c std::endl; \n    std::cout \u003c\u003c p \u003c\u003c std::endl; // prints \u0026point\n    std::cout \u003c\u003c x \u003c\u003c std::endl; // prints \u0026point\n    std::cout \u003c\u003c y \u003c\u003c std::endl; // prints \u0026point + sizeof(float) bytes\n    \n}\n```\n\u003cbr\u003e\u003c/br\u003e\n\n## Binary Data\n\nCRPS does not currently support tracking pointers during the serialization of binary data. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilip-murray%2Fcereal-raw-pointer-support-crps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphilip-murray%2Fcereal-raw-pointer-support-crps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilip-murray%2Fcereal-raw-pointer-support-crps/lists"}