log at warn level invalid bps, channel values. inform user of default value.

This commit is contained in:
onyx-and-iris 2026-02-14 20:43:55 +00:00
parent c6d03e87d7
commit 08909b6b66

View File

@ -19,18 +19,37 @@ func WithRateLimit(ratelimit time.Duration) Option {
// WithBPSOpt is a functional option to set the bps index for {VbanTxt}.packet. // WithBPSOpt is a functional option to set the bps index for {VbanTxt}.packet.
func WithBPSOpt(bps int) Option { func WithBPSOpt(bps int) Option {
return func(vt *VbanTxt) { return func(vt *VbanTxt) {
defaultBps := BpsOpts[vt.packet.bpsIndex]
bpsIndex := indexOf(BpsOpts, bps) bpsIndex := indexOf(BpsOpts, bps)
if bpsIndex == -1 { if bpsIndex == -1 {
log.Warnf("invalid bps value %d, expected one of %v, defaulting to 0", bps, BpsOpts) log.Warnf(
"invalid bps value %d, expected one of %v, defaulting to %d",
bps,
BpsOpts,
defaultBps,
)
return return
} }
vt.packet.bpsIndex = bpsIndex if bpsIndex > 255 {
log.Warnf("bps index %d too large for uint8, defaulting to %d", bpsIndex, defaultBps)
return
}
vt.packet.bpsIndex = uint8(bpsIndex)
} }
} }
// WithChannel is a functional option to set the channel for {VbanTxt}.packet. // WithChannel is a functional option to set the channel for {VbanTxt}.packet.
func WithChannel(channel int) Option { func WithChannel(channel int) Option {
return func(vt *VbanTxt) { return func(vt *VbanTxt) {
vt.packet.channel = channel if channel < 0 || channel > 255 {
log.Warnf(
"channel value %d out of range [0,255], defaulting to %d",
channel,
vt.packet.channel,
)
return
}
vt.packet.channel = uint8(channel)
} }
} }