github.com/pingcap/tidb/parser@v0.0.0-20231013125129-93a834a6bf8d/charset/encoding_bin.go (about) 1 // Copyright 2021 PingCAP, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package charset 15 16 import ( 17 "bytes" 18 19 "golang.org/x/text/encoding" 20 ) 21 22 // EncodingBinImpl is the instance of encodingBin. 23 var EncodingBinImpl = &encodingBin{encodingBase{enc: encoding.Nop}} 24 25 func init() { 26 EncodingBinImpl.self = EncodingBinImpl 27 } 28 29 // encodingBin is the binary encoding. 30 type encodingBin struct { 31 encodingBase 32 } 33 34 // Name implements Encoding interface. 35 func (*encodingBin) Name() string { 36 return CharsetBin 37 } 38 39 // Tp implements Encoding interface. 40 func (*encodingBin) Tp() EncodingTp { 41 return EncodingTpBin 42 } 43 44 // Peek implements Encoding interface. 45 func (*encodingBin) Peek(src []byte) []byte { 46 if len(src) == 0 { 47 return src 48 } 49 return src[:1] 50 } 51 52 // IsValid implements Encoding interface. 53 func (*encodingBin) IsValid(_ []byte) bool { 54 return true 55 } 56 57 // Foreach implements Encoding interface. 58 func (*encodingBin) Foreach(src []byte, _ Op, fn func(from, to []byte, ok bool) bool) { 59 for i := 0; i < len(src); i++ { 60 if !fn(src[i:i+1], src[i:i+1], true) { 61 return 62 } 63 } 64 } 65 66 func (*encodingBin) Transform(_ *bytes.Buffer, src []byte, _ Op) ([]byte, error) { 67 return src, nil 68 }