github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/types/bool.go (about) 1 // Copyright 2019 Dolthub, 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 // 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 // This file incorporates work covered by the following copyright and 16 // permission notice: 17 // 18 // Copyright 2016 Attic Labs, Inc. All rights reserved. 19 // Licensed under the Apache License, version 2.0: 20 // http://www.apache.org/licenses/LICENSE-2.0 21 22 package types 23 24 import ( 25 "context" 26 "strconv" 27 28 "github.com/dolthub/dolt/go/store/hash" 29 ) 30 31 // Bool is a Noms Value wrapper around the primitive bool type. 32 type Bool bool 33 34 // Value interface 35 func (b Bool) Value(ctx context.Context) (Value, error) { 36 return b, nil 37 } 38 39 func (b Bool) Equals(other Value) bool { 40 return b == other 41 } 42 43 func (b Bool) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error) { 44 if b2, ok := other.(Bool); ok { 45 return !bool(b) && bool(b2), nil 46 } 47 return true, nil 48 } 49 50 func (b Bool) Hash(nbf *NomsBinFormat) (hash.Hash, error) { 51 return getHash(b, nbf) 52 } 53 54 func (b Bool) isPrimitive() bool { 55 return true 56 } 57 58 func (b Bool) WalkValues(ctx context.Context, cb ValueCallback) error { 59 return nil 60 } 61 62 func (b Bool) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error { 63 return nil 64 } 65 66 func (b Bool) typeOf() (*Type, error) { 67 return PrimitiveTypeMap[BoolKind], nil 68 } 69 70 func (b Bool) Kind() NomsKind { 71 return BoolKind 72 } 73 74 func (b Bool) valueReadWriter() ValueReadWriter { 75 return nil 76 } 77 78 func (b Bool) writeTo(w nomsWriter, nbf *NomsBinFormat) error { 79 err := BoolKind.writeTo(w, nbf) 80 81 if err != nil { 82 return err 83 } 84 85 w.writeBool(bool(b)) 86 87 return nil 88 } 89 90 func (b Bool) readFrom(nbf *NomsBinFormat, bnr *binaryNomsReader) (Value, error) { 91 return Bool(bnr.ReadBool()), nil 92 } 93 94 func (b Bool) skip(nbf *NomsBinFormat, bnr *binaryNomsReader) { 95 bnr.skipUint8() 96 } 97 98 func (b Bool) HumanReadableString() string { 99 return strconv.FormatBool(bool(b)) 100 }