decode.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifndef __CH_DECODE_H__
  17. #define __CH_DECODE_H__
  18. /*
  19. * Base Decode/encode routines:
  20. * p = encode...(p, ...); // encode object and advance pointer
  21. * EncodedBytes...(...); // calculate encoded object size
  22. * Decode...(...); // Decode objects
  23. */
  24. #include "value.h"
  25. #include "../table/../table/table_def.h"
  26. #include "section.h"
  27. #include "../field/field.h"
  28. #include "../field/field_api.h"
  29. #define __FLTFMT__ "%LA"
  30. static inline char *encode_data_type(char *p, uint8_t type)
  31. {
  32. *p++ = type == DField::Unsigned ? DField::Signed : type;
  33. return p;
  34. }
  35. extern int decode_length(DTCBinary &bin, uint32_t &len);
  36. extern char *encode_length(char *p, uint32_t len);
  37. extern int encoded_bytes_length(uint32_t n);
  38. extern int decode_data_value(DTCBinary &bin, DTCValue &val, int type);
  39. extern char *encode_data_value(char *p, const DTCValue *v, int type);
  40. extern int encoded_bytes_data_value(const DTCValue *v, int type);
  41. extern int decode_field_id(DTCBinary &, uint8_t &id,
  42. const DTCTableDefinition *tdef, int &needDefinition);
  43. extern int decode_simple_section(DTCBinary &, SimpleSection &, uint8_t);
  44. extern int decode_simple_section(char *, int, SimpleSection &, uint8_t);
  45. extern int encoded_bytes_simple_section(const SimpleSection &, uint8_t);
  46. extern char *encode_simple_section(char *p, const SimpleSection &, uint8_t);
  47. extern int encoded_bytes_field_set(const DTCFieldSet &);
  48. extern char *encode_field_set(char *p, const DTCFieldSet &);
  49. extern int encoded_bytes_field_value(const DTCFieldValue &);
  50. extern char *encode_field_value(char *, const DTCFieldValue &);
  51. extern int encoded_bytes_multi_key(const DTCValue *v,
  52. const DTCTableDefinition *tdef);
  53. extern char *encode_multi_key(char *, const DTCValue *v,
  54. const DTCTableDefinition *tdef);
  55. class FieldSetByName;
  56. extern int encoded_bytes_field_set(const FieldSetByName &);
  57. extern char *encode_field_set(char *p, const FieldSetByName &);
  58. extern int encoded_bytes_field_value(const FieldValueByName &);
  59. extern char *encode_field_value(char *, const FieldValueByName &);
  60. #endif