Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you write a codec for Rebol 3?

Tags:

rebol

rebol3

I wrote a JSON encoder/decoder for Rebol 2. I'm rewriting it for Rebol 3 and would prefer to make it available in Rebol 3 as a codec:

load %data.json
save %data.json object
decode 'json to-binary {["some","json"]}

How should I go about this?

At the time of asking, documentation on this subject is scarce.

like image 859
rgchris Avatar asked Jan 16 '13 18:01

rgchris


3 Answers

The simple answer is that you can't. As for why, there are several answers to that.

  1. The current codec model is undocumented. Only Carl knows how to write codecs at the moment. Though someone might be able to look at the source and figure it out, noone has yet.
  2. The current codec functions aren't really flexible enough to make what you want here. You could make a decoder, but not an encoder because encode only takes images, binaries or strings. Maybe just having a decoder is enough for you though.
  3. Only native codecs are supported by the current model. You can't write codecs in Rebol code, and for a parser that means that you can't use parse. Do you have a native code version of your parser?
  4. The current codec model is a placeholder for the codec model we hope to eventually have. This is why it hasn't been that well documented. We eventually hope to support incremental en/decoding, codecs that can read directly from files or other ports, and Rebol codecs. However, we haven't really decided on the final model yet, or even started the discussion of how it will be designed, beyond initial criticisms.

I wish there was a better answer to your question right now.

like image 175
BrianH Avatar answered Sep 29 '22 09:09

BrianH


Codecs were imo in highly non-finished state. I proposed some kind of streamed mechanism was needed, IIRC Carl understood the need, but the solution was never imo outlined. Ditto for tasks - current "implementation" is far from what Carl envisioned for R3 tasking ...

like image 40
pekr Avatar answered Sep 29 '22 08:09

pekr


There is a tool, read this: http://rebol2.blogspot.it/2012/12/json.html

and this: http://www.rebol.com/article/0522.html

However json is a complex way to handle data, rebol block is perfect in my humble opinion.

like image 40
MaxV Avatar answered Sep 29 '22 09:09

MaxV