rtlread_imp.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef rtlread_imp_hpp
  14. #define rtlread_imp_hpp
  15. #include "eclhelper.hpp"
  16. #include "jfile.hpp"
  17. #include "eclrtl.hpp"
  18. //This file references jlib directly, so it should not be #included from generated code
  19. //It is shared with the implementation of eclrtl and the engines.
  20. //This class is designed to be used as the source parameter when deserializing data.
  21. class ECLRTL_API CThorStreamDeserializerSource : implements IRowDeserializerSource
  22. {
  23. public:
  24. CThorStreamDeserializerSource(ISerialStream * _in = NULL);
  25. CThorStreamDeserializerSource(size32_t len, const void * data); // a short cut for creating a createMemorySerialStream()
  26. inline void setStream(ISerialStream *_in) { in.set(_in); }
  27. virtual const byte * peek(size32_t maxSize);
  28. virtual offset_t beginNested();
  29. virtual bool finishedNested(offset_t & len);
  30. virtual size32_t read(size32_t len, void * ptr);
  31. virtual size32_t readSize();
  32. virtual size32_t readPackedInt(void * ptr);
  33. virtual size32_t readUtf8(ARowBuilder & target, size32_t offset, size32_t fixedSize, size32_t len);
  34. virtual size32_t readVStr(ARowBuilder & target, size32_t offset, size32_t fixedSize);
  35. virtual size32_t readVUni(ARowBuilder & target, size32_t offset, size32_t fixedSize);
  36. //These shouldn't really be called since this class is meant to be used for a deserialize.
  37. //If we allowed padding/alignment fields in the input then the first function would make sense.
  38. virtual void skip(size32_t size);
  39. virtual void skipPackedInt();
  40. virtual void skipUtf8(size32_t len);
  41. virtual void skipVStr();
  42. virtual void skipVUni();
  43. inline bool eos()
  44. {
  45. return in->eos();
  46. }
  47. inline offset_t tell()
  48. {
  49. return in->tell();
  50. }
  51. inline void clearStream()
  52. {
  53. in.clear();
  54. }
  55. inline void reset(offset_t offset, offset_t flen = (offset_t)-1)
  56. {
  57. in->reset(offset, flen);
  58. }
  59. private:
  60. inline const byte * doPeek(size32_t minSize, size32_t & available)
  61. {
  62. const byte * ret = static_cast<const byte *>(in->peek(minSize, available));
  63. if (minSize > available)
  64. reportReadFail();
  65. return ret;
  66. }
  67. inline void doRead(size32_t len, void * ptr)
  68. {
  69. in->get(len, ptr);
  70. // if (read != len)
  71. // reportReadFail();
  72. }
  73. virtual void reportReadFail();
  74. protected:
  75. Linked<ISerialStream> in; // could use a CStreamSerializer class (with inlines to improve)
  76. };
  77. #endif