CodedInputData.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Tencent is pleased to support the open source community by making
  3. * MMKV available.
  4. *
  5. * Copyright (C) 2018 THL A29 Limited, a Tencent company.
  6. * All rights reserved.
  7. *
  8. * Licensed under the BSD 3-Clause License (the "License"); you may not use
  9. * this file except in compliance with the License. You may obtain a copy of
  10. * the License at
  11. *
  12. * https://opensource.org/licenses/BSD-3-Clause
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. #ifndef MMKV_CODEDINPUTDATA_H
  21. #define MMKV_CODEDINPUTDATA_H
  22. #ifdef __cplusplus
  23. #include "MMKVPredef.h"
  24. #include "KeyValueHolder.h"
  25. #include "MMBuffer.h"
  26. #include <cstdint>
  27. namespace mmkv {
  28. class CodedInputData {
  29. uint8_t *const m_ptr;
  30. size_t m_size;
  31. size_t m_position;
  32. int8_t readRawByte();
  33. int32_t readRawVarint32();
  34. int32_t readRawLittleEndian32();
  35. int64_t readRawLittleEndian64();
  36. public:
  37. CodedInputData(const void *oData, size_t length);
  38. bool isAtEnd() const { return m_position == m_size; };
  39. void seek(size_t addedSize);
  40. bool readBool();
  41. double readDouble();
  42. float readFloat();
  43. int64_t readInt64();
  44. uint64_t readUInt64();
  45. int32_t readInt32();
  46. uint32_t readUInt32();
  47. MMBuffer readData();
  48. void readData(KeyValueHolder &kvHolder);
  49. #ifndef MMKV_APPLE
  50. std::string readString();
  51. std::string readString(KeyValueHolder &kvHolder);
  52. #else
  53. NSString *readString();
  54. NSString *readString(KeyValueHolder &kvHolder);
  55. NSData *readNSData();
  56. #endif
  57. };
  58. } // namespace mmkv
  59. #endif
  60. #endif //MMKV_CODEDINPUTDATA_H