msgpack.go 812 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2017 Manu Martinez-Almeida. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. //go:build !nomsgpack
  5. // +build !nomsgpack
  6. package binding
  7. /*
  8. import (
  9. "bytes"
  10. "io"
  11. "net/http"
  12. "github.com/ugorji/go/codec"
  13. )
  14. type msgpackBinding struct{}
  15. func (msgpackBinding) Name() string {
  16. return "msgpack"
  17. }
  18. func (msgpackBinding) Bind(req *http.Request, obj interface{}) error {
  19. return decodeMsgPack(req.Body, obj)
  20. }
  21. func (msgpackBinding) BindBody(body []byte, obj interface{}) error {
  22. return decodeMsgPack(bytes.NewReader(body), obj)
  23. }
  24. func decodeMsgPack(r io.Reader, obj interface{}) error {
  25. cdc := new(codec.MsgpackHandle)
  26. if err := codec.NewDecoder(r, cdc).Decode(&obj); err != nil {
  27. return err
  28. }
  29. return nil
  30. }
  31. //*/