1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright 2012 Raritan Inc. All rights reserved.
package Raritan::RPC::ObjectCodec;
use strict;
use warnings;
use Raritan::RPC::Registry;
use Raritan::RPC::Exception;
sub encode($) {
my ($obj) = @_;
if ($obj) {
return {
'rid' => $obj->{'rid'},
'type' => $obj->{'typeId'}
};
} else {
return undef;
}
}
sub decode($$$) {
my ($agent, $ref, $classname) = @_;
if (!defined $ref) {
return undef;
}
# try to find a compatible proxy for the type ID reported by the server
my $proxy_class = Raritan::RPC::Registry::findProxyClass($ref->{'type'});
if (!defined $proxy_class) {
# no compatible proxy found; use class from the IDL signature
if ($classname eq 'idl.Object') {
$proxy_class = 'Raritan::RPC::RemoteObject';
} else {
$proxy_class = Raritan::RPC::Registry::findProxyClass($classname);
}
}
if (!defined $proxy_class) {
throw Raritan::RPC::JsonRpcErrorException("No proxy found for $ref->{'type'}");
}
return $proxy_class->new($agent, $ref->{'rid'});
}
1;
|