Implement a part of submit encode

This commit is contained in:
PhatPhuckDave
2024-07-22 22:58:01 +02:00
parent abfba3b5a7
commit 4fcc1d88ff

View File

@@ -1,5 +1,7 @@
package pdu package pdu
import "fmt"
type ( type (
SUBMIT_SM struct { SUBMIT_SM struct {
header PDU_HEADER header PDU_HEADER
@@ -58,16 +60,28 @@ type (
SUBMIT_MULTI_RESP struct{} SUBMIT_MULTI_RESP struct{}
) )
func (p *SUBMIT_SM) Encode() []byte { func (p *SUBMIT_SM) Encode() ([]byte, error) {
return []byte{} buf := make([]byte, p.Size())
err := p.EncodeInto(&buf)
return buf, err
} }
func (p *SUBMIT_SM) EncodeInto(buf *[]byte) { 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)
return nil
} }
func (p *SUBMIT_SM) Decode(data []byte) { func (p *SUBMIT_SM) Decode(data []byte) {
} }
func (p *SUBMIT_SM) Size() uint32 { func (p *SUBMIT_SM) Size() uint32 {
var size uint32 var size uint32
size += 16 // header size += p.header.Size()
size += uint32(len(p.service_type) * 1) size += uint32(len(p.service_type) * 1)
size += 1 // source_addr_ton size += 1 // source_addr_ton
size += 1 // source_addr_npi size += 1 // source_addr_npi