Skip to content

gramaziokohler/compas_pb

Repository files navigation

compas_pb

PyPI version Python versions License MIT Build Status Documentation

A COMPAS extension which lets you serialize and deserialize COMPAS Data types using protobuf.

Installation

Stable releases can be installed from PyPI.

pip install compas_pb

Basic Usage

Serialize to file

from compas.geometry import Vector
from compas_pb import pb_dump
from compas_pb import pb_load

PATH = "vector.data"

vector = Vector(1.0, 2.0, 3.0)

pb_dump(vector, PATH)

loaded_vector = pb_load(PATH)

(De)serialize to bytes

from compas.geometry import Vector
from compas_pb import pb_dump_bts
from compas_pb import pb_load_bts

vector = Vector(1.0, 2.0, 3.0)

bytes_vector = pb_dump_bts(vector)

loaded_vector = pb_load_bts(bytes_vector)

Serialization of arbitrarily nested data structures

from compas.geometry import Vector
from compas.geometry import Polyline
from compas_pb import pb_dump_bts
from compas_pb import pb_load_bts

data = {
    "direction": Vector(1.0, 2.0, 3.0),
    "outlines": 
        [
            Polyline([0, 0, 0], [1, 1, 1], [2, 2, 2]), 
            Polyline([3, 3, 3], [4, 4, 4], [5, 5, 5])
        ],
}

pb_data = pb_dump_bts(data)

loaded_data = pb_load_bts(pb_data)

Documentation

For further "getting started" instructions, a tutorial, examples, and an API reference, please check out the online documentation here: compas_pb docs

Issue Tracker

If you find a bug or if you have a problem with running the code, please file an issue on the Issue Tracker.

About

A COMPAS extension which lets you serialize and deserialize COMPAS Data types using protobuf.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 6

Languages