home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / next / programm / 8096 < prev    next >
Encoding:
Text File  |  1993-01-12  |  1.9 KB  |  62 lines

  1. Path: sparky!uunet!rosie!next.com
  2. From: burkhold@next.com (Thomas Burkholder)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: Re: Archiving memory streams
  5. Keywords: memory, NXStream, archiving
  6. Message-ID: <6241@rosie.NeXT.COM>
  7. Date: 13 Jan 93 02:21:37 GMT
  8. References: <1993Jan8.150148.6961@ornl.gov>
  9. Sender: news@NeXT.COM
  10. Lines: 50
  11.  
  12. In article <1993Jan8.150148.6961@ornl.gov> woo@ornl.gov (John W. Wooten)  
  13. writes:
  14. > I have a NXStream that contains information I wish to archive.
  15. > I have demonstrated that the Object I am archiving which as
  16. > the stream pointer as an instance variable works properly as far as  
  17. > being able to set and retreive the contents of the stream pointer.
  18. > When archiving the Object, I wish to archive the contents of the stream  
  19. > pointer.  How do I do this?  I've tried * as type, and several other  
  20. > options, but the stream is a structure, should I have to describe the  
  21. > structure?
  22. > - - - - - - - - -
  23. > J. W. Wooten
  24.  
  25. Just hacked this up on the fly, so it probably isn't error-free; but you  
  26. get the idea.  A production version should probably be more careful about  
  27. how memory is allocated, not to mention error checking.  Hope it helps.
  28.  
  29. -thomas
  30. Thomas Burkholder (burkhold@next.com)
  31. NeXT Developer Support Team
  32. * And, no, I don't speak for NeXT, at least, not when I post on the net.*
  33.  
  34. -----cut here-----
  35. -writeStreamToTypedStream(NXTypedStream *cooked, NXStream *raw)
  36. {
  37.   char formatStr[10], *buf;
  38.   int len, maxLen;
  39.  
  40.   NXGetMemoryBuffer(raw,&buf,&len,&maxLen);
  41.   sprintf(formatStr,"%c%dc%c",len,'[',']');
  42.   NXWriteTypes(cooked,"i",len);
  43.   NXWriteTypes(cooked,formatStr,buf);
  44.   return self;
  45. }
  46.  
  47. -NXStream *readStreamFromTypedStream(NXTypedStream *cooked)
  48. {
  49.   int len;
  50.   char *formatStr;
  51.  
  52.   NXReadTypes(cooked,"i",&len);
  53.   buf = (char *)malloc(len * sizeof(char));
  54.   sprintf(formatStr,"%c%dc%c",len,'[',']');
  55.   NXReadTypes(cooked,formatStr,&buf);
  56.   return NXOpenMemory(buf,len,NX_READONLY);
  57. }
  58.  
  59.