-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtoy_data_awkward.cpp
More file actions
75 lines (60 loc) · 2.01 KB
/
Copy pathtoy_data_awkward.cpp
File metadata and controls
75 lines (60 loc) · 2.01 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// BSD 3-Clause License; see https://github.com/jpivarski/awkward-1.0/blob/master/LICENSE
#include <iostream> // std::cout
#include <fstream> // std::ifstream
#include <string> // duh
#include <assert.h> // for fancy erroring
#include "awkward/Slice.h"
#include "awkward/fillable/FillableArray.h"
#include "awkward/fillable/FillableOptions.h"
namespace ak = awkward;
int main(int, char**){
std::ifstream rf("/home/josh/dev/awkward-kaitai/dataReaderWriter/data/animal_raw", std::ifstream::out | std::ifstream::binary);
if(!rf){
std::cout << "Cannot open file!" << std::endl;
return 1;
}
ak::FillableArray animal(ak::FillableOptions(1024, 2.0));
while (rf.peek() != EOF){
// start record for i-th animal
animal.beginrecord();
// get length of species name
char species_len;
rf.read(&species_len,1);
assert(!rf.eof());
// get species name
char name[(int)species_len];
rf.read(&name[0], (int)species_len);
assert(!rf.eof());
animal.field_check("Name");
animal.string(name);
// get age
char age_char;
rf.read(&age_char,1);
assert(!rf.eof());
animal.field_check("Age");
animal.integer((int)age_char);
// get weight
char weight_char[2];
rf.read(&weight_char[0],2);
assert(!rf.eof());
animal.field_check("Weight");
animal.integer((int) weight_char[0]+(100*weight_char[1]));
// end record for i-th animal
animal.endrecord();
}
// snapshot the FillableArray
std::shared_ptr<ak::Content> array = animal.snapshot();
std::cout << array.get()-> tojson(false,1);
return 0;
}
////// Awkward stuff for later //////
// create fillable array
// ak::FillableArray myarray(ak::FillableOptions(1024, 2.0));
//
// // take a snapshot
// std::shared_ptr<ak::Content> array = myarray.snapshot();
//
// // check output
// if (array.get()->tojson(false,1) != "[{\"one\":true,\"two\":1,\"three\":1.1},{\"one\":false,\"two\":2,\"three\":2.2},{\"one\":true,\"two\":3,\"three\":3.3}]")
// {return -1;}
// return 0;