🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #2359

Re: Archiving memory streams

#2359
From: Thomas Burkholder
Date: Wed, 13 Jan 1993 02:21
49 lines
2002 bytes
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);
}
Technical Details
Message-ID: <6241@rosie.NeXT.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!rosie!next.com
References: <1993Jan8.150148.6961@ornl.gov>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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