Files
smpp-tester/pdu/pdu.go
2024-07-22 20:41:18 +02:00

43 lines
1019 B
Go

package pdu
type (
PDU interface {
EncodeInto(*[]byte)
Encode() []byte
Decode([]byte)
}
PDU_HEADER struct {
command_length uint32
command_id uint32
command_status uint32
sequence_number uint32
}
GENERIC_NACK struct {
PDU_HEADER
}
)
func (p *PDU_HEADER) Encode() []byte {
buf := make([]byte, 16)
EncodeUint32(buf[0:4], p.command_length)
EncodeUint32(buf[4:8], p.command_id)
EncodeUint32(buf[8:12], p.command_status)
EncodeUint32(buf[12:16], p.sequence_number)
return buf
}
func (p *PDU_HEADER) EncodeInto(buf *[]byte) {
bufVal := *buf
EncodeUint32(bufVal[0:4], p.command_length)
EncodeUint32(bufVal[4:8], p.command_id)
EncodeUint32(bufVal[8:12], p.command_status)
EncodeUint32(bufVal[12:16], p.sequence_number)
}
func (p *PDU_HEADER) Decode(data []byte) {
p.command_length = DecodeUint32(data[0:4])
p.command_id = DecodeUint32(data[4:8])
p.command_status = DecodeUint32(data[8:12])
p.sequence_number = DecodeUint32(data[12:16])
}