Open gavin-norman-sociomantic opened 6 years ago
Wouldn't it be better to use dhtcli
in D scripts ? That would also ensure it can be used in any script, not only D
The basic problem is that we need an easy way to modify records in a DHT, for testing. (Read a record, deserialize the struct, change some fields, serialize, write back.) There's no easy way to do this with dhtcli. We did discuss using some kind of struct <-> json converter, say, but I think that'd be a lot more work to develop than the above suggestion would.
Read a record, deserialize the struct, change some fields, serialize, write back.
What I did back in the day for a very similar use case was:
swarm.util.RecordStream
. DHTCLI was spawned via EpollProcess
IIRC.MultiVersionDecorator
vibe.data.json : serializeToJsonString
stdout
That utility was less than 100 LoCs (but only handled deserialization). @christoph-wasicki-sociomantic might still have it hanging around.
Right, the point is that it requires knowledge of the serialized struct, though, right? That alone locks us into the D domain.
Right, the point is that it requires knowledge of the serialized struct, though, right? Right, the point is that it requires knowledge of the serialized struct, though, right?
Sorry, I don't understand your point here. You have a similar use case in profileview, where one can give either the channel or the struct type as argument and have the other one being automatically deduced. The only difference is generating machine readable output as opposed to human readable one. And once it's in JSON, it's accessible to anyone, not just D.
My point is that it always requires D code that knows the type of the struct to be deserialized, either to implement a DHT client API that automatically deserializes or a struct -> json deserializer. I guess you weren't suggesting otherwise, though.
It's really a question of what is simpler to implement and more convenient to use.
I agree that a solution that works via json would be more generic, of course, but we have to think about what is more directly convenient to us right now. (We can also implement both solutions, down the line. There's no reason to have to choose one or the other.)
Currently, initialising and using a DHT client involves a lot of boilerplate, making it unsuitable for use in quick D scripts.
The ideal would be for things like this to work: