Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Marshaling of Dialogue
Browse files Browse the repository at this point in the history
linouxis9 committed Mar 26, 2024
1 parent def14b7 commit 7acf04f
Showing 3 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion dialogue-pdu.go
Original file line number Diff line number Diff line change
@@ -702,13 +702,14 @@ func (d *DialoguePDU) ContextVersion() string {

// String returns DialoguePDU in human readable string.
func (d *DialoguePDU) String() string {
return fmt.Sprintf("{Type: %#x, Length: %d, ProtocolVersion: %v, ApplicationContextName: %v, Result: %v, ResultSourceDiagnostic: %v, AbortSource: %v}",
return fmt.Sprintf("{Type: %#x, Length: %d, ProtocolVersion: %v, ApplicationContextName: %v, Result: %v, ResultSourceDiagnostic: %v, AbortSource: %v, UserInformation: %v}",
d.Type,
d.Length,
d.ProtocolVersion,
d.ApplicationContextName,
d.Result,
d.ResultSourceDiagnostic,
d.AbortSource,
d.UserInformation,
)
}
28 changes: 17 additions & 11 deletions dialogue.go
Original file line number Diff line number Diff line change
@@ -79,20 +79,23 @@ func (d *Dialogue) MarshalTo(b []byte) error {
}

if field := d.SingleAsn1Type; field != nil {
if err := field.MarshalTo(b[offset : offset+field.MarshalLen()]); err != nil {
return err
if field := d.DialoguePDU; field != nil {
d.SingleAsn1Type.Value = make([]byte, d.DialoguePDU.MarshalLen())

if err := d.DialoguePDU.MarshalTo(d.SingleAsn1Type.Value); err != nil {
return err
}
}
offset += field.MarshalLen()
}

if field := d.DialoguePDU; field != nil {
d.SingleAsn1Type.SetLength()
if err := field.MarshalTo(b[offset : offset+field.MarshalLen()]); err != nil {
return err
}
offset += field.MarshalLen()
}

copy(b[offset:], d.Payload)

return nil
}

@@ -190,19 +193,22 @@ func (d *Dialogue) MarshalLen() int {
if field := d.ObjectIdentifier; field != nil {
l += field.MarshalLen()
}
if field := d.SingleAsn1Type; field != nil {
l += field.MarshalLen()
}
if field := d.DialoguePDU; field != nil {
l += field.MarshalLen()
l += field.MarshalLen() + 2 // 2 = SingleAsn1Type IE Header
}
l += len(d.Payload)

return l
return l + len(d.Payload)
}

// SetLength sets the length in Length field.
func (d *Dialogue) SetLength() {
if field := d.ObjectIdentifier; field != nil {
d.ObjectIdentifier.SetLength()
}
if field := d.DialoguePDU; field != nil {
d.DialoguePDU.SetLength()
}

d.Length = uint8(d.MarshalLen() - 2)
d.ExternalLength = uint8(d.MarshalLen() - 4)
}
1 change: 1 addition & 0 deletions tcap.go
Original file line number Diff line number Diff line change
@@ -114,6 +114,7 @@ func Parse(b []byte) (*TCAP, error) {
if err := t.UnmarshalBinary(b); err != nil {
return nil, err
}

return t, nil
}

0 comments on commit 7acf04f

Please sign in to comment.