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

Function DecodeTSVectorPGBinary

pkg/util/tsearch/encoding.go:128–165  ·  view source on GitHub ↗

DecodeTSVectorPGBinary decodes a tsvector from the input byte slice which is formatted in Postgres binary protocol.

(b []byte)

Source from the content-addressed store, hash-verified

126// DecodeTSVectorPGBinary decodes a tsvector from the input byte slice which is
127// formatted in Postgres binary protocol.
128func DecodeTSVectorPGBinary(b []byte) (ret TSVector, err error) {
129 var nTerms uint32
130 var nPositions, position uint16
131 b, nTerms, err = encoding.DecodeUint32Ascending(b)
132 if err != nil {
133 return nil, err
134 }
135 ret = make([]tsTerm, nTerms)
136 for i := uint32(0); i < nTerms; i++ {
137 termIndex := bytes.IndexByte(b, byte(0))
138 if termIndex == -1 {
139 return nil, pgerror.Newf(pgcode.Syntax, "unterminated string while parsing tsvector: %s", b)
140 }
141 term := &ret[i]
142 term.lexeme = string(b[:termIndex])
143 b = b[termIndex+1:]
144 b, nPositions, err = encoding.DecodeUint16Ascending(b)
145 if err != nil {
146 return nil, err
147 }
148 term.positions = make([]tsPosition, nPositions)
149 for j := uint16(0); j < nPositions; j++ {
150 b, position, err = encoding.DecodeUint16Ascending(b)
151 if err != nil {
152 return nil, err
153 }
154 encodedWeight := position >> 14
155 weight, err := tsWeightFromVectorPGEncoding(byte(encodedWeight))
156 if err != nil {
157 return nil, err
158 }
159 // Clear the 2 most significant bits (they were used for the weight).
160 position = position & (^(uint16(3) << 14))
161 term.positions[j] = tsPosition{position: position, weight: weight}
162 }
163 }
164 return ret, nil
165}
166
167// EncodeTSQuery encodes a tsquery into a serialized representation for on-disk
168// storage.

Callers

nothing calls this directly

Calls 4

DecodeUint32AscendingFunction · 0.92
NewfFunction · 0.92
DecodeUint16AscendingFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…