MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / EncodeDurationAscending

Function EncodeDurationAscending

pkg/util/encoding/encoding.go:1510–1522  ·  view source on GitHub ↗

EncodeDurationAscending encodes a duration.Duration value, appends it to the supplied buffer, and returns the final buffer. The encoding is guaranteed to be ordered such that if t1.Compare(t2) < 0 (or = 0 or > 0) then bytes.Compare will order them the same way after encoding.

(b []byte, d duration.Duration)

Source from the content-addressed store, hash-verified

1508// be ordered such that if t1.Compare(t2) < 0 (or = 0 or > 0) then bytes.Compare
1509// will order them the same way after encoding.
1510func EncodeDurationAscending(b []byte, d duration.Duration) ([]byte, error) {
1511 sortNanos, months, days, err := d.Encode()
1512 if err != nil {
1513 // TODO(dan): Handle this using d.EncodeBigInt() and the
1514 // durationBigNeg/durationBigPos markers.
1515 return b, err
1516 }
1517 b = append(b, durationMarker)
1518 b = EncodeVarintAscending(b, sortNanos)
1519 b = EncodeVarintAscending(b, months)
1520 b = EncodeVarintAscending(b, days)
1521 return b, nil
1522}
1523
1524// EncodeDurationDescending is the descending version of EncodeDurationAscending.
1525func EncodeDurationDescending(b []byte, d duration.Duration) ([]byte, error) {

Callers

nothing calls this directly

Calls 2

EncodeVarintAscendingFunction · 0.85
EncodeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…