# deserialize

Definition: | object res = deserialize(object sf, integer pos = 1, bool returnpos = false)
Description: | Converts a serialized object back to a standard Phix object. sf: a sequence or integer file handle, or memory address (if pos<0) pos: if sf is a sequence, must be a valid index into sf which points to the start of a serialized object. if sf is an atom, a negative pos indicates that sf is a raw memory address, otherwise sf is an open file handle. Defaults to 1. returnpos: true/1 = yes, false/0 = no. returns: res or {res,pos}, depending on returnpos.
pwa/p2js: | Supported, note however that it cannot decode anything that originally used atom_to_float80() [which realistically c/should only be from a 64-bit desktop/Phix program] since float80_to_atom() is (also) not supported under pwa/p2js. See serialize() for a suggestion on avoiding that in the first place.
Comments: | A serialized object is one that has been converted to a series of byte values, as originally returned from the serialize() function, but for any of this to be particularly useful, one that has had a fairly colourful journey through files, shared memory, network connections, or some such. An additional parameter has been added to deserialize to control whether or not the final pos should be returned when processing a sequence input. This allows several concatenated serialised objects to be extracted from a single stream. The Euphoria version always returns {res,pos} when given a sequence, but not a file. To retrieve data from a memory address, such as a shared memory block, specify a negative pos, with -1 indicating the first byte of that block. If pos is returned in this case, it will be more negative, and valid for a subsequent concatenated serialised object within the same memory block. Note that a returned pos is meaningless, and unchanged, when sf is a file handle. For examples, see serialize().
See Also: | serialize
Technicalia | Some performance loss may be noticed in comparison with the Euphoria version of this routine, which can be attributed to making it thread-safe.