github.com/hernad/nomad@v1.6.112/helper/pluginutils/hclutils/types.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package hclutils 5 6 import ( 7 "github.com/hashicorp/go-msgpack/codec" 8 ) 9 10 // MapStrInt is a wrapper for map[string]int that handles 11 // deserialization from different hcl2 json representation 12 // that were supported in Nomad 0.8 13 type MapStrInt map[string]int 14 15 func (s *MapStrInt) CodecEncodeSelf(enc *codec.Encoder) { 16 v := []map[string]int{*s} 17 enc.MustEncode(v) 18 } 19 20 func (s *MapStrInt) CodecDecodeSelf(dec *codec.Decoder) { 21 ms := []map[string]int{} 22 dec.MustDecode(&ms) 23 24 r := map[string]int{} 25 for _, m := range ms { 26 for k, v := range m { 27 r[k] = v 28 } 29 } 30 *s = r 31 } 32 33 // MapStrStr is a wrapper for map[string]string that handles 34 // deserialization from different hcl2 json representation 35 // that were supported in Nomad 0.8 36 type MapStrStr map[string]string 37 38 func (s *MapStrStr) CodecEncodeSelf(enc *codec.Encoder) { 39 v := []map[string]string{*s} 40 enc.MustEncode(v) 41 } 42 43 func (s *MapStrStr) CodecDecodeSelf(dec *codec.Decoder) { 44 ms := []map[string]string{} 45 dec.MustDecode(&ms) 46 47 r := map[string]string{} 48 for _, m := range ms { 49 for k, v := range m { 50 r[k] = v 51 } 52 } 53 *s = r 54 }