]>
jfr.im git - irc/SurrealServices/srsv.git/blob - branches/erry-devel/SrSv/Insp/UUID.pm
1 # This file is part of SurrealServices.
3 # SurrealServices is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU Lesser General Public License version 2.1,
5 # as published by the Free Software Foundation.
7 # SurrealServices is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU Lesser General Public License
13 # along with SurrealServices; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #THIS CODE IS alpha only, and untested. Don't just trust it blindly.
23 package SrSv
::Insp
::UUID
;
29 use Exporter
qw( import );
31 our @EXPORT = qw( decodeUUID encodeUUID );
40 # the 24 here is SID_BITS, the 40 is UID_BITS
41 # but you can't reference a constant in a constant.
42 SID_BITMASK
=> (((2**24)-1) << 40),
43 UID_BITMASK
=> ~(((2**24)-1) << 40),
48 return ($char =~ /^[A-Z]$/);
53 return (ord($char) - ORD_A
);
55 return int($char) + 26;
61 ($a, $b, $c) = split(//, $a);
64 foreach my $char ($a,$b,$c) {
66 $sidN |= getBase36
($char);
72 my @chars = split(//, $UUID);
73 #my @sidC = @chars[0..2];
74 #my @uidC = @chars[3..8];
75 my $sidN = decodeSID
(@chars[0..2]);
77 foreach my $char (@chars[3..8]) {
79 $uidN |= getBase36
($char);
81 return (($sidN << UID_BITS
) | $uidN);
87 $ch = chr(($ch) + ORD_A
);
93 my ($id_int, $list) = @_;
94 foreach my $ch (reverse @$list) {
95 $ch = $id_int & CHAR_MASK
;
96 $id_int >>= CHAR_BITS
;
97 $ch = encodeChar
($ch);
102 my $SID_int = ($int & (SID_BITMASK
)) >> UID_BITS
;
103 my $UID_int = $int & UID_BITMASK
;
105 int2chars
($SID_int, \
@SID);
106 my @UID = (0,0,0,0,0,0);
107 int2chars
($UID_int, \
@UID);
108 print join('', @SID,@UID),"\n";
114 #my $int = decodeUUID('751AAAAAA');
116 #print log($int)/log(2), "\n";
118 print decodeUUID
('583AAAAAK');
119 #print encodeUUID (1);