I'm trying to write a pod in Rust, and it seems I've successfully sent out a describe message, but when sending out a response (bencoded message is d2:id36:dddca2e8-9956-44c2-878c-47f7ee1746de6:status8:[\"done\"]5:value2:[]e), I get a class cast exception (`class java.lang.Byte cannot be cast to class [B`). The message looks correct, anyone got any pointers?
Byte is one byte, I believe [B is an array of bytes.
Seems there's something screwy with the bencoding, Babashka doesn't even want the description message.
in case you haven't seen it, here's an example rust pod: https://github.com/babashka/pod-babashka-filewatcher
Yeah, I'm copying that one, but using a different bencode crate.
this website says "invalid integer" when decoding the bencode: https://adrianstoll.com/post/bencoding/
or perhaps I should remove the \ escape char from your pasted bencode?
that does work
that gives me:
{
"id": "dddca2e8-9956-44c2-878c-47f7ee1746de",
"status": "[\"done\"]",
"value": "[]"
}Thanks, I'll have a look at that!
Yeah, that was rust debug output .
This looks correct:
$ bb -e '(bencode.core/read-bencode (java.io.PushbackInputStream. (java.io.ByteArrayInputStream. (.getBytes "d2:id36:dddca2e8-9956-44c2-878c-47f7ee1746de6:status8:[\"done\"]5:value2:[]e"))))'
{"id" #object["[B" 0x340c60bf "[B@340c60bf"], "status" #object["[B" 0x8610de1 "[B@8610de1"], "value" #object["[B" 0x43777a73 "[B@43777a73"]}with decoded values:
$ bb -e '(update-vals (bencode.core/read-bencode (java.io.PushbackInputStream. (java.io.ByteArrayInputStream. (.getBytes "d2:id36:dddca2e8-9956-44c2-878c-47f7ee1746de6:status8:[\"done\"]5:value2:[]e")))) (fn [v] (if (vector? v) (map #(String. % "utf-8") v) (String. v "utf-8"))))'
{"id" "dddca2e8-9956-44c2-878c-47f7ee1746de", "status" "[\"done\"]", "value" "[]"}Ah, found the problem. The list in status needs to be a bencoded list of strings, not a bencoded string of a JSON list.
π
OlΓ‘, I'd like your feedback https://github.com/babashka/cli/issues/121 π Thanks in advance
I already left some feedback. Your proposal isn't bad, but I just wondered: it's something that seems easily solved outside bb.cli as well. Just trying to understand your use case a bit more :)
tools.cli doesn't support this either π
(and there has already been a long discussion about possible alternative approaches that do work with tools.cli)