1 package GSM::SMS::NBS::Lib;
8 our @EXPORT=qw(&dcs_to_bits &empty_subload &encode_payload &nail_payload_len &min);
12 use vars qw($VERSION);
19 return ($dcs & 0xF4)==0xF4 ? 8 : 7;
23 my ($dcs, $freebytes) = @_;
25 return $freebytes if 8==dcs_to_bits($dcs);
26 # assumed 7==dcs_to_bits($dcs)
27 return int($freebytes*8/7); # floor-rounding is the proper one
31 my ($dcs, $payload) = @_;
33 return $payload if 8==dcs_to_bits($dcs);
34 # assumed 7==dcs_to_bits($dcs)
37 $bits.=unpack("b7",$&) while ($payload=~s/^.//);
38 $bits.="0"x7; # trailing padding
40 $r.=pack("b8",$&) while ($bits=~s/^.{8}//);
45 # returns length(encode_payload($dcs, "T"x$payload)) but it is more effective
46 sub nail_payload_len {
47 my ($dcs, $payload_len) = @_;
49 return $payload_len if 8==dcs_to_bits($dcs);
50 # assumed 7==dcs_to_bits($dcs)
51 return int(($payload_len*7+7)/8);
54 # Very common function but where is standardized?