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