blixt/py-starbound

SBON to YAML conversion?

mk-pmb opened this issue · 5 comments

Hi, very nice work!
Would it seem easy (or maybe interesting?) to you to add conversion from SBON to YAML and back? If I tried myself, would you see some caveats that I should avoid?

That would be easy. Just get a yaml library for Python, and open the world
file with my library and call get_metadata() on it to get a Python dict.
Then use the yaml library to convert it to a yaml string :)

On Tuesday, March 25, 2014, mk-pmb notifications@github.com wrote:

Hi, very nice work!
Would it seem easy (or maybe interesting?) to you to add conversion from
SBON to YAML and back? If I tried myself, would you see some caveats that I
should avoid?

Reply to this email directly or view it on GitHubhttps://github.com//issues/16
.

To clarify, since you already get all the info you need to convert to YAML, there is no reason to add such a library here (same for any other format like XML, etc.)

Hi again,

conversion from SBON to YAML works fine (67fb6d6), but I still can't figure out the reverse direction.

I found some write_… functions in sbon.py, but wonder, how do I open the destination file for writing? FileSBVJ01 inherits its open from filebase.File, which doesn't feature file mode in its params, instead has rb hard-coded.

I tried to find examples of how to use sbon.write_…, but the only mention git grep found outside of sbon.py itself was repair.py writing bytes into a buffer. Could you give me some hints on how to write numbers and dicts into an SBON file? (For strings I already have an idea. Update: Seems like write_bytes even already does the basics, I'd just have to test enforcing UTF-8.)

Update: Looks like for dicts I'd have to make up the inverse function of read_dynamic, creating write_dynamic. Do I see correctly that read_dynamic in its current form is non-injective in mapping all SBON number types to python's default numbers? Then I'd have to add some new mode with stronger data types first.

Yours, MK

Sorry, I haven't finished writing the Starbound format yet (only very
little support to make repair.py work). I'll be working on adding the
missing write functions at some point in the future.

On Wed, Mar 26, 2014 at 10:09 AM, mk-pmb notifications@github.com wrote:

Hi again,

conversion from SBON to YAML works fine (2de6c6ahttps://github.com/blixt/py-starbound/commit/2de6c6a64d9101562a1ed249d4f2e655e2d3f7ff),
but I still can't figure out the reverse direction.

I found some write_... functions in sbon.pyhttps://github.com/blixt/py-starbound/blob/master/starbound/sbon.py,
but wonder, how do I open the destination file for writing? FileSBVJ01https://github.com/blixt/py-starbound/blob/master/starbound/sbvj01.py#L14inherits its
open from filebase.Filehttps://github.com/blixt/py-starbound/blob/master/starbound/filebase.py#L29,
which doesn't feature file mode in its params, instead has rb hard-coded.

I tried to find examples of how to use sbon.write_..., but the only mention git
grep found outside of sbon.py itself was repair.pyhttps://github.com/blixt/py-starbound/blob/master/repair.py#L272writing bytes into a buffer. Could you give me some hints on how to write
numbers and dicts into an SBON file? (For strings I already have an idea.)

Yours, MK

Reply to this email directly or view it on GitHubhttps://github.com//issues/16#issuecomment-38687121
.

No problem, maybe until then I can add some missing parts, too.