github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/types/int.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 // Int is a Noms Value wrapper around the primitive int32 type. 32 type Int int64 33 34 // Value interface 35 func (v Int) Value(ctx context.Context) (Value, error) { 36 return v, nil 37 } 38 39 func (v Int) Equals(other Value) bool { 40 return v == other 41 } 42 43 func (v Int) Less(nbf *NomsBinFormat, other LesserValuable) (bool, error) { 44 if v2, ok := other.(Int); ok { 45 return v < v2, nil 46 } 47 return IntKind < other.Kind(), nil 48 } 49 50 func (v Int) Hash(nbf *NomsBinFormat) (hash.Hash, error) { 51 return getHash(v, nbf) 52 } 53 54 func (v Int) isPrimitive() bool { 55 return true 56 } 57 58 func (v Int) WalkValues(ctx context.Context, cb ValueCallback) error { 59 return nil 60 } 61 62 func (v Int) WalkRefs(nbf *NomsBinFormat, cb RefCallback) error { 63 return nil 64 } 65 66 func (v Int) typeOf() (*Type, error) { 67 return PrimitiveTypeMap[IntKind], nil 68 } 69 70 func (v Int) Kind() NomsKind { 71 return IntKind 72 } 73 74 func (v Int) valueReadWriter() ValueReadWriter { 75 return nil 76 } 77 78 func (v Int) writeTo(w nomsWriter, nbf *NomsBinFormat) error { 79 err := IntKind.writeTo(w, nbf) 80 81 if err != nil { 82 return err 83 } 84 85 w.writeInt(v) 86 87 return nil 88 } 89 90 func (v Int) readFrom(nbf *NomsBinFormat, b *binaryNomsReader) (Value, error) { 91 return Int(b.ReadInt()), nil 92 } 93 94 func (v Int) skip(nbf *NomsBinFormat, b *binaryNomsReader) { 95 b.skipInt() 96 } 97 98 func (v Int) HumanReadableString() string { 99 return strconv.FormatInt(int64(v), 10) 100 }