1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* vim: set ts=8 sts=4 et sw=4 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* 8 * Basic APIs for streaming typelib structures from disk. 9 */ 10 11 #ifndef __xpt_xdr_h__ 12 #define __xpt_xdr_h__ 13 14 #include "xpt_struct.h" 15 #include "mozilla/NotNull.h" 16 17 using mozilla::NotNull; 18 19 struct XPTArena; 20 struct XPTCursor; 21 struct XPTState; 22 23 bool XPT_SkipStringInline(NotNull<XPTCursor *> cursor); 24 25 bool XPT_DoCString(XPTArena *arena, NotNull<XPTCursor *> cursor, 26 const char **strp, bool ignore = false); 27 28 bool XPT_DoIID(NotNull<XPTCursor *> cursor, nsID *iidp); 29 30 bool XPT_Do64(NotNull<XPTCursor *> cursor, int64_t *u64p); 31 32 bool XPT_Do32(NotNull<XPTCursor *> cursor, uint32_t *u32p); 33 34 bool XPT_Do16(NotNull<XPTCursor *> cursor, uint16_t *u16p); 35 36 bool XPT_Do8(NotNull<XPTCursor *> cursor, uint8_t *u8p); 37 38 bool XPT_DoHeader(XPTArena *arena, NotNull<XPTCursor *> cursor, 39 XPTHeader **headerp); 40 41 enum XPTPool { XPT_HEADER = 0, XPT_DATA = 1 }; 42 43 struct XPTState { 44 uint32_t data_offset; 45 uint32_t next_cursor[2]; 46 char *pool_data; 47 uint32_t pool_allocated; 48 }; 49 50 struct XPTCursor { 51 XPTState *state; 52 XPTPool pool; 53 uint32_t offset; 54 uint8_t bits; 55 }; 56 57 void XPT_InitXDRState(XPTState *state, char *data, uint32_t len); 58 59 bool XPT_MakeCursor(XPTState *state, XPTPool pool, uint32_t len, 60 NotNull<XPTCursor *> cursor); 61 62 bool XPT_SeekTo(NotNull<XPTCursor *> cursor, uint32_t offset); 63 64 void XPT_SetDataOffset(XPTState *state, uint32_t data_offset); 65 66 #endif /* __xpt_xdr_h__ */ 67