MCPcopy
hub / github.com/jackc/pgx / AppendValue

Method AppendValue

pgtype/composite.go:474–512  ·  view source on GitHub ↗
(oid uint32, field any)

Source from the content-addressed store, hash-verified

472}
473
474func (b *CompositeBinaryBuilder) AppendValue(oid uint32, field any) {
475 if b.err != nil {
476 return
477 }
478
479 isNil, callNilDriverValuer := isNilDriverValuer(field)
480 if isNil && !callNilDriverValuer {
481 b.buf = pgio.AppendUint32(b.buf, oid)
482 b.buf = pgio.AppendInt32(b.buf, -1)
483 b.fieldCount++
484 return
485 }
486
487 var plan EncodePlan
488 if isNil {
489 plan = &encodePlanDriverValuer{m: b.m, oid: oid, formatCode: BinaryFormatCode}
490 } else {
491 plan = b.m.PlanEncode(oid, BinaryFormatCode, field)
492 if plan == nil {
493 b.err = fmt.Errorf("unable to encode %v into OID %d in binary format", field, oid)
494 return
495 }
496 }
497
498 b.buf = pgio.AppendUint32(b.buf, oid)
499 lengthPos := len(b.buf)
500 b.buf = pgio.AppendInt32(b.buf, -1)
501 fieldBuf, err := plan.Encode(field, b.buf)
502 if err != nil {
503 b.err = err
504 return
505 }
506 if fieldBuf != nil {
507 binary.BigEndian.PutUint32(fieldBuf[lengthPos:], uint32(len(fieldBuf)-len(b.buf)))
508 b.buf = fieldBuf
509 }
510
511 b.fieldCount++
512}
513
514func (b *CompositeBinaryBuilder) Finish() ([]byte, error) {
515 if b.err != nil {

Callers 1

EncodeMethod · 0.95

Calls 5

EncodeMethod · 0.95
AppendUint32Function · 0.92
AppendInt32Function · 0.92
isNilDriverValuerFunction · 0.85
PlanEncodeMethod · 0.65

Tested by

no test coverage detected