Description

Native msgpack encodes unsigned integers using positive_fixint instead of the correct uintXX. Encoding with the external vmihailenco/msgpack gives the correct encoding.

How to reproduce

package main

import (
    "github.com/gin-gonic/gin"
    "github.com/vmihailenco/msgpack/v5"
)

func main() {
    var ret struct {
        T uint64 `msgpack:"t"`
    }

    g := gin.Default()
    g.GET("/testmsg", func(c *gin.Context) {
        c.Render(200, render.MsgPack{Data: ret})
    })
    g.GET("/testgin", func(c *gin.Context) {
        bytes, _ := msgpack.Marshal(ret)
        c.Writer.Write(bytes)
    })
    g.Run(":9000")
}

Expectations

$ curl -s localhost:9000/testmsg | fq -d msgpack '. | tovalue'
{
  "length": 1,
  "pairs": [
    {
      "key": {
        "length": 1,
        "type": "fixstr",
        "value": "t"
      },
      "value": {
        "type": "uint64",
        "value": 0
      }
    }
  ],
  "type": "fixmap"
}

Actual result

$ curl -s localhost:9000/testgin | fq -d msgpack '. | tovalue'
{
  "length": 1,
  "pairs": [
    {
      "key": {
        "length": 1,
        "type": "fixstr",
        "value": "T"
      },
      "value": {
        "type": "positive_fixint",
        "value": 0
      }
    }
  ],
  "type": "fixmap"
}

Environment

  • go version: go version go1.23.0 linux/amd64
  • gin version (or commit ref): v1.10.0
  • operating system: Ubuntu 24.04.1 LTS

Comment From: JimChenWYU

gin use github.com/ugorji/go/codec as msgpack encoder, can you help to test whether its behavior is consistent with github.com/vmihailenco/msgpack/v5 ?

Comment From: anpez

gin use github.com/ugorji/go/codec as msgpack encoder, can you help to test whether its behavior is consistent with github.com/vmihailenco/msgpack/v5 ?

I've been reading through ugorji/go and it looks like it's not a bug, but a feature. A long explaning issue is on their github here. So I guess that's it for gin then. Thanks anyway for your time