Skip to content

Instantly share code, notes, and snippets.

@philipptempel
Created September 23, 2019 13:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipptempel/af2618c515f78cccdd0ef10936fccde9 to your computer and use it in GitHub Desktop.
Save philipptempel/af2618c515f78cccdd0ef10936fccde9 to your computer and use it in GitHub Desktop.
import cdpyr
from sample import robots
# from prettyprinter import pprint
from marshmallow import pprint, Schema
def main():
# c = cdpyr.robot.Cable(diameter=6.0/1000)
# cblschm: cdpyr.robot.CableSchema = cdpyr.robot.CableSchema()
# jsn = cblschm.dump(c)
# pprint(jsn.data)
#
# o = cblschm.load(jsn.data)
# pprint(o.data)
#
# get a sample robot
r = robots.ipanema_cuboid()
rschema = cdpyr.robot.RobotSchema()
# create an streams object
stream = cdpyr.streams.Stream(cdpyr.streams.parser.JSON())
# encode to a string
encoded_str = stream.encodes(r)
pprint(encoded_str)
# decode from a string
robot = stream.decodes(encoded_str)
pprint(robot)
# # encode to a file
# streams.encode(r, open('robot.json', 'w'))
# # decode from a file
# robot = streams.decode(open('robot.json', 'r'))
if __name__ == "__main__":
main()
@philipptempel
Copy link
Author

Create directory sandbox, save file as streams.py and then run it.
Noe you'll need https://gist.github.com/philipptempel/b5fc4a185b6317aa86bb45cdc29e8517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment