CodedOutputData.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_CODEDOUTPUTDATA_H
  21. #define MMKV_CODEDOUTPUTDATA_H
  22. #ifdef __cplusplus
  23. #include "MMKVPredef.h"
  24. #include "MMBuffer.h"
  25. #include <cstdint>
  26. namespace mmkv {
  27. class CodedOutputData {
  28. uint8_t *const m_ptr;
  29. size_t m_size;
  30. size_t m_position;
  31. public:
  32. CodedOutputData(void *ptr, size_t len);
  33. size_t spaceLeft();
  34. uint8_t *curWritePointer();
  35. void seek(size_t addedSize);
  36. void writeRawByte(uint8_t value);
  37. void writeRawLittleEndian32(int32_t value);
  38. void writeRawLittleEndian64(int64_t value);
  39. void writeRawVarint32(int32_t value);
  40. void writeRawVarint64(int64_t value);
  41. void writeRawData(const MMBuffer &data);
  42. void writeDouble(double value);
  43. void writeFloat(float value);
  44. void writeInt64(int64_t value);
  45. void writeUInt64(uint64_t value);
  46. void writeInt32(int32_t value);
  47. void writeUInt32(uint32_t value);
  48. void writeBool(bool value);
  49. void writeData(const MMBuffer &value);
  50. #ifndef MMKV_APPLE
  51. void writeString(const std::string &value);
  52. #endif
  53. };
  54. } // namespace mmkv
  55. #endif
  56. #endif //MMKV_CODEDOUTPUTDATA_H