Re: Using C library libsndfile with D
D has the pragma(lib) feature where you can tell the compiler to link with a specific library as well. For example: pragma(lib, curl); I want to try that as soon as I get home from work. You probably need to make a .lib file from the dll too. The implib program does that. If you don't have it, if you wanna email me the libsoundfile.dll program, I'll run it and make the .lib for you. Your advice and your time is very important for me. I will try to run implib. I think it is important to get use to this tool for future anyways. Thanks alot Erdem
Re: Filling a char array with letters and element type of char[]
@Tobias @Ali @Jonathan @Steven Thanks alot for your answers. I will try to learn as much as I can from them. Regards Erdem
Getting the socket information from HTTP and DNS sessions
I have been ask to write a test tool which initiates DNS-HTTP-HTTPS-TCP sessions. And ofcourse I wrote this with D. For HTTP I used std.net like m_HTTP = HTTP(m_url);m_HTTP.perform(); For DNS I simply used getAddressInfo(m_domainName); Than tool makes some simple checks which are npt subjects of this thread and the tool works well, But now I need to make an improvement. I need to get sourceIP(ip which program runs), sourcePort( eg: 53212 not 80), destIP, destPort(most probably 80) from the session which I initiated. I need functions like std.socket.localAddress, std.socket.remoteAddress for HTTP-DNS but couldn't managed to find them. Is there any way that I can get socket info in HTTP and DNS sessions which I initiated? Regards Kadir Erdem
Filling a char array with letters and element type of char[]
I have an char[]; char[] strArr = http://www.hurriyet.com.tr/ekonomi.dup; I stripped the domain out of url like: auto domain = findSplitAfter(strArr, http://;)[1].until('/'); Than because I am new to the language I became curious if I change domain(which I believe a input iterator); the values of strArr will also change or not. I tried to to modify domain like : fill(domain, 'a'); Which gives error : cannot deduce function from argument types !()(Until!(a == b, char[], char), char) But if the array is a array of ints it compiles. I believe it fails because in compile messages I see std.algorithm.fill(Range, Value)(Range range, Value filler) if (isInputRange!Range is(typeof(range.front = filler))) and writeln( is(typeof(url.front = 'a')) ); --- false writeln( is(typeof(intArr.front = 0)) ); --- true(that is why compiles) I have three questions? If I change the iterator which I get from algorithm, the owner data will change or not? How to use std.algorithm.fill with char types? What is the type of char array holds why it does not matches char? Regards Kadir Erdem
Starting a HTTPS session with D
Hi We have a network traffic logger module at office. We need to a tool which creates simple traffic with different protocols and test our product's output to see if we parse the headers correctly or not. And of course I proposed writing this tool with D!!! When it comes to create a HTTP session it is very easy auto content = get(dlang.org); But I couldn't find any examples about https. Do I have to use a C library like libcurl for it. Or is there a native way do solve my problem. Regards Erdem
Re: Starting a HTTPS session with D
get(https://dlang.org;, http); It works as I wanted, thanks a lot . Regards Erdem
Using reduce with user types
I can use filter algorithm with my types easily. struct A { string value; int count; } void main( string[] args ) { A[] aArr; aArr ~= A(HTTP, 3); aArr ~= A(HTTPS, 2); aArr ~= A(UNKNOWN_TCP, 4); aArr.filter!( a = a.count == 2); But I couldn't compile when I want to use reduce algorithm. I simply want to get the sum of count variables inside of A[]. auto sum = aArr.reduce!((a,b) = a.count + b.count); The line above gives C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(770): Error: cannot implicitly convert expression (__lambda3(result, front(_param_1))) of type int to A C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(791): Error: template instance app.main.reduce!((a, b) = a.count + b.count).reduce!(A, A[]) error instantiating source\app.d(363):instantiated from here: reduce!(A[]) How can I achieve summing count variables inside A[]? Best Regards Kadir Erdem Demir Ps: The problem caused by my lack of D basics I admit, the reason I can't look up references more before ask question I am in a bit tight schedule. Sorry for my dummy questions.
Re: Using reduce with user types
auto sum = aArr.map!`a.count`.reduce!((a,b) = a + b); Rikki Thanks a lot. It works. Function map!a.count(aArr) surprises me a little. Because when I read std.algorithm reference: `Implements the homonym function (also known as transform)`. Which reminds me C++ transform and it will never used for returning a element of the struct. I expect transform to modify the elements of the range but in D it seem to me it also used traversing the elements. How can I imagine what map does in my mind, because it doesn't matches with the transform concept in my mind? Regards Kadir Erdem
Record separator is being lost after string cast
I am opening a .gz file and reading it chunk by chunk for uncompressing it. The data in the uncompressed file is like : aRSbRScRSd, There are record separators(ASCII code 30) between each record(records in my dummy example a,b,c). File file = File(mylog.gz, r); auto uc = new UnCompress(); foreach (ubyte[] curChunk; file.byChunk(4096*1024)) { auto uncompressed = cast(string)uc.uncompress(curChunk); writeln(uncompressed); auto stringRange = uncompressed.splitLines(); foreach (string line; stringRange) { * Do something with line The result of the code above is: abcd unfortunately record separators(ASCII 30) are missing. I realized by examining the data record separators are missing after I cast ubyte[] to string. Now I have two questions : Urgent one (my boss already a little disturbed I started the task with D I need to solve this): What should I change in the code to keep record separator? Second one : How can I write the code above without for loops? I want to read gz file line by line. A more general and understandable code for first question : ubyte[] temp = [ 65, 30, 66, 30, 67]; writeln(temp); string tempStr = cast(string) temp; writeln (tempStr); Result is : ABC which is not desired. Thanks Kadir Erdem
Re: Record separator is being lost after string cast
don't beleive what you see! ;-) I am sorry make a busy community more busy with false alarms. When I write to file I saw Record Separator really exists. I hope my second question is a valid one. How can I write the code below better? How can I reduce the number of foreach? statements. File file = File(mylog.gz, r); auto uc = new UnCompress(); foreach (ubyte[] curChunk; file.byChunk(4096*1024)) { auto uncompressed = cast(string)uc.uncompress(curChunk); writeln(uncompressed); auto stringRange = uncompressed.splitLines(); foreach (string line; stringRange) { Thanks a lot for replies Kadir Erdem
Re: Record separator is being lost after string cast
Thanks a lot, I will follow your advise and implement this part same as your example. Regards Kadir Erdem