binarchive.hh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef BINARCHIVE_HH_
  19. #define BINARCHIVE_HH_
  20. #include "recordio.hh"
  21. namespace hadoop {
  22. class BinIndex : public Index {
  23. private:
  24. size_t size;
  25. public:
  26. BinIndex(size_t size_) { size = size_; }
  27. bool done() { return (size==0); }
  28. void incr() { size--; }
  29. ~BinIndex() {}
  30. };
  31. class IBinArchive : public IArchive {
  32. private:
  33. InStream& stream;
  34. public:
  35. IBinArchive(InStream& _stream) : stream(_stream) {}
  36. virtual void deserialize(int8_t& t, const char* tag);
  37. virtual void deserialize(bool& t, const char* tag);
  38. virtual void deserialize(int32_t& t, const char* tag);
  39. virtual void deserialize(int64_t& t, const char* tag);
  40. virtual void deserialize(float& t, const char* tag);
  41. virtual void deserialize(double& t, const char* tag);
  42. virtual void deserialize(std::string& t, const char* tag);
  43. virtual void deserialize(std::string& t, size_t& len, const char* tag);
  44. virtual void startRecord(Record& s, const char* tag);
  45. virtual void endRecord(Record& s, const char* tag);
  46. virtual Index* startVector(const char* tag);
  47. virtual void endVector(Index* idx, const char* tag);
  48. virtual Index* startMap(const char* tag);
  49. virtual void endMap(Index* idx, const char* tag);
  50. virtual ~IBinArchive();
  51. };
  52. class OBinArchive : public OArchive {
  53. private:
  54. OutStream& stream;
  55. public:
  56. OBinArchive(OutStream& _stream) : stream(_stream) {}
  57. virtual void serialize(int8_t t, const char* tag);
  58. virtual void serialize(bool t, const char* tag);
  59. virtual void serialize(int32_t t, const char* tag);
  60. virtual void serialize(int64_t t, const char* tag);
  61. virtual void serialize(float t, const char* tag);
  62. virtual void serialize(double t, const char* tag);
  63. virtual void serialize(const std::string& t, const char* tag);
  64. virtual void serialize(const std::string& t, size_t len, const char* tag);
  65. virtual void startRecord(const Record& s, const char* tag);
  66. virtual void endRecord(const Record& s, const char* tag);
  67. virtual void startVector(size_t len, const char* tag);
  68. virtual void endVector(size_t len, const char* tag);
  69. virtual void startMap(size_t len, const char* tag);
  70. virtual void endMap(size_t len, const char* tag);
  71. virtual ~OBinArchive();
  72. };
  73. }
  74. #endif /*BINARCHIVE_HH_*/