| 327 | type scanPlanBinaryInt2ToUint8 struct{} |
| 328 | |
| 329 | func (scanPlanBinaryInt2ToUint8) Scan(src []byte, dst any) error { |
| 330 | if src == nil { |
| 331 | return fmt.Errorf("cannot scan NULL into %T", dst) |
| 332 | } |
| 333 | |
| 334 | if len(src) != 2 { |
| 335 | return fmt.Errorf("invalid length for uint2: %v", len(src)) |
| 336 | } |
| 337 | |
| 338 | p, ok := (dst).(*uint8) |
| 339 | if !ok { |
| 340 | return ErrScanTargetTypeChanged |
| 341 | } |
| 342 | |
| 343 | n := int16(binary.BigEndian.Uint16(src)) |
| 344 | if n < 0 { |
| 345 | return fmt.Errorf("%d is less than minimum value for uint8", n) |
| 346 | } |
| 347 | |
| 348 | if n > math.MaxUint8 { |
| 349 | return fmt.Errorf("%d is greater than maximum value for uint8", n) |
| 350 | } |
| 351 | |
| 352 | *p = uint8(n) |
| 353 | |
| 354 | return nil |
| 355 | } |
| 356 | |
| 357 | type scanPlanBinaryInt2ToInt16 struct{} |
| 358 | |