CodedOutputData.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 reset();
  37. size_t getPosition();
  38. void setPosition(size_t position);
  39. void writeRawByte(uint8_t value);
  40. void writeRawLittleEndian32(int32_t value);
  41. void writeRawLittleEndian64(int64_t value);
  42. void writeRawVarint32(int32_t value);
  43. void writeRawVarint64(int64_t value);
  44. void writeRawData(const MMBuffer &data);
  45. void writeDouble(double value);
  46. void writeFloat(float value);
  47. void writeInt64(int64_t value);
  48. void writeUInt64(uint64_t value);
  49. void writeInt32(int32_t value);
  50. void writeUInt32(uint32_t value);
  51. void writeBool(bool value);
  52. void writeData(const MMBuffer &value);
  53. void writeString(const std::string &value);
  54. };
  55. } // namespace mmkv
  56. #endif
  57. #endif //MMKV_CODEDOUTPUTDATA_H