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)
| 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 |
| 106 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…