github.com/matrixorigin/matrixone@v1.2.0/pkg/container/bytejson/types.go (about) 1 // Copyright 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package bytejson 16 17 import ( 18 "encoding/binary" 19 ) 20 21 type TpCode byte 22 type subPathType byte 23 type pathFlag byte 24 25 type ByteJson struct { 26 Data []byte 27 Type TpCode 28 } 29 type kv struct { 30 key string 31 val interface{} 32 } 33 34 type subPathIndices struct { 35 tp byte 36 num int 37 } 38 type subPathRangeExpr struct { 39 start *subPathIndices 40 end *subPathIndices 41 } 42 43 type subPath struct { 44 key string 45 idx *subPathIndices 46 iRange *subPathRangeExpr 47 tp subPathType 48 } 49 type Path struct { 50 paths []subPath 51 flag pathFlag 52 } 53 type pathGenerator struct { 54 pathStr string 55 pos int 56 } 57 58 type UnnestResult map[string][]byte 59 60 const ( 61 numberIndices byte = iota + 1 62 lastIndices 63 lastKey = "last" 64 lastKeyLen = 4 65 toKey = "to" 66 toKeyLen = 2 67 ) 68 69 const ( 70 subPathIdxALL = -1 71 subPathIdxErr = -2 72 ) 73 74 const ( 75 subPathDoubleStar subPathType = iota + 1 76 subPathIdx 77 subPathKey 78 subPathRange 79 ) 80 const ( 81 pathFlagSingleStar pathFlag = iota + 1 82 pathFlagDoubleStar 83 ) 84 85 const ( 86 TpCodeObject TpCode = 0x01 87 TpCodeArray TpCode = 0x03 88 TpCodeLiteral TpCode = 0x04 89 TpCodeInt64 TpCode = 0x09 90 TpCodeUint64 TpCode = 0x0a 91 TpCodeFloat64 TpCode = 0x0b 92 TpCodeString TpCode = 0x0c 93 ) 94 95 const ( 96 headerSize = 8 // element size + data size. 97 docSizeOff = 4 // 98 keyEntrySize = 6 // keyOff + keyLen 99 keyOriginOff = 4 // offset -> uint32 100 valTypeSize = 1 // TpCode -> byte 101 valEntrySize = 5 // TpCode + offset-or-inline-value 102 numberSize = 8 // float64|int64|uint64 103 ) 104 105 const ( 106 LiteralNull byte = iota + 1 107 LiteralTrue 108 LiteralFalse 109 ) 110 111 var ( 112 endian = binary.LittleEndian 113 ) 114 115 var ( 116 Null = ByteJson{Type: TpCodeLiteral, Data: []byte{LiteralNull}} 117 ) 118 119 var ( 120 escapedChars = map[byte]byte{ 121 '"': '"', 122 'b': '\b', 123 'f': '\f', 124 'n': '\n', 125 'r': '\r', 126 't': '\t', 127 } 128 )