Skip to content

Commit 55fa55c

Browse files
author
Mahmood Ali
authored
Merge pull request #7924 from hashicorp/b-codecgen-flags
Clarify Msgpack handling of json tags
2 parents 572713d + 88808b2 commit 55fa55c

File tree

5 files changed

+11
-21
lines changed

5 files changed

+11
-21
lines changed

client/structs/structs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package structs
22

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

55
import (
66
"errors"

helper/pool/pool.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import (
2121

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

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

3232
// streamClient is used to wrap a stream with an RPC client

nomad/structs/generate.sh

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -e
44
FILES="$(ls ./*.go | grep -v -e _test.go -e .generated.go | tr '\n' ' ')"
55
codecgen \
66
-c github.com/hashicorp/go-msgpack/codec \
7+
-st codec \
78
-d 100 \
89
-t codegen_generated \
910
-o structs.generated.go \

nomad/structs/structs.go

+3-18
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
"github.com/gorhill/cronexpr"
2727
"github.com/hashicorp/go-msgpack/codec"
28-
hcodec "github.com/hashicorp/go-msgpack/codec"
2928
"github.com/hashicorp/go-multierror"
3029
"github.com/hashicorp/go-version"
3130
"github.com/mitchellh/copystructure"
@@ -9562,6 +9561,9 @@ var MsgpackHandle = func() *codec.MsgpackHandle {
95629561
// nil interface{}.
95639562
h.MapType = reflect.TypeOf(map[string]interface{}(nil))
95649563

9564+
// only review struct codec tags
9565+
h.TypeInfos = codec.NewTypeInfos([]string{"codec"})
9566+
95659567
return h
95669568
}()
95679569

@@ -9577,23 +9579,6 @@ var (
95779579
}
95789580
)
95799581

9580-
// TODO Figure out if we can remove this. This is our fork that is just way
9581-
// behind. I feel like its original purpose was to pin at a stable version but
9582-
// now we can accomplish this with vendoring.
9583-
var HashiMsgpackHandle = func() *hcodec.MsgpackHandle {
9584-
h := &hcodec.MsgpackHandle{}
9585-
h.RawToString = true
9586-
9587-
// maintain binary format from time prior to upgrading latest ugorji
9588-
h.BasicHandle.TimeNotBuiltin = true
9589-
9590-
// Sets the default type for decoding a map into a nil interface{}.
9591-
// This is necessary in particular because we store the driver configs as a
9592-
// nil interface{}.
9593-
h.MapType = reflect.TypeOf(map[string]interface{}(nil))
9594-
return h
9595-
}()
9596-
95979582
// Decode is used to decode a MsgPack encoded object
95989583
func Decode(buf []byte, out interface{}) error {
95999584
return codec.NewDecoder(bytes.NewReader(buf), MsgpackHandle).Decode(out)

plugins/base/plugin.go

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ var MsgpackHandle = func() *codec.MsgpackHandle {
6565
h.BasicHandle.TimeNotBuiltin = true
6666

6767
h.MapType = reflect.TypeOf(map[string]interface{}(nil))
68+
69+
// only review struct codec tags - ignore `json` flags
70+
h.TypeInfos = codec.NewTypeInfos([]string{"codec"})
71+
6872
return h
6973
}()
7074

0 commit comments

Comments
 (0)