function decodeStream( $request, $stream, $headers=false, $cookies=array(), $statuscode="200"  )
    {
        $this->decodeStreamCommon( $request, $stream, $headers, $cookies, $statuscode );

        /// @todo refuse bad content-types?

        $results = json_decode( $stream, true );
        if ( !is_array($results) ||
            !array_key_exists( 'result', $results ) ||
            !array_key_exists( 'error', $results ) ||
            !array_key_exists( 'id', $results )
            )
        {
            // invalid jsonrpc response
            $this->IsFault = true;
            $this->FaultCode = self::INVALIDRESPONSEERROR;
            $this->FaultString = self::INVALIDRESPONSESTRING;
        }
        else
        {
            $this->Id =  $results['id'];

            /// we should check if id of response is same as id of request, and raise error if not
            if ( $results['id'] != $request->id() )
            {
                $this->IsFault = true;
                $this->FaultCode = self::INVALIDIDERROR;
                $this->FaultString = self::INVALIDIDSTRING;
            }
            else if ( $results['error'] === null )
            {
                /// NB: spec is formally strange: what if both error and result are null???

                $this->Value = $results['result'];
            }
            else
            {
                $this->IsFault = true;
                $error = $results['error'];
                if ( is_array( $error ) && array_key_exists( 'faultCode', $error ) && array_key_exists( 'faultString', $error ) )
                {
                    // since server conforms to our error syntax, we force the types on him, too
                    $this->FaultCode = (int)$error['faultCode'];
                    $this->FaultString = (string)$error['faultString'];
                }
                else
                {
                    $this->FaultCode = self::GENERICRESPONSEERROR;
                    /// @todo we should somehow typecast to string here??? maybe reencode as json?
                    $this->FaultString = $results['error'];
                }
            }
        }
    }