[squeak-dev] Beginner's question: How to serialize/materialize an
object to/from a ByteArray?
David T. Lewis
lewis at mail.msen.com
Sat Sep 7 18:35:40 UTC 2013
Yes, I think there was recent discussion about inconsistent stream
behavior with regard to #contents.
This also works:
myObject := MethodReference asClassDefinition.
ba := ((ReferenceStream on: ByteArray new writeStream asBinaryOrTextStream)
nextPut: myObject ;
(ReferenceStream on: ba readStream) next
So the serializer is ok, the issue relates only to stream positioning.
On Sat, Sep 07, 2013 at 02:07:41PM -0400, Bob Arning wrote:
> Well, this seems to work:
> | ba myObject rs |
> myObject := MethodReference asClassDefinition.
> rs _ ReferenceStream on: (MultiByteBinaryOrTextStream on: ByteArray new).
> rs nextPut: myObject.
> ba := rs reset; contents.
> (ReferenceStream on: (MultiByteBinaryOrTextStream with: ba) reset) next
> On 9/7/13 1:33 PM, Chris Muller wrote:
> >I just noticed 'browse class versions' is still not working with the
> >new-and-improved SqueakSource prototype because maybe there's a bug
> >with serializing an object to/from a ByteArray with Squeak?
> >I had wanted to use MultiByteBinaryOrTextStream to serialize to a
> >ByteArray, but when I try this:
> >| ba myObject |
> >myObject := MethodReference asClassDefinition.
> >ba := ((ReferenceStream on: (MultiByteBinaryOrTextStream on: ByteArray
> > nextPut: myObject ;
> > yourself) contents.
> >(ReferenceStream on: (MultiByteBinaryOrTextStream on: ba)) next
> >Produces an error: 'The file did not exist in this directory'. Huh?
> > What file? What directory?
> >I've only ever used my own serializer since about 2004, which I think
> >is much better but obviously for in-image stuff I have to use
> >Any help would be greatly appreciated.
More information about the Squeak-dev