babashka

jeeger 2025-04-29T13:01:02.810829Z

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?

teodorlu 2025-04-29T13:19:12.831269Z

Byte is one byte, I believe [B is an array of bytes.

jeeger 2025-04-29T13:22:50.818339Z

Seems there's something screwy with the bencoding, Babashka doesn't even want the description message.

borkdude 2025-04-29T13:24:16.420889Z

in case you haven't seen it, here's an example rust pod: https://github.com/babashka/pod-babashka-filewatcher

πŸ‘ 1
jeeger 2025-04-29T13:26:55.701679Z

Yeah, I'm copying that one, but using a different bencode crate.

borkdude 2025-04-29T13:27:32.992249Z

this website says "invalid integer" when decoding the bencode: https://adrianstoll.com/post/bencoding/

borkdude 2025-04-29T13:28:10.540639Z

or perhaps I should remove the \ escape char from your pasted bencode?

βœ… 1
borkdude 2025-04-29T13:28:13.615499Z

that does work

borkdude 2025-04-29T13:28:28.702989Z

that gives me:

{
  "id": "dddca2e8-9956-44c2-878c-47f7ee1746de",
  "status": "[\"done\"]",
  "value": "[]"
}

jeeger 2025-04-29T13:28:41.762669Z

Thanks, I'll have a look at that!

jeeger 2025-04-29T13:31:57.867739Z

Yeah, that was rust debug output .

borkdude 2025-04-29T13:41:30.432369Z

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"]}

borkdude 2025-04-29T13:42:53.457909Z

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" "[]"}

jeeger 2025-04-29T14:52:00.333479Z

Ah, found the problem. The list in status needs to be a bencoded list of strings, not a bencoded string of a JSON list.

borkdude 2025-04-29T14:52:21.091639Z

πŸ‘

AndrΓ© Camargo 2025-04-29T13:53:05.741509Z

OlΓ‘, I'd like your feedback https://github.com/babashka/cli/issues/121 πŸ™‚ Thanks in advance

borkdude 2025-04-29T13:54:41.316619Z

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 :)

seancorfield 2025-04-29T14:34:25.284519Z

tools.cli doesn't support this either πŸ™‚

seancorfield 2025-04-29T14:34:59.388379Z

(and there has already been a long discussion about possible alternative approaches that do work with tools.cli)