Annotation of sbbs/javascript/include/mozilla/js/jsxdrapi.h, revision 1.1.1.1

1.1       root        1: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
                      2:  *
                      3:  * The contents of this file are subject to the Netscape Public
                      4:  * License Version 1.1 (the "License"); you may not use this file
                      5:  * except in compliance with the License. You may obtain a copy of
                      6:  * the License at http://www.mozilla.org/NPL/
                      7:  *
                      8:  * Software distributed under the License is distributed on an "AS
                      9:  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
                     10:  * implied. See the License for the specific language governing
                     11:  * rights and limitations under the License.
                     12:  *
                     13:  * The Original Code is Mozilla Communicator client code, released
                     14:  * March 31, 1998.
                     15:  *
                     16:  * The Initial Developer of the Original Code is Netscape
                     17:  * Communications Corporation.  Portions created by Netscape are
                     18:  * Copyright (C) 1998 Netscape Communications Corporation. All
                     19:  * Rights Reserved.
                     20:  *
                     21:  * Contributor(s): 
                     22:  *
                     23:  * Alternatively, the contents of this file may be used under the
                     24:  * terms of the GNU Public License (the "GPL"), in which case the
                     25:  * provisions of the GPL are applicable instead of those above.
                     26:  * If you wish to allow use of your version of this file only
                     27:  * under the terms of the GPL and not to allow others to use your
                     28:  * version of this file under the NPL, indicate your decision by
                     29:  * deleting the provisions above and replace them with the notice
                     30:  * and other provisions required by the GPL.  If you do not delete
                     31:  * the provisions above, a recipient may use your version of this
                     32:  * file under either the NPL or the GPL.
                     33:  */
                     34: 
                     35: #ifndef jsxdrapi_h___
                     36: #define jsxdrapi_h___
                     37: 
                     38: /*
                     39:  * JS external data representation interface API.
                     40:  *
                     41:  * The XDR system is comprised of three major parts:
                     42:  *
                     43:  * - the state serialization/deserialization APIs, which allow consumers
                     44:  *   of the API to serialize JS runtime state (script bytecodes, atom maps,
                     45:  *   object graphs, etc.) for later restoration.  These portions
                     46:  *   are implemented in various appropriate files, such as jsscript.c
                     47:  *   for the script portions and jsobj.c for object state.
                     48:  * - the callback APIs through which the runtime requests an opaque
                     49:  *   representation of a native object, and through which the runtime
                     50:  *   constructs a live native object from an opaque representation. These
                     51:  *   portions are the responsibility of the native object implementor.
                     52:  * - utility functions for en/decoding of primitive types, such as
                     53:  *   JSStrings.  This portion is implemented in jsxdrapi.c.
                     54:  *
                     55:  * Spiritually guided by Sun's XDR, where appropriate.
                     56:  */
                     57: 
                     58: #include "jspubtd.h"
                     59: #include "jsprvtd.h"
                     60: 
                     61: JS_BEGIN_EXTERN_C
                     62: 
                     63: /* We use little-endian byteorder for all encoded data */
                     64: 
                     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: 
                     78: #define JSXDR_ALIGN     4
                     79: 
                     80: typedef enum JSXDRMode {
                     81:     JSXDR_ENCODE,
                     82:     JSXDR_DECODE,
                     83:     JSXDR_FREE
                     84: } JSXDRMode;
                     85: 
                     86: typedef enum JSXDRWhence {
                     87:     JSXDR_SEEK_SET,
                     88:     JSXDR_SEEK_CUR,
                     89:     JSXDR_SEEK_END
                     90: } JSXDRWhence;
                     91: 
                     92: typedef struct JSXDROps {
                     93:     JSBool      (*get32)(JSXDRState *, uint32 *);
                     94:     JSBool      (*set32)(JSXDRState *, uint32 *);
                     95:     JSBool      (*getbytes)(JSXDRState *, char *, uint32);
                     96:     JSBool      (*setbytes)(JSXDRState *, char *, uint32);
                     97:     void *      (*raw)(JSXDRState *, uint32);
                     98:     JSBool      (*seek)(JSXDRState *, int32, JSXDRWhence);
                     99:     uint32      (*tell)(JSXDRState *);
                    100:     void        (*finalize)(JSXDRState *);
                    101: } JSXDROps;
                    102: 
                    103: struct JSXDRState {
                    104:     JSXDRMode   mode;
                    105:     JSXDROps    *ops;
                    106:     JSContext   *cx;
                    107:     JSClass     **registry;
                    108:     uintN       numclasses;
                    109:     uintN       maxclasses;
                    110:     void        *reghash;
                    111:     void        *userdata;
                    112: };
                    113: 
                    114: extern JS_PUBLIC_API(void)
                    115: JS_XDRInitBase(JSXDRState *xdr, JSXDRMode mode, JSContext *cx);
                    116: 
                    117: extern JS_PUBLIC_API(JSXDRState *)
                    118: JS_XDRNewMem(JSContext *cx, JSXDRMode mode);
                    119: 
                    120: extern JS_PUBLIC_API(void *)
                    121: JS_XDRMemGetData(JSXDRState *xdr, uint32 *lp);
                    122: 
                    123: extern JS_PUBLIC_API(void)
                    124: JS_XDRMemSetData(JSXDRState *xdr, void *data, uint32 len);
                    125: 
                    126: extern JS_PUBLIC_API(uint32)
                    127: JS_XDRMemDataLeft(JSXDRState *xdr);
                    128: 
                    129: extern JS_PUBLIC_API(void)
                    130: JS_XDRMemResetData(JSXDRState *xdr);
                    131: 
                    132: extern JS_PUBLIC_API(void)
                    133: JS_XDRDestroy(JSXDRState *xdr);
                    134: 
                    135: extern JS_PUBLIC_API(JSBool)
                    136: JS_XDRUint8(JSXDRState *xdr, uint8 *b);
                    137: 
                    138: extern JS_PUBLIC_API(JSBool)
                    139: JS_XDRUint16(JSXDRState *xdr, uint16 *s);
                    140: 
                    141: extern JS_PUBLIC_API(JSBool)
                    142: JS_XDRUint32(JSXDRState *xdr, uint32 *lp);
                    143: 
                    144: extern JS_PUBLIC_API(JSBool)
                    145: JS_XDRBytes(JSXDRState *xdr, char *bytes, uint32 len);
                    146: 
                    147: extern JS_PUBLIC_API(JSBool)
                    148: JS_XDRCString(JSXDRState *xdr, char **sp);
                    149: 
                    150: extern JS_PUBLIC_API(JSBool)
                    151: JS_XDRCStringOrNull(JSXDRState *xdr, char **sp);
                    152: 
                    153: extern JS_PUBLIC_API(JSBool)
                    154: JS_XDRString(JSXDRState *xdr, JSString **strp);
                    155: 
                    156: extern JS_PUBLIC_API(JSBool)
                    157: JS_XDRStringOrNull(JSXDRState *xdr, JSString **strp);
                    158: 
                    159: extern JS_PUBLIC_API(JSBool)
                    160: JS_XDRDouble(JSXDRState *xdr, jsdouble **dp);
                    161: 
                    162: extern JS_PUBLIC_API(JSBool)
                    163: JS_XDRValue(JSXDRState *xdr, jsval *vp);
                    164: 
                    165: extern JS_PUBLIC_API(JSBool)
                    166: JS_XDRScript(JSXDRState *xdr, JSScript **scriptp);
                    167: 
                    168: extern JS_PUBLIC_API(JSBool)
                    169: JS_XDRRegisterClass(JSXDRState *xdr, JSClass *clasp, uint32 *lp);
                    170: 
                    171: extern JS_PUBLIC_API(uint32)
                    172: JS_XDRFindClassIdByName(JSXDRState *xdr, const char *name);
                    173: 
                    174: extern JS_PUBLIC_API(JSClass *)
                    175: JS_XDRFindClassById(JSXDRState *xdr, uint32 id);
                    176: 
                    177: /*
                    178:  * Magic numbers.
                    179:  */
                    180: #define JSXDR_MAGIC_SCRIPT_1        0xdead0001
                    181: #define JSXDR_MAGIC_SCRIPT_2        0xdead0002
                    182: #define JSXDR_MAGIC_SCRIPT_3        0xdead0003
                    183: #define JSXDR_MAGIC_SCRIPT_4        0xdead0004
                    184: #define JSXDR_MAGIC_SCRIPT_CURRENT  JSXDR_MAGIC_SCRIPT_4
                    185: 
                    186: JS_END_EXTERN_C
                    187: 
                    188: #endif /* ! jsxdrapi_h___ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.