github.com/matrixorigin/matrixone@v1.2.0/pkg/objectio/metav3.go (about) 1 // Copyright 2021 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 objectio 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/types" 19 ) 20 21 type objectMetaV3 []byte 22 23 func buildObjectMetaV3() objectMetaV3 { 24 var buf [metaHeaderLen]byte 25 return buf[:] 26 } 27 28 func (mh objectMetaV3) MustGetMeta(metaType DataMetaType) objectDataMetaV1 { 29 if metaType == SchemaData { 30 return mh.MustDataMeta() 31 } else if metaType == SchemaTombstone { 32 return mh.MustTombstoneMeta() 33 } 34 return nil 35 } 36 37 func (mh objectMetaV3) HeaderLength() uint32 { 38 return metaHeaderLen 39 } 40 41 func (mh objectMetaV3) DataMetaCount() uint16 { 42 return types.DecodeUint16(mh[:dataMetaCount]) 43 } 44 45 func (mh objectMetaV3) TombstoneMetaCount() uint16 { 46 return types.DecodeUint16(mh[tombstoneMetaCountOff : tombstoneMetaCountOff+tombstoneMetaCount]) 47 } 48 49 func (mh objectMetaV3) DataMeta() (objectDataMetaV1, bool) { 50 if mh.DataMetaCount() == 0 { 51 return nil, false 52 } 53 offset := types.DecodeUint32(mh[dataMetaCount:tombstoneMetaCountOff]) 54 return objectDataMetaV1(mh[offset:]), true 55 } 56 57 func (mh objectMetaV3) MustDataMeta() objectDataMetaV1 { 58 meta, ok := mh.DataMeta() 59 if !ok { 60 panic("no data meta") 61 } 62 return meta 63 } 64 65 func (mh objectMetaV3) TombstoneMeta() (objectDataMetaV1, bool) { 66 if mh.TombstoneMetaCount() == 0 { 67 return nil, false 68 } 69 offset := types.DecodeUint32(mh[tombstoneMetaCountOff+tombstoneMetaCount : metaDummyOff]) 70 return objectDataMetaV1(mh[offset:]), true 71 } 72 73 func (mh objectMetaV3) MustTombstoneMeta() objectDataMetaV1 { 74 meta, ok := mh.TombstoneMeta() 75 if !ok { 76 panic("no tombstone meta") 77 } 78 return meta 79 } 80 81 func (mh objectMetaV3) SetDataMetaCount(count uint16) { 82 copy(mh[:dataMetaCount], types.EncodeUint16(&count)) 83 } 84 85 func (mh objectMetaV3) SetDataMetaOffset(offset uint32) { 86 copy(mh[dataMetaCount:dataMetaCount+dataMetaOffset], types.EncodeUint32(&offset)) 87 } 88 89 func (mh objectMetaV3) SetTombstoneMetaCount(count uint16) { 90 copy(mh[tombstoneMetaCountOff:tombstoneMetaCountOff+tombstoneMetaCount], types.EncodeUint16(&count)) 91 } 92 93 func (mh objectMetaV3) SetTombstoneMetaOffset(offset uint32) { 94 copy(mh[tombstoneMetaCountOff+tombstoneMetaCount:tombstoneMetaCountOff+tombstoneMetaCount+tombstoneMetaOffset], types.EncodeUint32(&offset)) 95 } 96 97 func (mh objectMetaV3) SubMeta(pos uint16) (objectDataMetaV1, bool) { 98 offStart := schemaCountLen + uint32(pos)*typePosLen + schemaType + schemaBlockCount + metaHeaderLen 99 offEnd := schemaCountLen + uint32(pos)*typePosLen + typePosLen + metaHeaderLen 100 offset := types.DecodeUint32(mh[offStart:offEnd]) 101 return objectDataMetaV1(mh[offset:]), true 102 } 103 104 func (mh objectMetaV3) SubMetaCount() uint16 { 105 return types.DecodeUint16(mh[metaHeaderLen : metaHeaderLen+schemaCountLen]) 106 } 107 108 func (mh objectMetaV3) SubMetaIndex() SubMetaIndex { 109 return SubMetaIndex(mh[metaHeaderLen:]) 110 } 111 112 func (mh objectMetaV3) SubMetaTypes() []uint16 { 113 cnt := mh.SubMetaCount() 114 subMetaTypes := make([]uint16, cnt) 115 for i := uint16(0); i < cnt; i++ { 116 offStart := schemaCountLen + i*typePosLen + metaHeaderLen 117 offEnd := schemaCountLen + i*typePosLen + schemaType + metaHeaderLen 118 subMetaTypes[i] = types.DecodeUint16(mh[offStart:offEnd]) 119 } 120 return subMetaTypes 121 }