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

no longer panics with the following file #181

Merged
merged 1 commit into from
Jun 27, 2017
Merged

Conversation

karrick
Copy link
Contributor

@karrick karrick commented Jun 27, 2017

In msgp/write.go, the code that uses reflection to ensure the type of the map key is a string has a small bug.

Consider the following code sample, which ought to execute without panicking. After the fix, this code works as expected.

package main

//go:generate msgp

import (
	"bytes"
	"fmt"
	"os"

	"github.com/tinylib/msgp/msgp"
)

type Feedback map[string]interface{}

func main() {
	deepMap := make(map[string]map[string]string)
	feedback := Feedback{"general": deepMap}

	bb := new(bytes.Buffer)
	if err := msgp.Encode(bb, feedback); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
		os.Exit(1)
	}
	fmt.Printf("%#v\n", bb.Bytes())
}

// 1. Type `go generate main.go`.
// 2. Type `go run main.go main_gen.go`.

This change is Reviewable

```
package main

//go:generate msgp

import (
	"bytes"
	"fmt"
	"os"

	"github.com/tinylib/msgp/msgp"
)

type Feedback map[string]interface{}

func main() {
	deepMap := make(map[string]map[string]string)
	feedback := Feedback{"general": deepMap}

	bb := new(bytes.Buffer)
	if err := msgp.Encode(bb, feedback); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
		os.Exit(1)
	}
	fmt.Printf("%#v\n", bb.Bytes())
}

// 1. Type `go generate main.go`.
// 2. Type `go run main.go main_gen.go`.
```
@philhofer
Copy link
Member

Looks good. Thanks!

@philhofer philhofer merged commit b2b6a67 into tinylib:master Jun 27, 2017
@karrick
Copy link
Contributor Author

karrick commented Jun 28, 2017

I know this request seems trivial, but are you able to throw a release tag on master?

By the way, I just recently learned about tinylib/msgp and it's truly amazing! After spending a lot of time writing Avro libraries for Go, I truly think this is just one amazing library. More of our infrastructure will be moving to MessagePack because of this library. Thank you for all of your hard work!

@philhofer
Copy link
Member

Sure thing.

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

Successfully merging this pull request may close these issues.

2 participants