1 #include "XDRInPacket.h" 2 #include <malloc.h> 3 #include <string.h> 4 #include <ByteOrder.h> 5 6 extern void 7 XDRInPacketInit(struct XDRInPacket *packet) 8 { 9 packet->fBuffer=NULL; 10 packet->fOffset=0; 11 } 12 13 extern void 14 XDRInPacketDestroy(struct XDRInPacket *packet) 15 { 16 free (packet->fBuffer); 17 } 18 19 extern int32 20 XDRInPacketGetInt32(struct XDRInPacket *packet) 21 { 22 int32 val=B_BENDIAN_TO_HOST_INT32(*((int32 *)&packet->fBuffer[packet->fOffset])); 23 24 packet->fOffset+=4; 25 26 return val; 27 } 28 29 extern void 30 XDRInPacketGetFixed(struct XDRInPacket *packet, void *buffer, size_t len) 31 { 32 memcpy (buffer,&packet->fBuffer[packet->fOffset],len); 33 packet->fOffset+=(len+3)&~3; 34 } 35 36 extern size_t 37 XDRInPacketGetDynamic(struct XDRInPacket *packet, void *buffer) 38 { 39 size_t size=XDRInPacketGetInt32(packet); 40 XDRInPacketGetFixed (packet,buffer,size); 41 42 return size; 43 } 44 45 extern char * 46 XDRInPacketGetString(struct XDRInPacket *packet) 47 { 48 int32 size=XDRInPacketGetInt32(packet); 49 char *string=(char *)malloc(size+1); 50 string[size]=0; 51 XDRInPacketGetFixed (packet,string,size); 52 53 return string; 54 } 55 56 extern void 57 XDRInPacketSetTo(struct XDRInPacket *packet, uint8 *buffer, size_t offset) 58 { 59 free (packet->fBuffer); 60 packet->fBuffer=buffer; 61 packet->fOffset=offset; 62 } 63