Hi. Started working on server for Phel. https://github.com/arokettu/bencode/blob/7bd5447c34846476822c01cb62c0765f94a89e8c/src/Engine/Reader.php#L185C18-L185C19 seems too strict and throws errors with Cider/Calva because dict keys are not in alphabetical order e.g. 'id' after 'op' or 'code' after 'op'. Bencode spec seems to have that sort of restriction, but here it's not that strictly followed I assume? Maybe need to change the library, not seeing it has less strict parsing option regarding that.
Bencode indeed is a canonical-representation format (which means equal objects are encoded into equal strings). That requires dictionary keys to be sorted.
What do you mean by "but here it's not that strictly followed I assume"? Where's "here", the nREPL?
Ah, yes, I mean in nREPL server context / editor clients.
I still don't fully understand. You are right on one part for sure – nrepl server doesn't validate the order of keys in incoming messages to the server. But it produces valid outgoing messages.
So what's the problem again, where do you get malformed message from that your library barks on them?
Hmm. Looking what I receive on connect, seems that both of these editors are sending op key first.
Cider: d2:op5:clone2:id1:210:time-stamp29:2025-03-13 19:56:04.740577794e
Calva: d2:op4:eval4:code4:*ns*2:id1:1e
I see, it is indeed a client-side issue then.
Yeah, I can see in the CIDER code that it doesn't attempt to sort the keys. That's not cool, even if it didn't cause problems before.
Interesting finding then. Seems that PHP folks can be pedantic about certain things, hehe. Error what I get:
Arokettu\Bencode\Exceptions\ParseErrorException: Invalid order of dictionary keys: 'code' after 'op' in /home/user/dev/phel-nrepl/vendor/arokettu/bencode/src/Engine/Reader.php
Yeah. We never used the canonical representation property in CIDER or nrepl, but a spec is a spec, you have to adhere to it. @bozhidar We should fix this, what do you think?
It might be a while till we sort this out (sort... hehe), so you indeed might have better luck finding a more lax library in the meantime.
Yea, not a big trouble, thank's.
In this day an age, you may reasonably ask chatgpt to roll you a simple Bencode parser in PHP and embed it into your project. The whole thing will be very small.
@alexyakushev Yes, seems it got sorted (ha-ha), with another lib https://github.com/Rhilip/Bencode/blob/master/src/Bencode.php#L66
@alexyakushev Yeah, we should probably fix it - as you said it “a spec is a spec”. 🙂