6

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.

rgchris
  • 3,698
  • 19
  • 19

4 Answers4

5

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.

BrianH
  • 2,186
  • 16
  • 14
4

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 ...

pekr
  • 96
  • 1
  • 3
  • He is the source. Pekr and I were on the team that was originally working on R3. His role was more to point out things that we messed or were not doing right - that's not an insult, he's actually really good at that, a one-person focus group. He was the one who originally pointed out the flaws in the current codec model, and made the initial suggestions for the capabilities that a new model must have, that the current model doesn't. You *can* take his word for it. – BrianH Feb 20 '13 at 17:03
2

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.

MaxV
  • 588
  • 1
  • 4
  • 13
  • Max, he already has a JSON parser; he linked it in his question. The question is about changing that JSON parser into a codec for R3. – BrianH Feb 01 '13 at 13:49
0

I just noticed that system/catalog/codecs is removed from Rebol 3; so I suppose that the feature was removed after 31-Mar-2009.

>> ? system/catalog
SYSTEM/CATALOG is an object of value:
 datatypes       block!    length: 56
 actions         block!    length: 56
 natives         block!    length: 159
 errors          object!   [Throw Note Syntax Script Math Access Command...
 reflectors      block!    length: 6
 boot-flags      block!    length: 18
MaxV
  • 588
  • 1
  • 4
  • 13
  • Nope, we just reorganized the system a few times; `system/catalog/codecs` became `system/codecs` at some point, and it even has the same structure. Feature is still there. However, we never did make it possible to make mezzanine codecs, even from the beginning. – BrianH Feb 20 '13 at 10:44