digitalmars.D.learn - How do I call this tamplte function?
- Rib (9/9) Jun 26 2018 to get get() from std.net.curl return a ubyte[] and use my http
- =?UTF-8?Q?Ali_=c3=87ehreli?= (23/34) Jun 26 2018 This worked for me:
to get get() from std.net.curl return a ubyte[] and use my http instance, all those failed: string link = "http://..."; auto client = HTTP(); // set some client attributes... auto fileContents = get!(AutoProtocol, ubyte)(link, client); auto fileContents = get!(ubyte)(link, client); auto fileContents = get!(client, ubyte)(link, client); I still didn't "get" D templates.
Jun 26 2018
On 06/26/2018 10:37 AM, Rib wrote:to get get() from std.net.curl return a ubyte[] and use my http instance, all those failed: string link = "http://..."; auto client = HTTP(); // set some client attributes... auto fileContents = get!(AutoProtocol, ubyte)(link, client); auto fileContents = get!(ubyte)(link, client); auto fileContents = get!(client, ubyte)(link, client); I still didn't "get" D templates.This worked for me: import std.net.curl; import std.stdio; import std.functional; void myHeaderReceivingFunction(const(char[]) key, const(char[]) value) { writefln("Received header: %s = %s", key, value); } size_t myDataReceivingFunction(ubyte[] data) { writefln("Received data; first part: %s", data[0..10]); return data.length; } void main() { auto client = HTTP("http://dlang.org"); // If you don't have an actual delegate, you can use std.functional.toDelegate: client.onReceiveHeader = (&myHeaderReceivingFunction).toDelegate; // ... or you can create a delegate with a lambda on the fly: client.onReceive = (ubyte[] data) { return myDataReceivingFunction(data); }; client.perform(); } Ali
Jun 26 2018