~eda-qa/dhlib/main

« back to all changes in this revision

Viewing changes to restricted/wordlib/src/writeraw.cc

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <string>
 
2
#include <fstream>
 
3
#include <core/stdtypes.h>
 
4
#include <netinet/in.h>
 
5
 
 
6
#include <iostream>
 
7
using namespace std;
 
8
 
 
9
void writeRAW( const std::string& file, const _uint8* data, _uint32 len )
 
10
{
 
11
        //adapt to network order
 
12
        _uint32 nlen = htonl( len );
 
13
 
 
14
        ofstream out( file.c_str(), ios::binary );
 
15
        out.write( "WRAW", 4 );
 
16
        out.write( (char*)&nlen, sizeof(nlen) );        
 
17
        out.write( (char*)data, len );
 
18
        out.write( (char*)&nlen, sizeof(nlen) );
 
19
        
 
20
        out.close();
 
21
}
 
22
 
 
23
_uint8* loadRAW( const std::string& file )
 
24
{
 
25
        ifstream in( file.c_str(), ios::binary );
 
26
        _uint8 buf[4];
 
27
        in.read( (char*)buf, 4 );
 
28
        
 
29
        _uint32 len;
 
30
        in.read( (char*)&len, sizeof(len) );
 
31
        len = ntohl( len );     //back to host order
 
32
        
 
33
        _uint8* data = new _uint8[len];
 
34
        in.read( (char*)data, len );
 
35
        
 
36
        return data;
 
37
}
 
38