diff options
author | Eiichiro Watanabe <a16tochjp@gmail.com> | 2015-12-09 11:40:24 +0900 |
---|---|---|
committer | Eiichiro Watanabe <a16tochjp@gmail.com> | 2015-12-09 12:30:49 +0900 |
commit | 86c92e09677875c027cf0aba9f15052b2becdadf (patch) | |
tree | d8a49eca74e2e1cd41fd1f25c86f413929c298b0 /packet/rtr.go | |
parent | 54addf3f4c04920283ca47f48e89eb07b9acbd55 (diff) |
packet: add constructor for RTRErrorReport
Diffstat (limited to 'packet/rtr.go')
-rw-r--r-- | packet/rtr.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/packet/rtr.go b/packet/rtr.go index 91a57b32..34186234 100644 --- a/packet/rtr.go +++ b/packet/rtr.go @@ -331,6 +331,23 @@ func (m *RTRErrorReport) Serialize() ([]byte, error) { return data, nil } +func NewRTRErrorReport(errCode uint16, errPDU []byte, errMsg []byte) *RTRErrorReport { + pdu := &RTRErrorReport{Type: RTR_ERROR_REPORT} + if errPDU != nil { + if errPDU[1] == RTR_ERROR_REPORT { + return nil + } + pdu.PDULen = uint32(len(errPDU)) + pdu.PDU = errPDU + } + if errMsg != nil { + pdu.Text = errMsg + pdu.TextLen = uint32(len(errMsg)) + } + pdu.Len = uint32(RTR_MIN_LEN) + uint32(RTR_ERROR_REPORT_ERR_PDU_LEN) + pdu.PDULen + uint32(RTR_ERROR_REPORT_ERR_TEXT_LEN) + pdu.TextLen + return pdu +} + func SplitRTR(data []byte, atEOF bool) (advance int, token []byte, err error) { if atEOF && len(data) == 0 || len(data) < RTR_MIN_LEN { return 0, nil, nil |