object.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * MessagePack for C dynamic typing routine
  3. *
  4. * Copyright (C) 2008-2009 FURUHASHI Sadayuki
  5. *
  6. * Distributed under the Boost Software License, Version 1.0.
  7. * (See accompanying file LICENSE_1_0.txt or copy at
  8. * http://www.boost.org/LICENSE_1_0.txt)
  9. */
  10. #ifndef MSGPACK_OBJECT_H
  11. #define MSGPACK_OBJECT_H
  12. #include "zone.h"
  13. #include <stdio.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /**
  18. * @defgroup msgpack_object Dynamically typed object
  19. * @ingroup msgpack
  20. * @{
  21. */
  22. typedef enum {
  23. MSGPACK_OBJECT_NIL = 0x00,
  24. MSGPACK_OBJECT_BOOLEAN = 0x01,
  25. MSGPACK_OBJECT_POSITIVE_INTEGER = 0x02,
  26. MSGPACK_OBJECT_NEGATIVE_INTEGER = 0x03,
  27. MSGPACK_OBJECT_FLOAT32 = 0x0a,
  28. MSGPACK_OBJECT_FLOAT64 = 0x04,
  29. MSGPACK_OBJECT_FLOAT = 0x04,
  30. #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
  31. MSGPACK_OBJECT_DOUBLE = MSGPACK_OBJECT_FLOAT, /* obsolete */
  32. #endif /* MSGPACK_USE_LEGACY_NAME_AS_FLOAT */
  33. MSGPACK_OBJECT_STR = 0x05,
  34. MSGPACK_OBJECT_ARRAY = 0x06,
  35. MSGPACK_OBJECT_MAP = 0x07,
  36. MSGPACK_OBJECT_BIN = 0x08,
  37. MSGPACK_OBJECT_EXT = 0x09
  38. } msgpack_object_type;
  39. struct msgpack_object;
  40. struct msgpack_object_kv;
  41. typedef struct {
  42. uint32_t size;
  43. struct msgpack_object* ptr;
  44. } msgpack_object_array;
  45. typedef struct {
  46. uint32_t size;
  47. struct msgpack_object_kv* ptr;
  48. } msgpack_object_map;
  49. typedef struct {
  50. uint32_t size;
  51. const char* ptr;
  52. } msgpack_object_str;
  53. typedef struct {
  54. uint32_t size;
  55. const char* ptr;
  56. } msgpack_object_bin;
  57. typedef struct {
  58. int8_t type;
  59. uint32_t size;
  60. const char* ptr;
  61. } msgpack_object_ext;
  62. typedef union {
  63. bool boolean;
  64. uint64_t u64;
  65. int64_t i64;
  66. #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
  67. double dec; /* obsolete*/
  68. #endif /* MSGPACK_USE_LEGACY_NAME_AS_FLOAT */
  69. double f64;
  70. msgpack_object_array array;
  71. msgpack_object_map map;
  72. msgpack_object_str str;
  73. msgpack_object_bin bin;
  74. msgpack_object_ext ext;
  75. } msgpack_object_union;
  76. typedef struct msgpack_object {
  77. msgpack_object_type type;
  78. msgpack_object_union via;
  79. } msgpack_object;
  80. typedef struct msgpack_object_kv {
  81. msgpack_object key;
  82. msgpack_object val;
  83. } msgpack_object_kv;
  84. MSGPACK_DLLEXPORT
  85. void msgpack_object_print(FILE* out, msgpack_object o);
  86. MSGPACK_DLLEXPORT
  87. int msgpack_object_print_buffer(char *buffer, size_t buffer_size, msgpack_object o);
  88. MSGPACK_DLLEXPORT
  89. bool msgpack_object_equal(const msgpack_object x, const msgpack_object y);
  90. /** @} */
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. #endif /* msgpack/object.h */