-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathsubmit_multi_response.rb
More file actions
50 lines (39 loc) · 1.44 KB
/
Copy pathsubmit_multi_response.rb
File metadata and controls
50 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- encoding : utf-8 -*-
# Recieving response for an MT message sent to multiple addresses
# Author: Abhishek Parolkar, (abhishek[at]parolkar.com)
class Smpp::Pdu::SubmitMultiResponse < Smpp::Pdu::Base
class UnsuccessfulSme
Struct.new(:dest_addr_ton, :dest_addr_npi, :destination_addr, :error_status_code)
end
handles_cmd SUBMIT_MULTI_RESP
attr_accessor :message_id, :unsuccess_smes
def initialize(seq, status, message_id, unsuccess_smes = [])
@unsuccess_smes = unsuccess_smes
seq ||= next_sequence_number
packed_smes = ""
unsuccess_smes.each do |sme|
packed_smes << [
sme.dest_addr_ton,
sme.dest_addr_npi,
sme.destination_addr,
sme.error_status_code
].pack("CCZ*N")
end
body = [message_id, unsuccess_smes.size, packed_smes].pack("Z*Ca*")
super(SUBMIT_MULTI_RESP, status, seq, body)
@message_id = message_id
end
def self.from_wire_data(seq, status, body)
message_id, no_unsuccess, rest = body.unpack("Z*Ca*")
unsuccess_smes = []
no_unsuccess.times do |i|
#unpack the next sme
dest_addr_ton, dest_addr_npi, destination_addr, error_status_code =
rest.unpack("CCZ*N")
#remove the SME from rest
rest.slice!(0,7 + destination_addr.length)
unsuccess_smes << UnsuccessfulSme.new(dest_addr_ton, dest_addr_npi, destination_addr, error_status_code)
end
new(seq, status, message_id, unsuccess_smes)
end
end