@@ -134,10 +134,14 @@ const parseFuncFooter = `
134134// parseFuncTemplate decodes a struct encoded as a map.
135135// It calls `makeNumericConst` for special integer values in a top-level FuncMap.
136136const parseFuncTemplate = `
137- cnt, err := p.expectWriteMapMarker({{.MaxFieldCount}}, c )
137+ cnt, err := p.readFixMap( )
138138 if err != nil {
139- return fmt.Errorf("map for {{.TypeName}}: %w", err)
139+ return fmt.Errorf("reading map for {{.TypeName}}: %w", err)
140140 }
141+ if cnt < 1 || cnt > {{.MaxFieldCount}} {
142+ return fmt.Errorf("expected fixmap size for {{.TypeName}} 1 <= cnt <= {{.MaxFieldCount}}, got %d", cnt)
143+ }
144+ c.writeStatic(StaticIdxMapMarker0+cnt)
141145
142146 for range cnt {
143147 key, err := p.readString()
@@ -153,6 +157,7 @@ const parseFuncTemplate = `
153157 c.writeStatic({{$fd.FieldNameConst}})
154158 {{renderParseFunction $fd.SubStructName}}
155159 {{- else if $fd.IsUint64Alias}}
160+ {{ if not $fd.VpackSpecial }}c.writeStatic({{$fd.FieldNameConst}}){{end}}
156161 valBytes, err := p.readUintBytes()
157162 if err != nil {
158163 return fmt.Errorf("reading {{$fd.CodecName}}: %w", err)
@@ -170,9 +175,10 @@ const parseFuncTemplate = `
170175 }
171176 }
172177 {{end}}
173- c.writeStatic({{$fd.FieldNameConst}})
178+ {{ if $fd.VpackSpecial }} c.writeStatic({{$fd.FieldNameConst}}){{ end }}
174179 c.writeDynamicVaruint(valBytes)
175180 {{- else if gt $fd.ArrayLen 0}}
181+ {{ if and (not $fd.VpackSpecial) (not $fd.IsZeroCheck) }}c.writeStatic({{$fd.FieldNameConst}}){{end}}
176182 val, err := p.readBin{{$fd.ArrayLen}}()
177183 if err != nil {
178184 return fmt.Errorf("reading {{$fd.CodecName}}: %w", err)
@@ -185,10 +191,10 @@ const parseFuncTemplate = `
185191 c.writeLiteralBin{{$fd.ArrayLen}}(val)
186192 }
187193 {{- else if $fd.IsLiteral}}
188- c.writeStatic({{$fd.FieldNameConst}})
194+ {{ if $fd.VpackSpecial }} c.writeStatic({{$fd.FieldNameConst}}){{ end }}
189195 c.writeLiteralBin{{$fd.ArrayLen}}(val)
190196 {{- else}}
191- c.writeStatic({{$fd.FieldNameConst}})
197+ {{ if $fd.VpackSpecial }} c.writeStatic({{$fd.FieldNameConst}}){{ end }}
192198 c.writeDynamicBin{{$fd.ArrayLen}}(val)
193199 {{- end}}
194200 {{- else}}
@@ -232,7 +238,7 @@ func (g *codeGenerator) generate(root reflect.Type) error {
232238 // Also define map-marker constants for 1..6
233239 // We don't need more than this, and an error will be thrown if a
234240 // field grows beyond 6 items.
235- for i := 1 ; i <= 6 ; i ++ {
241+ for i := 0 ; i <= 6 ; i ++ {
236242 g .getOrCreateMapMarkerIndex (i )
237243 }
238244
0 commit comments