generate: Add branch decode function request queue
This commit is contained in:
parent
b15c3aa76c
commit
711ac30486
@ -47,6 +47,13 @@ type Generator struct {
|
|||||||
nestingLevel int
|
nestingLevel int
|
||||||
temporaryVar int
|
temporaryVar int
|
||||||
protocol *Protocol
|
protocol *Protocol
|
||||||
|
|
||||||
|
decodeBranchRequestQueue []decodeBranchRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
type decodeBranchRequest struct {
|
||||||
|
hash [16]byte
|
||||||
|
typ Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Generator) Generate(protocol *Protocol) (n int, err error) {
|
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 }
|
n += nn; if err != nil { return n, err }
|
||||||
nn, err = this.generateErrorCheck()
|
nn, err = this.generateErrorCheck()
|
||||||
n += nn; if err != nil { return n, err }
|
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)
|
this.pushDecodeBranchRequest(hash, typ)
|
||||||
return n, nil
|
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) {
|
func (this *Generator) generateErrorCheck() (n int, err error) {
|
||||||
return this.iprintf("n += nn; if err != nil { return n, err }\n")
|
return this.iprintf("n += nn; if err != nil { return n, err }\n")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user