Skip to content

Commit

Permalink
Merge pull request #7924 from hashicorp/b-codecgen-flags
Browse files Browse the repository at this point in the history
Clarify Msgpack handling of json tags
  • Loading branch information
Mahmood Ali authored May 11, 2020
2 parents 572713d + 88808b2 commit 55fa55c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
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

0 comments on commit 55fa55c

Please sign in to comment.