Raised This Month: $ Target: $400
 0% 

Print the content of a trie to the server for debug


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
fakuivan
Senior Member
Join Date: Nov 2015
Old 12-22-2015 , 18:39   Print the content of a trie to the server for debug
Reply With Quote #1

Hi there!

This can turn out to be very useful when dealing with nested handles. It prints the content of a trie to the server console.

Code:
stock void DEBUG_PrintMapStructure(Handle nh_map, char[] ns_mapnametoshow, char[] ns_prefix) 
{ 
    if (nh_map == INVALID_HANDLE) 
    { 
        PrintToServer("%s Invalid map Handle: \"%s\" (0)", ns_prefix, ns_mapnametoshow); 
        return; 
    } 
         
    Handle nh_snapshot = CreateTrieSnapshot(nh_map); 
    int ni_size = TrieSnapshotLength(nh_snapshot); 
    PrintToServer("%s Analyzing Map: \"%s\"", ns_prefix, ns_mapnametoshow); 
    PrintToServer("%s Size of the Map: %i", ns_prefix, ni_size); 
    for (int ni_i = 0; ni_i < ni_size; ni_i++) 
    { 
        int ni_buffersize = TrieSnapshotKeyBufferSize(nh_snapshot, ni_i); 
        char[] ns_buffer = new char[ni_buffersize]; 
        GetTrieSnapshotKey(nh_snapshot, ni_i, ns_buffer, ni_buffersize); 
        int ni_value; 
        PrintToServer("%s     #%i. Key: %s | Value: %s", (GetTrieValue(nh_map, ns_buffer, ni_value) ? ni_value : "--probably an array or a string--")); 
    } 
    PrintToServer("%s Finished analyzing Map: \"%s\"", ns_prefix, ns_mapnametoshow); 
    CloseHandle(nh_snapshot); 
}
how I called it: DEBUG_PrintMapStructure(table, "DBTable", "[DBScanner.inc]");

the output
Code:
[DBScanner.inc] Analyzing Map: "DBTable"
[DBScanner.inc] Size of the Map: 6
[DBScanner.inc]     #1. Key: rows | Value: 3433
[DBScanner.inc]     #2. Key: DBTColumnsName | Value: 97124628
[DBScanner.inc]     #3. Key: name | Value: --probably an array or a string--
[DBScanner.inc]     #4. Key: column_count | Value: 12
[DBScanner.inc]     #5. Key: name__size_ | Value: 12
[DBScanner.inc]     #6. Key: DBTColumns | Value: 97059132
[DBScanner.inc] Finished analyzing Map: "DBTable"
And if for some reason the handle is 0

DEBUG_PrintMapStructure(0, "VOID TEST", "[DBScanner.inc]");

Code:
[DBScanner.inc] Invalid map Handle: "VOID TEST" (0)

Last edited by fakuivan; 12-29-2015 at 22:28. Reason: Thanks to Black-Rabbit
fakuivan is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode