PageRenderTime 28ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/jsxdrapi.h

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 220 lines | 108 code | 38 blank | 74 comment | 0 complexity | 93ff2c657204a9df707589e2e55b6fac MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. * vim: set ts=8 sw=4 et tw=78:
  3. *
  4. * ***** BEGIN LICENSE BLOCK *****
  5. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is Mozilla Communicator client code, released
  18. * March 31, 1998.
  19. *
  20. * The Initial Developer of the Original Code is
  21. * Netscape Communications Corporation.
  22. * Portions created by the Initial Developer are Copyright (C) 1998
  23. * the Initial Developer. All Rights Reserved.
  24. *
  25. * Contributor(s):
  26. *
  27. * Alternatively, the contents of this file may be used under the terms of
  28. * either of the GNU General Public License Version 2 or later (the "GPL"),
  29. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30. * in which case the provisions of the GPL or the LGPL are applicable instead
  31. * of those above. If you wish to allow use of your version of this file only
  32. * under the terms of either the GPL or the LGPL, and not to allow others to
  33. * use your version of this file under the terms of the MPL, indicate your
  34. * decision by deleting the provisions above and replace them with the notice
  35. * and other provisions required by the GPL or the LGPL. If you do not delete
  36. * the provisions above, a recipient may use your version of this file under
  37. * the terms of any one of the MPL, the GPL or the LGPL.
  38. *
  39. * ***** END LICENSE BLOCK ***** */
  40. #ifndef jsxdrapi_h___
  41. #define jsxdrapi_h___
  42. /*
  43. * JS external data representation interface API.
  44. *
  45. * The XDR system is comprised of three major parts:
  46. *
  47. * - the state serialization/deserialization APIs, which allow consumers
  48. * of the API to serialize JS runtime state (script bytecodes, atom maps,
  49. * object graphs, etc.) for later restoration. These portions
  50. * are implemented in various appropriate files, such as jsscript.c
  51. * for the script portions and jsobj.c for object state.
  52. * - the callback APIs through which the runtime requests an opaque
  53. * representation of a native object, and through which the runtime
  54. * constructs a live native object from an opaque representation. These
  55. * portions are the responsibility of the native object implementor.
  56. * - utility functions for en/decoding of primitive types, such as
  57. * JSStrings. This portion is implemented in jsxdrapi.c.
  58. *
  59. * Spiritually guided by Sun's XDR, where appropriate.
  60. */
  61. #include "jspubtd.h"
  62. #include "jsprvtd.h"
  63. JS_BEGIN_EXTERN_C
  64. /* We use little-endian byteorder for all encoded data */
  65. #if defined IS_LITTLE_ENDIAN
  66. #define JSXDR_SWAB32(x) x
  67. #define JSXDR_SWAB16(x) x
  68. #elif defined IS_BIG_ENDIAN
  69. #define JSXDR_SWAB32(x) (((uint32)(x) >> 24) | \
  70. (((uint32)(x) >> 8) & 0xff00) | \
  71. (((uint32)(x) << 8) & 0xff0000) | \
  72. ((uint32)(x) << 24))
  73. #define JSXDR_SWAB16(x) (((uint16)(x) >> 8) | ((uint16)(x) << 8))
  74. #else
  75. #error "unknown byte order"
  76. #endif
  77. #define JSXDR_ALIGN 4
  78. typedef enum JSXDRMode {
  79. JSXDR_ENCODE,
  80. JSXDR_DECODE,
  81. JSXDR_FREE
  82. } JSXDRMode;
  83. typedef enum JSXDRWhence {
  84. JSXDR_SEEK_SET,
  85. JSXDR_SEEK_CUR,
  86. JSXDR_SEEK_END
  87. } JSXDRWhence;
  88. typedef struct JSXDROps {
  89. JSBool (*get32)(JSXDRState *, uint32 *);
  90. JSBool (*set32)(JSXDRState *, uint32 *);
  91. JSBool (*getbytes)(JSXDRState *, char *, uint32);
  92. JSBool (*setbytes)(JSXDRState *, char *, uint32);
  93. void * (*raw)(JSXDRState *, uint32);
  94. JSBool (*seek)(JSXDRState *, int32, JSXDRWhence);
  95. uint32 (*tell)(JSXDRState *);
  96. void (*finalize)(JSXDRState *);
  97. } JSXDROps;
  98. struct JSXDRState {
  99. JSXDRMode mode;
  100. JSXDROps *ops;
  101. JSContext *cx;
  102. JSClass **registry;
  103. uintN numclasses;
  104. uintN maxclasses;
  105. void *reghash;
  106. void *userdata;
  107. JSScript *script;
  108. };
  109. extern JS_PUBLIC_API(void)
  110. JS_XDRInitBase(JSXDRState *xdr, JSXDRMode mode, JSContext *cx);
  111. extern JS_PUBLIC_API(JSXDRState *)
  112. JS_XDRNewMem(JSContext *cx, JSXDRMode mode);
  113. extern JS_PUBLIC_API(void *)
  114. JS_XDRMemGetData(JSXDRState *xdr, uint32 *lp);
  115. extern JS_PUBLIC_API(void)
  116. JS_XDRMemSetData(JSXDRState *xdr, void *data, uint32 len);
  117. extern JS_PUBLIC_API(uint32)
  118. JS_XDRMemDataLeft(JSXDRState *xdr);
  119. extern JS_PUBLIC_API(void)
  120. JS_XDRMemResetData(JSXDRState *xdr);
  121. extern JS_PUBLIC_API(void)
  122. JS_XDRDestroy(JSXDRState *xdr);
  123. extern JS_PUBLIC_API(JSBool)
  124. JS_XDRUint8(JSXDRState *xdr, uint8 *b);
  125. extern JS_PUBLIC_API(JSBool)
  126. JS_XDRUint16(JSXDRState *xdr, uint16 *s);
  127. extern JS_PUBLIC_API(JSBool)
  128. JS_XDRUint32(JSXDRState *xdr, uint32 *lp);
  129. extern JS_PUBLIC_API(JSBool)
  130. JS_XDRBytes(JSXDRState *xdr, char *bytes, uint32 len);
  131. extern JS_PUBLIC_API(JSBool)
  132. JS_XDRCString(JSXDRState *xdr, char **sp);
  133. extern JS_PUBLIC_API(JSBool)
  134. JS_XDRCStringOrNull(JSXDRState *xdr, char **sp);
  135. extern JS_PUBLIC_API(JSBool)
  136. JS_XDRString(JSXDRState *xdr, JSString **strp);
  137. extern JS_PUBLIC_API(JSBool)
  138. JS_XDRStringOrNull(JSXDRState *xdr, JSString **strp);
  139. extern JS_PUBLIC_API(JSBool)
  140. JS_XDRDouble(JSXDRState *xdr, jsdouble **dp);
  141. extern JS_PUBLIC_API(JSBool)
  142. JS_XDRValue(JSXDRState *xdr, jsval *vp);
  143. extern JS_PUBLIC_API(JSBool)
  144. JS_XDRScript(JSXDRState *xdr, JSScript **scriptp);
  145. extern JS_PUBLIC_API(JSBool)
  146. JS_XDRRegisterClass(JSXDRState *xdr, JSClass *clasp, uint32 *lp);
  147. extern JS_PUBLIC_API(uint32)
  148. JS_XDRFindClassIdByName(JSXDRState *xdr, const char *name);
  149. extern JS_PUBLIC_API(JSClass *)
  150. JS_XDRFindClassById(JSXDRState *xdr, uint32 id);
  151. /*
  152. * Magic numbers.
  153. */
  154. #define JSXDR_MAGIC_SCRIPT_1 0xdead0001
  155. #define JSXDR_MAGIC_SCRIPT_2 0xdead0002
  156. #define JSXDR_MAGIC_SCRIPT_3 0xdead0003
  157. #define JSXDR_MAGIC_SCRIPT_4 0xdead0004
  158. #define JSXDR_MAGIC_SCRIPT_5 0xdead0005
  159. #define JSXDR_MAGIC_SCRIPT_6 0xdead0006
  160. #define JSXDR_MAGIC_SCRIPT_7 0xdead0007
  161. #define JSXDR_MAGIC_SCRIPT_8 0xdead0008
  162. #define JSXDR_MAGIC_SCRIPT_9 0xdead0009
  163. #define JSXDR_MAGIC_SCRIPT_CURRENT JSXDR_MAGIC_SCRIPT_9
  164. /*
  165. * Bytecode version number. Increment the subtrahend whenever JS bytecode
  166. * changes incompatibly.
  167. *
  168. * This version number should be XDR'ed once near the front of any file or
  169. * larger storage unit containing XDR'ed bytecode and other data, and checked
  170. * before deserialization of bytecode. If the saved version does not match
  171. * the current version, abort deserialization and invalidate the file.
  172. */
  173. #define JSXDR_BYTECODE_VERSION (0xb973c0de - 37)
  174. /*
  175. * Library-private functions.
  176. */
  177. extern JSBool
  178. js_XDRAtom(JSXDRState *xdr, JSAtom **atomp);
  179. extern JSBool
  180. js_XDRStringAtom(JSXDRState *xdr, JSAtom **atomp);
  181. JS_END_EXTERN_C
  182. #endif /* ! jsxdrapi_h___ */