| 336 | } |
| 337 | |
| 338 | func (op uint256Op) genWrite(ctx *genContext, v string) string { |
| 339 | var b bytes.Buffer |
| 340 | |
| 341 | dst := v |
| 342 | if !op.pointer { |
| 343 | dst = "&" + v |
| 344 | } |
| 345 | fmt.Fprintf(&b, "w.WriteUint256(%s)\n", dst) |
| 346 | |
| 347 | // Wrap with nil check. |
| 348 | if op.pointer { |
| 349 | code := b.String() |
| 350 | b.Reset() |
| 351 | fmt.Fprintf(&b, "if %s == nil {\n", v) |
| 352 | fmt.Fprintf(&b, " w.Write(rlp.EmptyString)") |
| 353 | fmt.Fprintf(&b, "} else {\n") |
| 354 | fmt.Fprint(&b, code) |
| 355 | fmt.Fprintf(&b, "}\n") |
| 356 | } |
| 357 | |
| 358 | return b.String() |
| 359 | } |
| 360 | |
| 361 | func (op uint256Op) genDecode(ctx *genContext) (string, string) { |
| 362 | ctx.addImport("github.com/holiman/uint256") |