PRBool XDR(XPTArena *arena, XPTCursor *cursor, struct TestData *str) { TRY("Do32", XPT_Do32(cursor, &str->bit32)); TRY("Do16", XPT_Do16(cursor, &str->bit16)); TRY("Do8", XPT_Do8 (cursor, &str->bit8[0])); TRY("Do8", XPT_Do8 (cursor, &str->bit8[1])); TRY("DoCString", XPT_DoCString(arena, cursor, &str->cstr)); TRY("DoString", XPT_DoString(arena, cursor, &str->str)); return 0; }
XPT_DoIID(XPTCursor *cursor, nsID *iidp) { int i; if (!XPT_Do32(cursor, &iidp->m0) || !XPT_Do16(cursor, &iidp->m1) || !XPT_Do16(cursor, &iidp->m2)) return PR_FALSE; for (i = 0; i < 8; i++) if (!XPT_Do8(cursor, (uint8_t *)&iidp->m3[i])) return PR_FALSE; return PR_TRUE; }
XPT_DoIID(NotNull<XPTCursor*> cursor, nsID *iidp) { int i; if (!XPT_Do32(cursor, &iidp->m0) || !XPT_Do16(cursor, &iidp->m1) || !XPT_Do16(cursor, &iidp->m2)) return false; for (i = 0; i < 8; i++) if (!XPT_Do8(cursor, (uint8_t *)&iidp->m3[i])) return false; return true; }
XPT_DoCString(XPTArena *arena, NotNull<XPTCursor*> cursor, char **identp, bool ignore) { uint32_t offset = 0; if (!XPT_Do32(cursor, &offset)) return false; if (!offset) { *identp = NULL; return true; } XPTCursor my_cursor; my_cursor.pool = XPT_DATA; my_cursor.offset = offset; my_cursor.state = cursor->state; char* start = &CURS_POINT(&my_cursor); char* end = strchr(start, 0); /* find the end of the string */ if (!end) { fprintf(stderr, "didn't find end of string on decode!\n"); return false; } int len = end - start; XPT_ASSERT(len > 0); if (!ignore) { char *ident = (char*)XPT_CALLOC1(arena, len + 1u); if (!ident) return false; memcpy(ident, start, (size_t)len); ident[len] = 0; *identp = ident; } return true; }
XPT_Do64(XPTCursor *cursor, int64_t *u64p) { return XPT_Do32(cursor, (uint32_t *)u64p) && XPT_Do32(cursor, ((uint32_t *)u64p) + 1); }
XPT_DoCString(XPTArena *arena, XPTCursor *cursor, char **identp) { XPTCursor my_cursor; char *ident = *identp; uint32_t offset = 0; XPTMode mode = cursor->state->mode; if (mode == XPT_DECODE) { char *start, *end; int len; if (!XPT_Do32(cursor, &offset)) return PR_FALSE; if (!offset) { *identp = NULL; return PR_TRUE; } my_cursor.pool = XPT_DATA; my_cursor.offset = offset; my_cursor.state = cursor->state; start = &CURS_POINT(&my_cursor); end = strchr(start, 0); /* find the end of the string */ if (!end) { fprintf(stderr, "didn't find end of string on decode!\n"); return PR_FALSE; } len = end - start; XPT_ASSERT(len > 0); ident = (char*)XPT_MALLOC(arena, len + 1u); if (!ident) return PR_FALSE; memcpy(ident, start, (size_t)len); ident[len] = 0; *identp = ident; } else { if (!ident) { offset = 0; if (!XPT_Do32(cursor, &offset)) return PR_FALSE; return PR_TRUE; } if (!XPT_MakeCursor(cursor->state, XPT_DATA, strlen(ident) + 1, &my_cursor) || !XPT_Do32(cursor, &my_cursor.offset)) return PR_FALSE; while(*ident) if (!XPT_Do8(&my_cursor, (uint8_t *)ident++)) return PR_FALSE; if (!XPT_Do8(&my_cursor, (uint8_t *)ident)) /* write trailing zero */ return PR_FALSE; } return PR_TRUE; }
XPT_Do64(XPTCursor *cursor, PRInt64 *u64p) { return XPT_Do32(cursor, (PRUint32 *)u64p) && XPT_Do32(cursor, ((PRUint32 *)u64p) + 1); }
XPT_Do64(NotNull<XPTCursor*> cursor, int64_t *u64p) { return XPT_Do32(cursor, (uint32_t *)u64p) && XPT_Do32(cursor, ((uint32_t *)u64p) + 1); }