package sctp
import (
"errors"
"fmt"
)
type chunkReconfig struct {
chunkHeader
paramA param
paramB param
}
var (
ErrChunkParseParamTypeFailed = errors .New ("failed to parse param type" )
ErrChunkMarshalParamAReconfigFailed = errors .New ("unable to marshal parameter A for reconfig" )
ErrChunkMarshalParamBReconfigFailed = errors .New ("unable to marshal parameter B for reconfig" )
)
func (c *chunkReconfig ) unmarshal (raw []byte ) error {
if err := c .chunkHeader .unmarshal (raw ); err != nil {
return err
}
pType , err := parseParamType (c .raw )
if err != nil {
return fmt .Errorf ("%w: %v" , ErrChunkParseParamTypeFailed , err )
}
a , err := buildParam (pType , c .raw )
if err != nil {
return err
}
c .paramA = a
padding := getPadding (a .length ())
offset := a .length () + padding
if len (c .raw ) > offset {
pType , err := parseParamType (c .raw [offset :])
if err != nil {
return fmt .Errorf ("%w: %v" , ErrChunkParseParamTypeFailed , err )
}
b , err := buildParam (pType , c .raw [offset :])
if err != nil {
return err
}
c .paramB = b
}
return nil
}
func (c *chunkReconfig ) marshal () ([]byte , error ) {
out , err := c .paramA .marshal ()
if err != nil {
return nil , fmt .Errorf ("%w: %v" , ErrChunkMarshalParamAReconfigFailed , err )
}
if c .paramB != nil {
out = padByte (out , getPadding (len (out )))
outB , err := c .paramB .marshal ()
if err != nil {
return nil , fmt .Errorf ("%w: %v" , ErrChunkMarshalParamBReconfigFailed , err )
}
out = append (out , outB ...)
}
c .typ = ctReconfig
c .raw = out
return c .chunkHeader .marshal ()
}
func (c *chunkReconfig ) check () (abort bool , err error ) {
return true , nil
}
func (c *chunkReconfig ) String () string {
res := fmt .Sprintf ("Param A:\n %s" , c .paramA )
if c .paramB != nil {
res += fmt .Sprintf ("Param B:\n %s" , c .paramB )
}
return res
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .