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

Function EncodeTSVectorPGBinary

pkg/util/tsearch/encoding.go:106–124  ·  view source on GitHub ↗

EncodeTSVectorPGBinary encodes a tsvector into a serialized representation that's identical to Postgres's wire protocol representation. The below comment explains the wire protocol representation. It is taken from this page: https://www.npgsql.org/dev/types.html tsvector: UInt32 number of lexeme

(appendTo []byte, vector TSVector)

Source from the content-addressed store, hash-verified

104// for each position:
105// UInt16 WordEntryPos, where the most significant 2 bits is weight, and the 14 least significant bits is pos (can't be 0). Weights 3,2,1,0 represent A,B,C,D
106func EncodeTSVectorPGBinary(appendTo []byte, vector TSVector) ([]byte, error) {
107 appendTo = encoding.EncodeUint32Ascending(appendTo, uint32(len(vector)))
108 for _, term := range vector {
109 l := term.lexeme
110 appendTo = append(appendTo, []byte(l)...)
111 appendTo = append(appendTo, byte(0))
112 i := len(term.positions)
113 appendTo = encoding.EncodeUint16Ascending(appendTo, uint16(i))
114 for _, pos := range term.positions {
115 weight, err := pos.weight.TSVectorPGEncoding()
116 if err != nil {
117 return nil, err
118 }
119 out := pos.position | (uint16(weight) << 14)
120 appendTo = encoding.EncodeUint16Ascending(appendTo, out)
121 }
122 }
123 return appendTo, nil
124}
125
126// DecodeTSVectorPGBinary decodes a tsvector from the input byte slice which is
127// formatted in Postgres binary protocol.

Callers

nothing calls this directly

Calls 3

EncodeUint32AscendingFunction · 0.92
EncodeUint16AscendingFunction · 0.92
TSVectorPGEncodingMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…