Repository: amzn/ion-go
Pull request #160 (2020-09-15 19:26:17)

Remove Uint64 int type
Resolves https://github.com/amzn/ion-go/issues/102

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.



Armanbqt: If we decided to remove Unit64, we might have to remove its corresponding values in ```type.go``` as well.
justing-bq: > If we decided to remove Unit64, we might have to remove its corresponding values in `type.go` as well.

I did.
codecov-commenter: # [Codecov](https://codecov.io/gh/amzn/ion-go/pull/160?src=pr&el=h1) Report
> Merging [#160](https://codecov.io/gh/amzn/ion-go/pull/160?src=pr&el=desc) into [master](https://codecov.io/gh/amzn/ion-go/commit/121885273a78458ae2a0c76853f0f297a112453e?el=desc) will **increase** coverage by `0.14%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/amzn/ion-go/pull/160/graphs/tree.svg?width=650&height=150&src=pr&token=OBDT1TNoNE)](https://codecov.io/gh/amzn/ion-go/pull/160?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #160      +/-   ##
==========================================
+ Coverage   76.99%   77.13%   +0.14%     
==========================================
  Files          25       25              
  Lines        5424     5402      -22     
==========================================
- Hits         4176     4167       -9     
+ Misses        747      739       -8     
+ Partials      501      496       -5     
```


| [Impacted Files](https://codecov.io/gh/amzn/ion-go/pull/160?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [ion/reader.go](https://codecov.io/gh/amzn/ion-go/pull/160/diff?src=pr&el=tree#diff-aW9uL3JlYWRlci5nbw==) | `71.77% <ø> (+5.10%)` | :arrow_up: |
| [ion/type.go](https://codecov.io/gh/amzn/ion-go/pull/160/diff?src=pr&el=tree#diff-aW9uL3R5cGUuZ28=) | `100.00% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/amzn/ion-go/pull/160?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/amzn/ion-go/pull/160?src=pr&el=footer). Last update [1218852...23759b4](https://codecov.io/gh/amzn/ion-go/pull/160?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/cmd/ion-go/process.go b/cmd/ion-go/process.go
index 88d1af6..b48741d 100644
--- a/cmd/ion-go/process.go
+++ b/cmd/ion-go/process.go
@@ -268,13 +268,6 @@ func (p *processor) process(in ion.Reader) error {
 				}
 				err = p.out.WriteInt(*val)
 
-			case ion.Uint64:
-				val, err := in.Uint64Value()
-				if err != nil {
-					return p.error(read, err)
-				}
-				err = p.out.WriteUint(*val)
-
 			case ion.BigInt:
 				val, err := in.BigIntValue()
 				if err != nil {
diff --git a/ion/reader.go b/ion/reader.go
index 6f43584..42417fc 100644
--- a/ion/reader.go
+++ b/ion/reader.go
@@ -123,11 +123,6 @@ type Reader interface {
 	// or requires more than 64 bits to represent losslessly.
 	Int64Value() (*int64, error)
 
-	// Uint64Value returns the current value as an unsigned 64-bit integer (if that makes
-	// sense). It returns nil if the value is an Ion null. It returns an error if the current value
-	// is not an Ion integer, is negative, or requires more than 64 bits to represent losslessly.
-	Uint64Value() (*uint64, error)
-
 	// BigIntValue returns the current value as a big.Integer (if that makes sense). It returns
 	// nil if the value is an Ion null. It returns an error if the current value is not an Ion integer.
 	BigIntValue() (*big.Int, error)
@@ -265,11 +260,6 @@ func (r *reader) IntSize() (IntSize, error) {
 		return Int32, nil
 	}
 
-	i := r.value.(*big.Int)
-	if i.IsUint64() {
-		return Uint64, nil
-	}
-
 	return BigInt, nil
 }
 
@@ -308,34 +298,6 @@ func (r *reader) Int64Value() (*int64, error) {
 	return nil, &UsageError{"Reader.Int64Value", "value too large for an int64"}
 }
 
-// Uint64Value returns the current value as a uint64.
-func (r *reader) Uint64Value() (*uint64, error) {
-	if r.valueType != IntType {
-		return nil, &UsageError{"Reader.Uint64Value", "value is not an Ion int"}
-	}
-	if r.value == nil {
-		return nil, nil
-	}
-
-	if i, ok := r.value.(int64); ok {
-		if i >= 0 {
-			val := uint64(i)
-			return &val, nil
-		}
-		return nil, &UsageError{"Reader.Uint64Value", "value is negative"}
-	}
-
-	bi := r.value.(*big.Int)
-	if bi.Sign() < 0 {
-		return nil, &UsageError{"Reader.Uint64Value", "value is negative"}
-	}
-	if !bi.IsUint64() {
-		return nil, &UsageError{"Reader.Uint64Value", "value too large for a uint64"}
-	}
-	val := bi.Uint64()
-	return &val, nil
-}
-
 // BigIntValue returns the current value as a big int.
 func (r *reader) BigIntValue() (*big.Int, error) {
 	if r.valueType != IntType {
diff --git a/ion/type.go b/ion/type.go
index 8462585..d7bc0ae 100644
--- a/ion/type.go
+++ b/ion/type.go
@@ -125,8 +125,6 @@ const (
 	Int32
 	// Int64 is the size of an Ion integer that can be losslessly stored in an int64.
 	Int64
-	// Uint64 is the size of an Ion integer that can be losslessly stored in a uint64.
-	Uint64
 	// BigInt is the size of an Ion integer that can only be losslessly stored in a big.Int.
 	BigInt
 )
@@ -140,8 +138,6 @@ func (i IntSize) String() string {
 		return "int32"
 	case Int64:
 		return "int64"
-	case Uint64:
-		return "uint64"
 	case BigInt:
 		return "big.Int"
 	default:


Test patch:
diff --git a/ion/binaryreader_test.go b/ion/binaryreader_test.go
index 36135e9..27d477e 100644
--- a/ion/binaryreader_test.go
+++ b/ion/binaryreader_test.go
@@ -456,9 +456,8 @@ func TestReadBinaryInts(t *testing.T) {
 	_int64(t, r, math.MaxInt64)
 	_int64(t, r, -math.MaxInt64)
 
-	_uint(t, r, math.MaxInt64+1)
-
 	i := new(big.Int).SetUint64(math.MaxInt64 + 1)
+	_bigInt(t, r, i)
 	_bigInt(t, r, new(big.Int).Neg(i))
 
 	_eof(t, r)
diff --git a/ion/integration_test.go b/ion/integration_test.go
index c28fa1c..0bfd7f8 100644
--- a/ion/integration_test.go
+++ b/ion/integration_test.go
@@ -507,16 +507,6 @@ func writeFromReaderToWriter(t *testing.T, reader Reader, writer Writer) {
 				if err != nil {
 					t.Errorf("Something went wrong while writing an Int value: " + err.Error())
 				}
-			case Uint64:
-				val, err := reader.Uint64Value()
-				if err != nil {
-					t.Errorf("Something went wrong while reading a UInt value: " + err.Error())
-				}
-
-				err = writer.WriteUint(*val)
-				if err != nil {
-					t.Errorf("Something went wrong while writing a UInt value: " + err.Error())
-				}
 			case BigInt:
 				val, err := reader.BigIntValue()
 				if err != nil {
diff --git a/ion/textreader_test.go b/ion/textreader_test.go
index f0c1e91..d13cae6 100644
--- a/ion/textreader_test.go
+++ b/ion/textreader_test.go
@@ -678,33 +678,6 @@ func _int64AF(t *testing.T, r Reader, efn *SymbolToken, etas []SymbolToken, eval
 	}
 }
 
-func _uint(t *testing.T, r Reader, eval uint64) {
-	_uintAF(t, r, nil, nil, eval)
-}
-
-func _uintAF(t *testing.T, r Reader, efn *SymbolToken, etas []SymbolToken, eval uint64) {
-	_nextAF(t, r, IntType, efn, etas)
-	if r.IsNull() {
-		t.Fatalf("expected %v, got null.int", eval)
-	}
-
-	size, err := r.IntSize()
-	if err != nil {
-		t.Fatal(err)
-	}
-	if size != Uint64 {
-		t.Errorf("expected size=Uint, got %v", size)
-	}
-
-	val, err := r.Uint64Value()
-	if err != nil {
-		t.Fatal(err)
-	}
-	if *val != eval {
-		t.Errorf("expected %v, got %v", eval, *val)
-	}
-}
-
 func _bigInt(t *testing.T, r Reader, eval *big.Int) {
 	_bigIntAF(t, r, nil, nil, eval)
 }