129 lines
4.0 KiB
Go
129 lines
4.0 KiB
Go
package pdu
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/ascii85"
|
|
"encoding/binary"
|
|
"fmt"
|
|
)
|
|
|
|
type (
|
|
SUBMIT_SM struct {
|
|
header *PDU_HEADER
|
|
service_type string
|
|
source_addr_ton byte
|
|
source_addr_npi byte
|
|
source_addr string
|
|
dest_addr_ton byte
|
|
dest_addr_npi byte
|
|
destination_addr string
|
|
esm_class byte
|
|
protocol_id byte
|
|
priority_flag byte
|
|
schedule_delivery_time string
|
|
validity_period string
|
|
registered_delivery byte
|
|
replace_if_present byte
|
|
data_coding byte
|
|
sm_default_msg_id byte
|
|
sm_length byte
|
|
short_message string
|
|
// user_message_reference uint16
|
|
// source_port uint16
|
|
// source_addr_subunit byte
|
|
// destination_port uint16
|
|
// dest_addr_subunit byte
|
|
// sar_msg_ref_num uint16
|
|
// sar_total_segments byte
|
|
// sar_segment_seqnum byte
|
|
// more_messages_to_send byte
|
|
// payload_type byte
|
|
// message_payload string
|
|
// privacy_indicator byte
|
|
// callback_num string
|
|
// callback_num_pres byte
|
|
// callback_num_atag string
|
|
// source_subaddress string
|
|
// dest_subaddress string
|
|
// user_response_code byte
|
|
// display_time byte
|
|
// sms_signal byte
|
|
// ms_validity byte
|
|
// ms_msg_wait_facilities byte
|
|
// number_of_messages byte
|
|
// alert_on_message_delivery byte
|
|
// language_indicator byte
|
|
// its_reply_type byte
|
|
// its_session_info byte
|
|
// ussd_service_op byte
|
|
}
|
|
SUBMIT_SM_RESP struct {
|
|
header *PDU_HEADER
|
|
message_id string
|
|
}
|
|
SUBMIT_MULTI struct{}
|
|
SUBMIT_MULTI_RESP struct{}
|
|
)
|
|
|
|
func (p *SUBMIT_SM) Encode(buf *bytes.Buffer) error {
|
|
if buf == nil {
|
|
return fmt.Errorf("cannot encode into nil buffer")
|
|
}
|
|
p.header.Encode(buf)
|
|
n := ascii85.Encode(buf.Bytes(), []byte(p.service_type))
|
|
buf.Truncate(n)
|
|
binary.Write(buf, binary.BigEndian, p.source_addr_ton)
|
|
binary.Write(buf, binary.BigEndian, p.source_addr_npi)
|
|
n = ascii85.Encode(buf.Bytes(), []byte(p.source_addr))
|
|
buf.Truncate(n)
|
|
binary.Write(buf, binary.BigEndian, p.dest_addr_ton)
|
|
binary.Write(buf, binary.BigEndian, p.dest_addr_npi)
|
|
n = ascii85.Encode(buf.Bytes(), []byte(p.destination_addr))
|
|
buf.Truncate(n)
|
|
binary.Write(buf, binary.BigEndian, p.esm_class)
|
|
binary.Write(buf, binary.BigEndian, p.protocol_id)
|
|
binary.Write(buf, binary.BigEndian, p.priority_flag)
|
|
n = ascii85.Encode(buf.Bytes(), []byte(p.schedule_delivery_time))
|
|
buf.Truncate(n)
|
|
n = ascii85.Encode(buf.Bytes(), []byte(p.validity_period))
|
|
buf.Truncate(n)
|
|
binary.Write(buf, binary.BigEndian, p.registered_delivery)
|
|
binary.Write(buf, binary.BigEndian, p.replace_if_present)
|
|
binary.Write(buf, binary.BigEndian, p.data_coding)
|
|
binary.Write(buf, binary.BigEndian, p.sm_default_msg_id)
|
|
binary.Write(buf, binary.BigEndian, p.sm_length)
|
|
// TODO: Implement encodings bsed on p.data_coding
|
|
n = ascii85.Encode(buf.Bytes(), []byte(p.short_message))
|
|
buf.Truncate(n)
|
|
return nil
|
|
}
|
|
func (p *SUBMIT_SM) Decode(buf *bytes.Buffer) error {
|
|
if buf == nil {
|
|
return fmt.Errorf("cannot decode nil buffer")
|
|
}
|
|
return nil
|
|
}
|
|
func (p *SUBMIT_SM) Size() int {
|
|
var size int
|
|
size += p.header.Size()
|
|
size += len(p.service_type) * 1
|
|
size += 1 // source_addr_ton
|
|
size += 1 // source_addr_npi
|
|
size += len(p.source_addr) * 1
|
|
size += 1 // dest_addr_ton
|
|
size += 1 // dest_addr_npi
|
|
size += len(p.destination_addr) * 1
|
|
size += 1 // esm_class
|
|
size += 1 // protocol_id
|
|
size += 1 // priority_flag
|
|
size += len(p.schedule_delivery_time) * 1
|
|
size += len(p.validity_period) * 1
|
|
size += 1 // registered_delivery
|
|
size += 1 // replace_if_present
|
|
size += 1 // data_coding
|
|
size += 1 // sm_default_msg_id
|
|
size += 1 // sm_length
|
|
size += len(p.short_message) * 1
|
|
return size
|
|
}
|