source: proiecte/HadoopJUnit/hadoop-0.20.1/src/c++/librecordio/utils.cc @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "utils.hh"
20#include "recordTypeInfo.hh"
21
22using namespace hadoop;
23
24void Utils::skip(IArchive& a, const char* tag, const TypeID& typeID)
25{
26  bool b;
27  size_t len=0;
28  ::std::string str;
29  int8_t bt;
30  double d;
31  float f;
32  int32_t i;
33  int64_t l;
34
35  switch(typeID.getTypeVal()) {
36  case RIOTYPE_BOOL: 
37    a.deserialize(b, tag);
38    break;
39  case RIOTYPE_BUFFER: 
40    a.deserialize(str, len, tag);
41    break;
42  case RIOTYPE_BYTE: 
43    a.deserialize(bt, tag);
44    break;
45  case RIOTYPE_DOUBLE: 
46    a.deserialize(d, tag);
47    break;
48  case RIOTYPE_FLOAT: 
49    a.deserialize(f, tag);
50    break;
51  case RIOTYPE_INT: 
52    a.deserialize(i, tag);
53    break;
54  case RIOTYPE_LONG: 
55    a.deserialize(l, tag);
56    break;
57  case RIOTYPE_MAP:
58    {
59      // since we don't know the key, value types,
60      // we need to deserialize in a generic manner
61      Index* idx = a.startMap(tag);
62      MapTypeID& mtID = (MapTypeID&) typeID;
63      while (!idx->done()) {
64        skip(a, tag, *(mtID.getKeyTypeID()));
65        skip(a, tag, *(mtID.getValueTypeID()));
66        idx->incr();
67      }
68      a.endMap(idx, tag);
69    }
70    break;
71  case RIOTYPE_STRING: 
72    a.deserialize(str, tag);
73    break;
74  case RIOTYPE_STRUCT: 
75    {
76      // since we don't know the key, value types,
77      // we need to deserialize in a generic manner
78      // we need to pass a record in, though it's never used
79      RecordTypeInfo rec;
80      a.startRecord(rec, tag);
81      StructTypeID& stID = (StructTypeID&) typeID;
82      std::vector<FieldTypeInfo*>& typeInfos = stID.getFieldTypeInfos();
83      for (unsigned int i=0; i<typeInfos.size(); i++) {
84        skip(a, tag, *(typeInfos[i]->getTypeID()));
85      }
86      a.endRecord(rec, tag);
87    }
88    break;
89  case RIOTYPE_VECTOR:
90    {
91      // since we don't know the key, value types,
92      // we need to deserialize in a generic manner
93      Index* idx = a.startVector(tag);
94      VectorTypeID& vtID = (VectorTypeID&) typeID;
95      while (!idx->done()) {
96        skip(a, tag, *(vtID.getElementTypeID()));
97        idx->incr();
98      }
99      a.endVector(idx, tag);
100    }
101    break;
102  default: 
103    // shouldn't be here
104    throw new IOException("Unknown typeID when skipping bytes");
105    break;
106  };
107
108}
109
Note: See TracBrowser for help on using the repository browser.