home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!rosie!next.com
- From: burkhold@next.com (Thomas Burkholder)
- Newsgroups: comp.sys.next.programmer
- Subject: Re: Archiving memory streams
- Keywords: memory, NXStream, archiving
- Message-ID: <6241@rosie.NeXT.COM>
- Date: 13 Jan 93 02:21:37 GMT
- References: <1993Jan8.150148.6961@ornl.gov>
- Sender: news@NeXT.COM
- Lines: 50
-
- In article <1993Jan8.150148.6961@ornl.gov> woo@ornl.gov (John W. Wooten)
- writes:
- > I have a NXStream that contains information I wish to archive.
- >
- > I have demonstrated that the Object I am archiving which as
- > the stream pointer as an instance variable works properly as far as
- > being able to set and retreive the contents of the stream pointer.
- >
- > When archiving the Object, I wish to archive the contents of the stream
- > pointer. How do I do this? I've tried * as type, and several other
- > options, but the stream is a structure, should I have to describe the
- > structure?
- >
- > - - - - - - - - -
- > J. W. Wooten
-
- Just hacked this up on the fly, so it probably isn't error-free; but you
- get the idea. A production version should probably be more careful about
- how memory is allocated, not to mention error checking. Hope it helps.
-
- -thomas
- Thomas Burkholder (burkhold@next.com)
- NeXT Developer Support Team
- * And, no, I don't speak for NeXT, at least, not when I post on the net.*
-
- -----cut here-----
- -writeStreamToTypedStream(NXTypedStream *cooked, NXStream *raw)
- {
- char formatStr[10], *buf;
- int len, maxLen;
-
- NXGetMemoryBuffer(raw,&buf,&len,&maxLen);
- sprintf(formatStr,"%c%dc%c",len,'[',']');
- NXWriteTypes(cooked,"i",len);
- NXWriteTypes(cooked,formatStr,buf);
- return self;
- }
-
- -NXStream *readStreamFromTypedStream(NXTypedStream *cooked)
- {
- int len;
- char *formatStr;
-
- NXReadTypes(cooked,"i",&len);
- buf = (char *)malloc(len * sizeof(char));
- sprintf(formatStr,"%c%dc%c",len,'[',']');
- NXReadTypes(cooked,formatStr,&buf);
- return NXOpenMemory(buf,len,NX_READONLY);
- }
-
-