add seek-back handling in entity metadata decoding

This commit is contained in:
adman
2026-05-14 00:06:45 +02:00
parent a39999b344
commit d43ff7f83d
4 changed files with 19 additions and 4 deletions
+5
View File
@@ -578,6 +578,9 @@ func EntityMetadataLoopDecoder(g *Generator, varToSet ast.Expr, dataRaw any, nam
decodeIdStatements, err := g.VisitDecoder(Ident("id"), "u8", name)
endCheck := If(Equals(Ident("id"), NumLit(data.EndVal)), NewBlockEllipsis(Break()))
// r.Seek(-1, io.SeekCurrent)
seekBack := Assign(Exprs(Ident("_"), Ident("err")), Exprs(Call(Selector("r", "Seek"), NumLit(-1), Selector("io", "SeekCurrent"))))
declEntry := VarStmt("entry", innerType)
decodingEntryStmts, err := g.VisitDecoder(Ident("entry"), data.Type, name+"Inner")
if err != nil {
@@ -588,6 +591,8 @@ func EntityMetadataLoopDecoder(g *Generator, varToSet ast.Expr, dataRaw any, nam
var loopStmts []ast.Stmt
loopStmts = append(loopStmts, decodeIdStatements...)
loopStmts = append(loopStmts, endCheck)
loopStmts = append(loopStmts, seekBack)
loopStmts = append(loopStmts, IfErrNil())
loopStmts = append(loopStmts, declEntry)
loopStmts = append(loopStmts, decodingEntryStmts...)
loopStmts = append(loopStmts, assignEntry)