Add length parameter to GSM7Bit decode
parent
84fbedc46b
commit
cf655b2b3c
|
@ -31,17 +31,18 @@ module Biju
|
|||
user_data_length: string[52..53],
|
||||
}
|
||||
res[:sender_number] = string[22..(22 + res[:address_length])]
|
||||
res[:user_data] = PDU.decode_user_data(
|
||||
string[54..-1], res[:data_coding_scheme])
|
||||
res[:user_data] = PDU.decode_user_data(string[54..-1],
|
||||
encoding: res[:data_coding_scheme],
|
||||
length: res[:user_data_length].hex)
|
||||
|
||||
res
|
||||
end
|
||||
|
||||
def self.decode_user_data(message, encoding = '00')
|
||||
def self.decode_user_data(message, encoding: '00', length: 0)
|
||||
encoding = data_coding_scheme(encoding) unless encoding.is_a?(Symbol)
|
||||
|
||||
raise ArgumentError, "Unknown encoding" unless ENCODING.has_key?(:gsm7bit)
|
||||
ENCODING[:gsm7bit].decode(message)
|
||||
ENCODING[:gsm7bit].decode(message, length: length)
|
||||
end
|
||||
|
||||
def self.data_coding_scheme(dcs)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module Biju::PDU
|
||||
module Biju
|
||||
module PDU
|
||||
class GSM7Bit
|
||||
BASIC_7BIT_CHARACTER_SET = [
|
||||
'@', '£', '$', '¥', 'è', 'é', 'ù', 'ì', 'ò', 'Ç', "\n", 'Ø', 'ø', "\r", 'Å', 'å',
|
||||
|
@ -26,7 +27,7 @@ module Biju::PDU
|
|||
0x65 => '€',
|
||||
}
|
||||
|
||||
def self.decode(string)
|
||||
def self.decode(string, length: 0)
|
||||
res = ''
|
||||
next_char = 0
|
||||
|
||||
|
@ -43,7 +44,7 @@ module Biju::PDU
|
|||
end
|
||||
end
|
||||
|
||||
res
|
||||
res[0..(length - 1)]
|
||||
end
|
||||
|
||||
def self.encode(string)
|
||||
|
@ -78,4 +79,5 @@ module Biju::PDU
|
|||
"%07b" % char
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue