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

Clarify Msgpack handling of json tags #7924

Merged
merged 2 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/structs/structs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package structs

//go:generate codecgen -c github.com/hashicorp/go-msgpack/codec -d 102 -t codegen_generated -o structs.generated.go structs.go
//go:generate codecgen -c github.com/hashicorp/go-msgpack/codec -st codec -d 102 -t codegen_generated -o structs.generated.go structs.go

import (
"errors"
Expand Down
4 changes: 2 additions & 2 deletions helper/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (

// NewClientCodec returns a new rpc.ClientCodec to be used to make RPC calls.
func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec {
return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.HashiMsgpackHandle)
return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.MsgpackHandle)
}

// NewServerCodec returns a new rpc.ServerCodec to be used to handle RPCs.
func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec {
return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.HashiMsgpackHandle)
return msgpackrpc.NewCodecFromHandle(true, true, conn, structs.MsgpackHandle)
}

// streamClient is used to wrap a stream with an RPC client
Expand Down
1 change: 1 addition & 0 deletions nomad/structs/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -e
FILES="$(ls ./*.go | grep -v -e _test.go -e .generated.go | tr '\n' ' ')"
codecgen \
-c github.com/hashicorp/go-msgpack/codec \
-st codec \
-d 100 \
-t codegen_generated \
-o structs.generated.go \
Expand Down
21 changes: 3 additions & 18 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/gorhill/cronexpr"
"github.com/hashicorp/go-msgpack/codec"
hcodec "github.com/hashicorp/go-msgpack/codec"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-version"
"github.com/mitchellh/copystructure"
Expand Down Expand Up @@ -9562,6 +9561,9 @@ var MsgpackHandle = func() *codec.MsgpackHandle {
// nil interface{}.
h.MapType = reflect.TypeOf(map[string]interface{}(nil))

// only review struct codec tags
h.TypeInfos = codec.NewTypeInfos([]string{"codec"})

return h
}()

Expand All @@ -9577,23 +9579,6 @@ var (
}
)

// TODO Figure out if we can remove this. This is our fork that is just way
// behind. I feel like its original purpose was to pin at a stable version but
// now we can accomplish this with vendoring.
var HashiMsgpackHandle = func() *hcodec.MsgpackHandle {
h := &hcodec.MsgpackHandle{}
h.RawToString = true

// maintain binary format from time prior to upgrading latest ugorji
h.BasicHandle.TimeNotBuiltin = true

// Sets the default type for decoding a map into a nil interface{}.
// This is necessary in particular because we store the driver configs as a
// nil interface{}.
h.MapType = reflect.TypeOf(map[string]interface{}(nil))
return h
}()

// Decode is used to decode a MsgPack encoded object
func Decode(buf []byte, out interface{}) error {
return codec.NewDecoder(bytes.NewReader(buf), MsgpackHandle).Decode(out)
Expand Down
4 changes: 4 additions & 0 deletions plugins/base/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ var MsgpackHandle = func() *codec.MsgpackHandle {
h.BasicHandle.TimeNotBuiltin = true

h.MapType = reflect.TypeOf(map[string]interface{}(nil))

// only review struct codec tags - ignore `json` flags
h.TypeInfos = codec.NewTypeInfos([]string{"codec"})

return h
}()

Expand Down