Advertisement
Guest User

Untitled

a guest
Sep 18th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.69 KB | None | 0 0
  1. import std.traits;
  2. import std.stdio;
  3.  
  4. static ubyte[] packVarint( ulong value )
  5. out( arr )
  6. {
  7.     writeln( "Inside of out contract: value=", value, " type=", typeid( typeof(value) ), " result=", arr );
  8. }
  9. body
  10. {
  11.     writeln( "Inside of body: value=", value, " type=", typeid( typeof(value) ) );
  12.    
  13.     ubyte[] res;
  14.    
  15.     immutable ubyte maximal = 0b_1000_0000;
  16.    
  17.     while( value >= maximal )
  18.     {
  19.         res ~= cast( ubyte )( value | maximal );
  20.         value >>= 7;
  21.     }
  22.    
  23.     res ~= cast(ubyte) value;
  24.    
  25.     return res;
  26. }
  27.  
  28. void main()
  29. {
  30.     writeln("works:");        
  31.     packVarint( 1 );
  32.    
  33.     writeln("not works:");        
  34.     packVarint( 300 );
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement