github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/containers/tools.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 containers 16 17 import ( 18 "bytes" 19 "io" 20 21 "github.com/matrixorigin/matrixone/pkg/container/types" 22 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 23 ) 24 25 func GetValueFrom[T types.FixedSizeT](tool *CodecTool, i int) (v T) { 26 buf := tool.Get(i) 27 v = types.DecodeFixed[T](buf) 28 return 29 } 30 31 type CodecTool struct { 32 storage *vector[[]byte] 33 } 34 35 func NewCodecTool() *CodecTool { 36 return &CodecTool{ 37 storage: NewVector[[]byte](types.T_char.ToType(), false), 38 } 39 } 40 41 func (tool *CodecTool) Close() { tool.storage.Close() } 42 func (tool *CodecTool) Reset() { tool.storage.Reset() } 43 func (tool *CodecTool) Write(buf []byte) (n int, err error) { 44 tool.storage.Append(buf) 45 n = len(buf) 46 return 47 } 48 49 func (tool *CodecTool) WriteTo(w io.Writer) (n int64, err error) { 50 return tool.storage.WriteTo(w) 51 } 52 53 func (tool *CodecTool) ReadFrom(r io.Reader) (n int64, err error) { 54 return tool.storage.ReadFrom(r) 55 } 56 57 func (tool *CodecTool) ReadFromFile(f common.IVFile, buffer *bytes.Buffer) (err error) { 58 return tool.storage.ReadFromFile(f, buffer) 59 } 60 61 func (tool *CodecTool) Allocated() int { return tool.storage.Allocated() } 62 func (tool *CodecTool) Elements() int { return tool.storage.Length() } 63 func (tool *CodecTool) Get(i int) []byte { return any(tool.storage.Get(i)).([]byte) } 64 func (tool *CodecTool) Update(i int, buf []byte) { tool.storage.Update(i, buf) } 65 func (tool *CodecTool) Delete(i int) { tool.storage.Delete(i) }