@@ -25,6 +25,7 @@ import (
25
25
"github.com/cockroachdb/cockroach/pkg/util/duration"
26
26
"github.com/cockroachdb/cockroach/pkg/util/encoding/encodingtype"
27
27
"github.com/cockroachdb/cockroach/pkg/util/ipaddr"
28
+ "github.com/cockroachdb/cockroach/pkg/util/ltree"
28
29
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
29
30
"github.com/cockroachdb/cockroach/pkg/util/timeofday"
30
31
"github.com/cockroachdb/cockroach/pkg/util/timetz"
@@ -1786,6 +1787,7 @@ const (
1786
1787
JsonEmptyArray Type = 42
1787
1788
JsonEmptyArrayDesc Type = 43
1788
1789
PGVector Type = 44
1790
+ LTree Type = 45
1789
1791
)
1790
1792
1791
1793
// typMap maps an encoded type byte to a decoded Type. It's got 256 slots, one
@@ -2840,6 +2842,22 @@ func EncodePGVectorValue(appendTo []byte, colIDDelta uint32, data []byte) []byte
2840
2842
return EncodeUntaggedBytesValue (appendTo , data )
2841
2843
}
2842
2844
2845
+ // EncodeLTreeValue encodes a ltree.T value with its value tag, appends it to
2846
+ // the supplied buffer, and returns the final buffer.
2847
+ func EncodeLTreeValue (appendTo []byte , colIDDelta uint32 , l ltree.T ) []byte {
2848
+ appendTo = EncodeValueTag (appendTo , colIDDelta , LTree )
2849
+ return EncodeUntaggedLTreeValue (appendTo , l )
2850
+ }
2851
+
2852
+ // EncodeUntaggedLTreeValue encodes a ltree.T value, appends it to the supplied
2853
+ // buffer, and returns the final buffer.
2854
+ func EncodeUntaggedLTreeValue (appendTo []byte , l ltree.T ) []byte {
2855
+ var buf bytes.Buffer
2856
+ l .FormatToBuffer (& buf )
2857
+ appendTo = EncodeUntaggedBytesValue (appendTo , buf .Bytes ())
2858
+ return appendTo
2859
+ }
2860
+
2843
2861
// DecodeValueTag decodes a value encoded by EncodeValueTag, used as a prefix in
2844
2862
// each of the other EncodeFooValue methods.
2845
2863
//
@@ -3189,6 +3207,28 @@ func DecodeUntaggedIPAddrValue(b []byte) (remaining []byte, u ipaddr.IPAddr, err
3189
3207
return remaining , u , err
3190
3208
}
3191
3209
3210
+ // DecodeLTreeValue decodes a value encoded by EncodeLTreeValue.
3211
+ func DecodeLTreeValue (b []byte ) (remaining []byte , l ltree.T , err error ) {
3212
+ b , err = decodeValueTypeAssert (b , LTree )
3213
+ if err != nil {
3214
+ return b , l , err
3215
+ }
3216
+ return DecodeUntaggedLTreeValue (b )
3217
+ }
3218
+
3219
+ // DecodeUntaggedLTreeValue decodes a value encoded by EncodeUntaggedLTreeValue.
3220
+ func DecodeUntaggedLTreeValue (b []byte ) (remaining []byte , l ltree.T , err error ) {
3221
+ remaining , data , err := DecodeUntaggedBytesValue (b )
3222
+ if err != nil {
3223
+ return b , l , err
3224
+ }
3225
+ l , err = ltree .ParseLTree (string (data ))
3226
+ if err != nil {
3227
+ return b , l , err
3228
+ }
3229
+ return remaining , l , nil
3230
+ }
3231
+
3192
3232
func decodeValueTypeAssert (b []byte , expected Type ) ([]byte , error ) {
3193
3233
_ , dataOffset , _ , typ , err := DecodeValueTag (b )
3194
3234
if err != nil {
@@ -3243,7 +3283,7 @@ func PeekValueLengthWithOffsetsAndType(b []byte, dataOffset int, typ Type) (leng
3243
3283
return dataOffset + n , err
3244
3284
case Float :
3245
3285
return dataOffset + floatValueEncodedLength , nil
3246
- case Bytes , Array , JSON , Geo , TSVector , TSQuery , PGVector :
3286
+ case Bytes , Array , JSON , Geo , TSVector , TSQuery , PGVector , LTree :
3247
3287
_ , n , i , err := DecodeNonsortingUvarint (b )
3248
3288
return dataOffset + n + int (i ), err
3249
3289
case Box2D :
0 commit comments