hotback_task.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "hotback_task.h"
  17. #include "mem_check.h"
  18. #include <stdlib.h>
  19. #include <string.h>
  20. HotBackTask::HotBackTask()
  21. : m_Type(0), m_Flag(0), m_pPackedKey(NULL), m_PackedKeyLen(0),
  22. m_pValue(NULL), m_ValueLen(0)
  23. {
  24. }
  25. HotBackTask::~HotBackTask()
  26. {
  27. FREE_IF(m_pPackedKey);
  28. FREE_IF(m_pValue);
  29. }
  30. void HotBackTask::set_packed_key(char *pPackedKey, int keyLen)
  31. {
  32. if ((NULL == pPackedKey) || (0 == keyLen)) {
  33. return;
  34. }
  35. m_pPackedKey = (char *)MALLOC(keyLen);
  36. if (NULL == m_pPackedKey) {
  37. return;
  38. }
  39. m_PackedKeyLen = keyLen;
  40. memcpy(m_pPackedKey, pPackedKey, m_PackedKeyLen);
  41. }
  42. void HotBackTask::set_value(char *pValue, int valueLen)
  43. {
  44. if ((NULL == pValue) || (0 == valueLen)) {
  45. return;
  46. }
  47. m_pValue = (char *)MALLOC(valueLen);
  48. if (NULL == m_pPackedKey) {
  49. return;
  50. }
  51. m_ValueLen = valueLen;
  52. memcpy(m_pValue, pValue, m_ValueLen);
  53. }