Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

omitempty doesn't work for pointer types and msgpack #237

Closed
akalin-keybase opened this issue Mar 27, 2018 · 3 comments
Closed

omitempty doesn't work for pointer types and msgpack #237

akalin-keybase opened this issue Mar 27, 2018 · 3 comments

Comments

@akalin-keybase
Copy link

akalin-keybase commented Mar 27, 2018

Repro test:

package main

import (
	"testing"

	"github.com/ugorji/go/codec"
)

type V struct {
	A int  `codec:"a"`
	B *int `codec:"b,omitempty"`
	C int  `codec:"c,omitempty"`
}

func TestPacketEncode(t *testing.T) {
	var v V
	var mh codec.MsgpackHandle
	var encoded []byte
	e := codec.NewEncoderBytes(&encoded, &mh)
	err := e.Encode(v)
	if err != nil {
		t.Fatal(err)
	}

	t.Logf("Encoded to %#v", encoded)
	if encoded[0] != 0x81 {
		t.Fatalf("Expected first byte of %#v to be 0x81", encoded)
	}
}

prints:

go test .
--- FAIL: TestPacketEncode (0.00s)
	msgpack_test.go:25: Encoded to []byte{0x82, 0xa1, 0x61, 0x0, 0xa1, 0x62, 0xc0}
	msgpack_test.go:27: Expected first byte of []byte{0x82, 0xa1, 0x61, 0x0, 0xa1, 0x62, 0xc0} to be 0x81
FAIL

on master and v1.1.

I'll see if I can bisect it...

@akalin-keybase
Copy link
Author

git bisect points to d41456c

@ugorji
Copy link
Owner

ugorji commented Mar 29, 2018

Why should the first character be 0x81?

@akalin-keybase
Copy link
Author

Sorry for not being clear, that's the marker for a map with one element: https://github.com/msgpack/msgpack/blob/master/spec.md#map-format-family . 0x82 is the marker for a map with two elements (since B is erroneously encoded).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants