references/sleep-functions/readAsObject.md

GitHub

readAsObject

Category: InputOutput

Source: https://sleep.dashnine.org/manual/readAsObject.html


Synopsis

$ readAsObject([$handle])

reads a serialized object from the specified handle

Parameters

$handle - the handle to read from (defaults to stdin)

Returns

the object read from the handle. $null is returned in the event there is any trouble.

Side Effects / Notes

  • this function is similiar to &readObject except no Scalar wrapper is involved. Use this function when you want to communicate Java objects to a non-sleep app.

Examples

Example:

# sleep can interoperate with Java servers by serializing objects
# and sending them over a channel...

$handle = connect("127.0.0.1", 9998);

$list = [new LinkedList];
# do some stuff to $list

# write a java.util.LinkedList to $handle
writeAsObject($handle, $list);

# read an object in.
$object = readAsObject($handle);

See Also

&bread; &readAll; &readb; &readc; &readln; &readObject; &setEncoding