aboutsummaryrefslogtreecommitdiff
path: root/c++-libbu++/src/tests/int.cpp
blob: dff5641e4c91d8183fedd005717e156abcfe7d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Copyright (C) 2007-2013 Xagasoft, All rights reserved.
 *
 * This file is part of the libgats library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "gats/integer.h"

#include <bu/sio.h>
#include <bu/membuf.h>
#include <bu/file.h>
#include <stdlib.h>

using namespace Bu;

void hexdump( char *dat, int iSize )
{
    static const char *hex="0123456789ABCDEF";
    printf("----\n");
    for( int j = 0; j < iSize; j += 8 )
    {
        for( int k = j; /*k < iSize &&*/ k < j+8; k++ )
            printf((k<iSize)?"%c%c ":"   ", hex[(dat[k]>>4)&0x0F], hex[dat[k]&0x0F] );
        printf("| ");
        for( int k = j; k < iSize && k < j+8; k++ )
            printf("%c ", (dat[k]>13&&dat[k]<127)?(dat[k]):('.') );
        printf("\n");
    }
    printf("----\n");
}

int main( int argc, char *argv[] )
{
    Bu::File mb("test.gats", Bu::File::WriteNew );
    for( int j = 1; j < argc; j++ )
    {
        int64_t i = strtoll( argv[j], NULL, 10 );
        Gats::Integer::writePackedInt( mb, i );
//        hexdump( mb.getString().getStr(), mb.getString().getSize() );
    }
/*
    sio << "Before: " << i << sio.nl;
    Gats::Integer::writePackedInt( mb, i );
    mb.write("aaa", 3 );
    mb.setPos( 0 );
    Gats::Integer::readPackedInt( mb, i );
    sio << "After:  " << i << sio.nl;
    char buf[4];
    buf[mb.read( buf, 3 )] = '\0';
    sio << "Extra: \"" << buf << "\"" << sio.nl;
*/
    return 0;
}