recordio.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2008, Yahoo! 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 __RECORDIO_H__
  17. #define __RECORDIO_H__
  18. #include <sys/types.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. struct buffer {
  23. int32_t len;
  24. char *buff;
  25. };
  26. void deallocate_String(char **s);
  27. void deallocate_Buffer(struct buffer *b);
  28. void deallocate_vector(void *d);
  29. struct iarchive {
  30. int (*start_record)(struct iarchive *ia, const char *tag);
  31. int (*end_record)(struct iarchive *ia, const char *tag);
  32. int (*start_vector)(struct iarchive *ia, const char *tag, int32_t *count);
  33. int (*end_vector)(struct iarchive *ia, const char *tag);
  34. int (*deserialize_Bool)(struct iarchive *ia, const char *name, int32_t *);
  35. int (*deserialize_Int)(struct iarchive *ia, const char *name, int32_t *);
  36. int (*deserialize_Long)(struct iarchive *ia, const char *name, int64_t *);
  37. int (*deserialize_Buffer)(struct iarchive *ia, const char *name,
  38. struct buffer *);
  39. int (*deserialize_String)(struct iarchive *ia, const char *name, char **);
  40. void *priv;
  41. };
  42. struct oarchive {
  43. int (*start_record)(struct oarchive *oa, const char *tag);
  44. int (*end_record)(struct oarchive *oa, const char *tag);
  45. int (*start_vector)(struct oarchive *oa, const char *tag, const int32_t *count);
  46. int (*end_vector)(struct oarchive *oa, const char *tag);
  47. int (*serialize_Bool)(struct oarchive *oa, const char *name, const int32_t *);
  48. int (*serialize_Int)(struct oarchive *oa, const char *name, const int32_t *);
  49. int (*serialize_Long)(struct oarchive *oa, const char *name,
  50. const int64_t *);
  51. int (*serialize_Buffer)(struct oarchive *oa, const char *name,
  52. const struct buffer *);
  53. int (*serialize_String)(struct oarchive *oa, const char *name, char **);
  54. void *priv;
  55. };
  56. struct oarchive *create_buffer_oarchive();
  57. void close_buffer_oarchive(struct oarchive **oa, int free_buffer);
  58. struct iarchive *create_buffer_iarchive(char *buffer, int len);
  59. void close_buffer_iarchive(struct iarchive **ia);
  60. char *get_buffer(struct oarchive *);
  61. int get_buffer_len(struct oarchive *);
  62. int64_t htonll(int64_t v);
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif