Class: SmppEncoding::Encoder

Inherits:
Object
  • Object
show all
Defined in:
lib/smpp_encoding/encoder.rb

Constant Summary collapse

ENCODING_GSM =

currently support only GSM and UNICODE

0
ENCODING_UNICODE =
8

Instance Method Summary collapse

Instance Method Details

#auto_encode(message) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/smpp_encoding/encoder.rb', line 10

def auto_encode message
  if GSMEncoder.can_encode?(message)
    {
      data_coding: ENCODING_GSM,
      payload: encode(ENCODING_GSM, message)
    }
  else
    {
      data_coding: ENCODING_UNICODE,
      payload: encode(ENCODING_UNICODE, message)
    }
  end
end

#enc(coding, message) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/smpp_encoding/encoder.rb', line 32

def enc coding, message
  if coding == :auto
    res = auto_encode(message)
    [res[:payload], res[:data_coding]]
  else
    [encode(coding, message), coding]
  end
end

#encode(encoding, message) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/smpp_encoding/encoder.rb', line 24

def encode encoding, message
  if (encoding < 2)
    GSMEncoder.encode(message)
  else
    message.encode('UTF-16BE').force_encoding('binary')
  end
end