Open Alexey1100 opened 6 years ago
Though, it works fine when dealing with SubmitSM PDU:
p := pdu.NewSubmitSM()
$ go run smpp_sample.go
INITIAL PDU: 0000003b000000040000000000000001000000544553540000002b3739303030303035353535000000000000000008000a00480065006c006c006f
DECODED PDU: 0000003b000000040000000000000001000000544553540000002b3739303030303035353535000000000000000008000a00480065006c006c006f
INITIAL SM: 00480065006c006c006f
DECODED SM: 00480065006c006c006f
Interesting. I haven't looked into this in a while, and haven't actually used this code for about a year now. If you can find where in the decoder we're adding that extra byte, please send a PR and I'll be happy to review.
What I found at the moment, that it somehow refers to UDH parsing.
Since when I'm removing UDHLength
from pdufield.List
in newDeliverSM
, it decodes the example PDU just fine.
newSubmitSM
doesn't have UDH fields defined for some reason.
This dirty hack seems to fix the problem, but I'm really not sure if it breaks something with an actual UDH.
// smpp/pdu/codec.go
// SerializeTo implements the PDU interface.
func (pdu *codec) SerializeTo(w io.Writer) error {
var b bytes.Buffer
for _, k := range pdu.FieldList() {
f, ok := pdu.f[k]
if !ok {
// HACK: Skipping serialisation of UDH if it's not found in PDU
if k == "gsm_sms_ud.udh.len" || k == "gsm_sms_ud.udh" {
continue
}
pdu.f.Set(k, nil)
f = pdu.f[k]
}
if err := f.SerializeTo(&b); err != nil {
return err
}
}
for _, f := range pdu.TLVFields() {
if err := f.SerializeTo(&b); err != nil {
return err
}
}
pdu.h.Len = uint32(pdu.Len())
err := pdu.h.SerializeTo(w)
if err != nil {
return err
}
_, err = io.Copy(w, &b)
return err
}
May be fixed by #94
Looks like decoding process adds one null byte at the start of ShortMessage field.
Example code:
Output: