cbor.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package binder
  2. import (
  3. "github.com/gofiber/utils/v2"
  4. )
  5. // CBORBinding is the CBOR binder for CBOR request body.
  6. type CBORBinding struct {
  7. CBORDecoder utils.CBORUnmarshal
  8. }
  9. // Name returns the binding name.
  10. func (*CBORBinding) Name() string {
  11. return "cbor"
  12. }
  13. // Bind parses the request body as CBOR and returns the result.
  14. func (b *CBORBinding) Bind(body []byte, out any) error {
  15. return b.CBORDecoder(body, out)
  16. }
  17. // Reset resets the CBORBinding binder.
  18. func (b *CBORBinding) Reset() {
  19. b.CBORDecoder = nil
  20. }
  21. // UnimplementedCborMarshal panics to signal that a CBOR marshaler must be
  22. // configured before CBOR support can be used.
  23. func UnimplementedCborMarshal(_ any) ([]byte, error) {
  24. panic("Must explicitly setup CBOR, please check docs: https://docs.gofiber.io/next/guide/advance-format#cbor")
  25. }
  26. // UnimplementedCborUnmarshal panics to signal that a CBOR unmarshaler must be
  27. // configured before CBOR support can be used.
  28. func UnimplementedCborUnmarshal(_ []byte, _ any) error {
  29. panic("Must explicitly setup CBOR, please check docs: https://docs.gofiber.io/next/guide/advance-format#cbor")
  30. }