From 711ac30486487856fbc990a674d1b7bb99ea3880 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 4 Aug 2025 12:26:16 -0400 Subject: [PATCH] generate: Add branch decode function request queue --- generate/generate.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/generate/generate.go b/generate/generate.go index ae36942..8cb081a 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -47,6 +47,13 @@ type Generator struct { nestingLevel int temporaryVar int protocol *Protocol + + decodeBranchRequestQueue []decodeBranchRequest +} + +type decodeBranchRequest struct { + hash [16]byte + typ Type } func (this *Generator) Generate(protocol *Protocol) (n int, err error) { @@ -531,13 +538,29 @@ func (this *Generator) generateDecodeBranch(typ Type, valueSource, tagSource str n += nn; if err != nil { return n, err } nn, err = this.generateErrorCheck() n += nn; if err != nil { return n, err } - // TODO: define this function to check if the hash exists in the - // request queue, and if not, put it at the back. then, when we actually - // generate these, continually pick items from the front. this.pushDecodeBranchRequest(hash, typ) return n, nil } +func (this *Generator) pushDecodeBranchRequest(hash [16]byte, typ Type) { + for _, item := range this.decodeBranchRequestQueue { + if item.hash == hash { return } + } + this.decodeBranchRequestQueue = append(this.decodeBranchRequestQueue, decodeBranchRequest { + hash: hash, + typ: typ, + }) +} + +func (this *Generator) pullDecodeBranchRequest() (hash [16]byte, typ Type, ok bool) { + if len(this.decodeBranchRequestQueue) < 1 { + return [16]byte { }, nil, false + } + request := this.decodeBranchRequestQueue[0] + this.decodeBranchRequestQueue = this.decodeBranchRequestQueue[1:] + return request.hash, request.typ, true +} + func (this *Generator) generateErrorCheck() (n int, err error) { return this.iprintf("n += nn; if err != nil { return n, err }\n") }