def build_by_receiver(sid,input)
@sid = sid
t,@code = read(input)
raise IOError.new("Wrong Result message: code field is not integer1.") unless t == T_INTEGER1
case @code
when R_OK
t,@value = read(input)
when R_APP_ERROR,R_PROTOCOL_ERROR,R_FATAL_ERROR
t,@err_klass = read(input)
raise IOError.new("Wrong Result message: error-class field is not string. #{t}") unless t == T_STRING || t == T_NULL
t,@err_message = read(input)
raise IOError.new("Wrong Result message: error-message field is not string. #{t}") unless t == T_STRING || t == T_NULL
t,@err_detail = read(input)
raise IOError.new("Wrong Result message: error-detail field is not string. #{t}") unless t == T_STRING || t == T_NULL
else
raise IOError.new("Unknown return code: #{@code}")
end
return self
end