binaryAppendCall generates code for appender interfaces that use pre-allocated buffer. We optimize for cases where the size is 0-256 bytes.
(vname, method, appendFunc string)
| 433 | // binaryAppendCall generates code for appender interfaces that use pre-allocated buffer. |
| 434 | // We optimize for cases where the size is 0-256 bytes. |
| 435 | func (m *marshalGen) binaryAppendCall(vname, method, appendFunc string) { |
| 436 | sz := randIdent() |
| 437 | vname = strings.Trim(vname, "(*)") |
| 438 | // Reserve 2 bytes for the header bin8 or str8. |
| 439 | m.p.printf("\no = append(o, 0, 0); %s := len(o)", sz) |
| 440 | m.p.printf("\no, err = %s.%s(o)", vname, method) |
| 441 | m.p.wrapErrCheck(m.ctx.ArgsStr()) |
| 442 | m.p.printf("\n%s = len(o) - %s", sz, sz) |
| 443 | if appendFunc == "msgp.AppendString" { |
| 444 | m.p.printf("\no = msgp.AppendBytesStringTwoPrefixed(o, %s)", sz) |
| 445 | } else { |
| 446 | m.p.printf("\no = msgp.AppendBytesTwoPrefixed(o, %s)", sz) |
| 447 | } |
| 448 | } |
no test coverage detected