package sctp
import (
"errors"
"fmt"
)
type chunkHeartbeat struct {
chunkHeader
params []param
}
var (
ErrChunkTypeNotHeartbeat = errors .New ("ChunkType is not of type HEARTBEAT" )
ErrHeartbeatNotLongEnoughInfo = errors .New ("heartbeat is not long enough to contain Heartbeat Info" )
ErrParseParamTypeFailed = errors .New ("failed to parse param type" )
ErrHeartbeatParam = errors .New ("heartbeat should only have HEARTBEAT param" )
ErrHeartbeatChunkUnmarshal = errors .New ("failed unmarshalling param in Heartbeat Chunk" )
)
func (h *chunkHeartbeat ) unmarshal (raw []byte ) error {
if err := h .chunkHeader .unmarshal (raw ); err != nil {
return err
} else if h .typ != ctHeartbeat {
return fmt .Errorf ("%w: actually is %s" , ErrChunkTypeNotHeartbeat , h .typ .String ())
}
if len (raw ) <= chunkHeaderSize {
return fmt .Errorf ("%w: %d" , ErrHeartbeatNotLongEnoughInfo , len (raw ))
}
pType , err := parseParamType (raw [chunkHeaderSize :])
if err != nil {
return fmt .Errorf ("%w: %v" , ErrParseParamTypeFailed , err )
}
if pType != heartbeatInfo {
return fmt .Errorf ("%w: instead have %s" , ErrHeartbeatParam , pType .String ())
}
p , err := buildParam (pType , raw [chunkHeaderSize :])
if err != nil {
return fmt .Errorf ("%w: %v" , ErrHeartbeatChunkUnmarshal , err )
}
h .params = append (h .params , p )
return nil
}
func (h *chunkHeartbeat ) Marshal () ([]byte , error ) {
return nil , ErrUnimplemented
}
func (h *chunkHeartbeat ) check () (abort bool , err error ) {
return false , nil
}
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 .