readBytesWithLimit will read bytes into vname. Returns field to check for nil.
(vname string, fieldLimit uint32)
| 144 | // readBytesWithLimit will read bytes into vname. |
| 145 | // Returns field to check for nil. |
| 146 | func (d *decodeGen) readBytesWithLimit(vname string, fieldLimit uint32) string { |
| 147 | if !d.p.ok() { |
| 148 | return "" |
| 149 | } |
| 150 | |
| 151 | // Determine effective limit: field limit > context field limit > file limit |
| 152 | var limit uint32 |
| 153 | var limitName string |
| 154 | |
| 155 | if fieldLimit > 0 { |
| 156 | // Explicit field limit passed as parameter |
| 157 | limit = fieldLimit |
| 158 | limitName = fmt.Sprintf("%d", fieldLimit) |
| 159 | } else if d.ctx.currentFieldArrayLimit != math.MaxUint32 { |
| 160 | // Field limit from context (set during field processing) |
| 161 | limit = d.ctx.currentFieldArrayLimit |
| 162 | limitName = fmt.Sprintf("%d", d.ctx.currentFieldArrayLimit) |
| 163 | } else if d.ctx.arrayLimit != math.MaxUint32 { |
| 164 | // File-level limit |
| 165 | limit = d.ctx.arrayLimit |
| 166 | limitName = fmt.Sprintf("%slimitArrays", d.ctx.limitPrefix) |
| 167 | } |
| 168 | |
| 169 | // Choose reading strategy based on whether limits exist |
| 170 | if limit > 0 && limit != math.MaxUint32 { |
| 171 | d.p.printf("\n%s, err = dc.ReadBytesLimit(%s, %s)", vname, vname, limitName) |
| 172 | // field cannot be nil |
| 173 | d.p.printf("\nif err == nil && %s == nil {", vname) |
| 174 | d.p.printf("\n%s = []byte{}", vname) |
| 175 | d.p.printf("\n}") |
| 176 | return "" |
| 177 | } else { |
| 178 | // No limits - use original direct reading approach for efficiency |
| 179 | d.p.printf("\n%s, err = dc.ReadBytes(%s)", vname, vname) |
| 180 | return vname |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | func (d *decodeGen) structAsTuple(s *Struct) { |
| 185 | sz := randIdent() |