From: minima Date: Thu, 8 Jul 2004 07:58:49 +0000 (+0000) Subject: add pc59 encode and decode X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=35f219e44afa6fef9b1886403d5e81f2012bd895;p=spider.git add pc59 encode and decode --- diff --git a/perl/Route.pm b/perl/Route.pm index 7858e16c..b6671154 100644 --- a/perl/Route.pm +++ b/perl/Route.pm @@ -168,6 +168,46 @@ sub conf return $r ? 1 : 0; } +# +# pc59 entity encoding and decoding +# +sub enc_pc59 +{ + my $self = shift; + my $sort = shift || 'N'; + my $out = "$sort$self->{flag}$self->{call}"; + if ($self->{build}) { + $out .= "b$self->{build}"; + } elsif ($self->{version}) { + $out .= "v$self->{version}"; + } +} + +sub dec_pc59 +{ + my $node = shift; + my $s = ref($node) ? shift : $node; + $node = undef; + + my ($sort, $here, $call) = unpack "A A A*", $s; + return unless is_callsign($call); + return unless $here =~ /^[0123]$/; + return unless $sort =~ /^[NUE]$/; + if ($sort eq 'E' || $sort eq 'N') { + $node = Route::Node::get($call) || Route::Node->new($call); + if ($s =~ /b([\d\.])/) { + $node->{build} = $1; + } + if ($s =~ /v([\d\.])/) { + $node->{version} = $1; + } + } elsif ($sort eq 'U') { + $node = Route::User::get($call) || Route::User->new($call); + } + $node->flags = $here; + return $node; +} + # # display routines #