Skip to main content

A Python library to generate C++ classes from JSON for working with structs.

Project description

TitaniumProto

TitaniumProto is a Python library designed to facilitate working with C++ structs. It reads a JSON file in a specific format and converts it into a C++ class that closely mirrors the JSON structure. The generated class includes methods for serializing and deserializing data, making it suitable for embedded systems and other applications requiring efficient data handling.

Motivation

I created this project to streamline the process of defining and managing data structures in C++ projects. By using a JSON-based format, TitaniumProto enables quick prototyping and seamless integration of structured data into C++ applications. The generated C++ classes offer serialization and deserialization capabilities, ensuring data integrity and efficiency in memory-constrained environments.

Features

  • Converts JSON definitions into C++ class structures.
  • Supports serialization and deserialization of data.
  • Easy integration into existing C++ projects.
  • Lightweight and suitable for embedded systems.

Installation

To install TitaniumProto, you can use pip or clone the repository and install dependencies:

Windows

pip install titanium-proto

Linux

pip3 install titanium-proto

Installation using clone and poetry:

git clone https://github.com/your_username/titanium-proto.git
cd titanium-proto
poetry install

Usage

Define Your JSON Structure: Create a JSON file following the specified format. Generate C++ Class: Use TitaniumProto to convert the JSON into a C++ class. Integrate: Include the generated C++ class in your project and utilize its methods for data handling.

Supported Types

The library supports the following data types, each with specific attributes:

  • uint8_t
  • int8_t
  • uint16_t
  • int16_t
  • uint32_t
  • int32_t
  • uint64_t
  • int64_t
  • float
  • double
  • string: This type should have a maximum_size associated.

Example

Consider a JSON file example.json:

{
  "package": "ExamplePackage",
  "syntax": "titanium1",
  "fields": [
    { "name": "id", "type": "uint32_t" },
    { "name": "name", "type": "string", "maximum_size": 32 },
    { "name": "value", "type": "double" }
  ]
}

Generate the C++ class:

titanium-proto -fp example.json

The above command creates a C++ class ExamplePackageProto with methods for accessing, serializing, and deserializing fields. Contributing

Contributions are welcome! Fork the repository, make your changes, and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

titanium_proto-0.1.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

titanium_proto-0.1.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file titanium_proto-0.1.0.tar.gz.

File metadata

  • Download URL: titanium_proto-0.1.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for titanium_proto-0.1.0.tar.gz
Algorithm Hash digest
SHA256 97cab7a2d7ecfabb22bc95e516644f496990c66b2402f4ec72b5074cbff62758
MD5 3a654a7427c4306a52f8861cf9a5dcba
BLAKE2b-256 b92db63209bac2f3b5e869d79987aa3e526e136dabe2953268b8667444beda7b

See more details on using hashes here.

File details

Details for the file titanium_proto-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: titanium_proto-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for titanium_proto-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 765e5b1fdde142f820adce8738f26b711d2f27df2ef84d441747965c34dae2e4
MD5 6dbd6bb422f16e197938067b073b1e77
BLAKE2b-256 7a0d979280eda7999d13e94eea0ec0be468cbb96589b9e8ddd02fb69bc9b70b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page