Rework every uint8 to byte and rework every []byte to bytes.Buffer
I just learnt that uint8 and byte are the fucking same And that bytes.Buffer is the thing to use Idiot idiot idiot... Live and learn
This commit is contained in:
125
pdu/submit.go
125
pdu/submit.go
@@ -1,56 +1,60 @@
|
||||
package pdu
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/ascii85"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
type (
|
||||
SUBMIT_SM struct {
|
||||
header PDU_HEADER
|
||||
service_type string
|
||||
source_addr_ton uint8
|
||||
source_addr_npi uint8
|
||||
source_addr_ton byte
|
||||
source_addr_npi byte
|
||||
source_addr string
|
||||
dest_addr_ton uint8
|
||||
dest_addr_npi uint8
|
||||
dest_addr_ton byte
|
||||
dest_addr_npi byte
|
||||
destination_addr string
|
||||
esm_class uint8
|
||||
protocol_id uint8
|
||||
priority_flag uint8
|
||||
esm_class byte
|
||||
protocol_id byte
|
||||
priority_flag byte
|
||||
schedule_delivery_time string
|
||||
validity_period string
|
||||
registered_delivery uint8
|
||||
replace_if_present uint8
|
||||
data_coding uint8
|
||||
sm_default_msg_id uint8
|
||||
sm_length uint8
|
||||
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 uint8
|
||||
// source_addr_subunit byte
|
||||
// destination_port uint16
|
||||
// dest_addr_subunit uint8
|
||||
// dest_addr_subunit byte
|
||||
// sar_msg_ref_num uint16
|
||||
// sar_total_segments uint8
|
||||
// sar_segment_seqnum uint8
|
||||
// more_messages_to_send uint8
|
||||
// payload_type uint8
|
||||
// sar_total_segments byte
|
||||
// sar_segment_seqnum byte
|
||||
// more_messages_to_send byte
|
||||
// payload_type byte
|
||||
// message_payload string
|
||||
// privacy_indicator uint8
|
||||
// privacy_indicator byte
|
||||
// callback_num string
|
||||
// callback_num_pres uint8
|
||||
// callback_num_pres byte
|
||||
// callback_num_atag string
|
||||
// source_subaddress string
|
||||
// dest_subaddress string
|
||||
// user_response_code uint8
|
||||
// display_time uint8
|
||||
// sms_signal uint8
|
||||
// ms_validity uint8
|
||||
// ms_msg_wait_facilities uint8
|
||||
// number_of_messages uint8
|
||||
// alert_on_message_delivery uint8
|
||||
// language_indicator uint8
|
||||
// its_reply_type uint8
|
||||
// its_session_info uint8
|
||||
// ussd_service_op uint8
|
||||
// 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
|
||||
@@ -60,45 +64,56 @@ type (
|
||||
SUBMIT_MULTI_RESP struct{}
|
||||
)
|
||||
|
||||
func (p *SUBMIT_SM) Encode() (*[]byte, error) {
|
||||
buf := ByteBufferPool.Get(uint(p.Size()))
|
||||
err := p.EncodeInto(buf)
|
||||
return buf, err
|
||||
}
|
||||
func (p *SUBMIT_SM) EncodeInto(buf *[]byte) error {
|
||||
if buf == nil {
|
||||
return fmt.Errorf("cannot encode SUBMIT_SM, buffer is nil")
|
||||
}
|
||||
if len(*buf) < int(p.Size()) {
|
||||
return fmt.Errorf("cannot encode SUBMIT_SM, buffer too small (%d, required %d)", len(*buf), p.Size())
|
||||
}
|
||||
|
||||
p.header.EncodeInto(buf)
|
||||
func (p *SUBMIT_SM) Encode(buf *bytes.Buffer) error {
|
||||
p.header.Encode(buf)
|
||||
n := ascii85.Encode(buf.Bytes(), []byte(p.service_type))
|
||||
buf.Truncate(n)
|
||||
binary.Write(buf, binary.BigEndian, byte(len(p.service_type)))
|
||||
|
||||
// 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
|
||||
|
||||
return nil
|
||||
}
|
||||
func (p *SUBMIT_SM) Decode(data []byte) {
|
||||
func (p *SUBMIT_SM) Decode(buf *bytes.Buffer) error {
|
||||
return nil
|
||||
}
|
||||
func (p *SUBMIT_SM) Size() uint32 {
|
||||
var size uint32
|
||||
func (p *SUBMIT_SM) Size() int {
|
||||
var size int
|
||||
size += p.header.Size()
|
||||
size += uint32(len(p.service_type) * 1)
|
||||
size += len(p.service_type) * 1
|
||||
size += 1 // source_addr_ton
|
||||
size += 1 // source_addr_npi
|
||||
size += uint32(len(p.source_addr) * 1)
|
||||
size += len(p.source_addr) * 1
|
||||
size += 1 // dest_addr_ton
|
||||
size += 1 // dest_addr_npi
|
||||
size += uint32(len(p.destination_addr) * 1)
|
||||
size += len(p.destination_addr) * 1
|
||||
size += 1 // esm_class
|
||||
size += 1 // protocol_id
|
||||
size += 1 // priority_flag
|
||||
size += uint32(len(p.schedule_delivery_time) * 1)
|
||||
size += uint32(len(p.validity_period) * 1)
|
||||
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 += uint32(len(p.short_message) * 1)
|
||||
size += len(p.short_message) * 1
|
||||
return size
|
||||
}
|
||||
|
Reference in New Issue
Block a user