Reading data from the network without knowing the size of the buffer that is coming
Roman Sztergbaum
rmscastle at gmail.com
Thu Mar 21 16:54:01 UTC 2019
Hello !
in my function :
```D
private config_load_answer load_config(string[] args)
in(args !is null, "args cannot be null")
in(args.length == 2, "need 1 arguments")
out(r; r.state == "SUCCESS", "load_config should succeed")
out(r; !r.config_name.empty, "config_name should not be
empty")
out(r; r.config_id > 0, "config_id should be different than
0")
{
string config_key;
string readonly_config_key;
getopt(args, "key", &config_key, "readonly_key",
&readonly_config_key);
auto cfg =
deserialize_to!config_load("../API_doc/json_recipes/config_load.json");
cfg.config_key = config_key;
cfg.readonly_config_key = readonly_config_key;
writeln(cfg);
writeln(cfg.serializeToJsonPretty);
client_.socket.send(cfg.serializeToJson);
auto answer = new ubyte[256]; //
client_.socket.receive(answer);
(cast(string) answer).writeln;
return (cast(string)
answer).deserialize!config_load_answer;
}
```
I would like to get rid of the "ubytes[256]" because I do not
know the size of the data that is comming, I would like to read
the entire buffer that I send at once. Can someone point me?
(i'm pretty new to D langage, but i'm familiar with C++, and for
example in boost asio we have `byte_transfered` so we can create
a buffer with this size and read the incoming data)
Thank's a lot for your help !
More information about the Digitalmars-d-learn
mailing list