@@ -63,10 +63,10 @@ func (t *TupleDecimal) DecodeMsgpack(d *msgpack.Decoder) error {
63
63
return err
64
64
}
65
65
66
- if dec , ok := res .(* Decimal ); ! ok {
66
+ if dec , ok := res .(Decimal ); ! ok {
67
67
return fmt .Errorf ("decimal doesn't match" )
68
68
} else {
69
- t .number = * dec
69
+ t .number = dec
70
70
}
71
71
return nil
72
72
}
@@ -143,12 +143,12 @@ var decimalSamples = []struct {
143
143
func TestMPEncodeDecode (t * testing.T ) {
144
144
for _ , testcase := range benchmarkSamples {
145
145
t .Run (testcase .numString , func (t * testing.T ) {
146
- decNum , err := NewDecimalFromString (testcase .numString )
146
+ decNum , err := MakeDecimalFromString (testcase .numString )
147
147
if err != nil {
148
148
t .Fatal (err )
149
149
}
150
150
var buf []byte
151
- tuple := TupleDecimal {number : * decNum }
151
+ tuple := TupleDecimal {number : decNum }
152
152
if buf , err = msgpack .Marshal (& tuple ); err != nil {
153
153
t .Fatalf ("Failed to msgpack.Encoder decimal number '%s' to a MessagePack buffer: %s" , testcase .numString , err )
154
154
}
@@ -251,7 +251,7 @@ func TestEncodeStringToBCDIncorrectNumber(t *testing.T) {
251
251
func TestEncodeMaxNumber (t * testing.T ) {
252
252
referenceErrMsg := "msgpack: decimal number is bigger than maximum supported number (10^38 - 1)"
253
253
decNum := decimal .New (1 , DecimalPrecision ) // // 10^DecimalPrecision
254
- tuple := TupleDecimal {number : * NewDecimal (decNum )}
254
+ tuple := TupleDecimal {number : MakeDecimal (decNum )}
255
255
_ , err := msgpack .Marshal (& tuple )
256
256
if err == nil {
257
257
t .Fatalf ("It is possible to msgpack.Encoder a number unsupported by Tarantool" )
@@ -265,7 +265,7 @@ func TestEncodeMinNumber(t *testing.T) {
265
265
referenceErrMsg := "msgpack: decimal number is lesser than minimum supported number (-10^38 - 1)"
266
266
two := decimal .NewFromInt (2 )
267
267
decNum := decimal .New (1 , DecimalPrecision ).Neg ().Sub (two ) // -10^DecimalPrecision - 2
268
- tuple := TupleDecimal {number : * NewDecimal (decNum )}
268
+ tuple := TupleDecimal {number : MakeDecimal (decNum )}
269
269
_ , err := msgpack .Marshal (& tuple )
270
270
if err == nil {
271
271
t .Fatalf ("It is possible to msgpack.Encoder a number unsupported by Tarantool" )
@@ -284,7 +284,7 @@ func benchmarkMPEncodeDecode(b *testing.B, src decimal.Decimal, dst interface{})
284
284
var buf []byte
285
285
var err error
286
286
for i := 0 ; i < b .N ; i ++ {
287
- tuple := TupleDecimal {number : * NewDecimal (src )}
287
+ tuple := TupleDecimal {number : MakeDecimal (src )}
288
288
if buf , err = msgpack .Marshal (& tuple ); err != nil {
289
289
b .Fatal (err )
290
290
}
@@ -309,13 +309,15 @@ func BenchmarkMPEncodeDecodeDecimal(b *testing.B) {
309
309
func BenchmarkMPEncodeDecimal (b * testing.B ) {
310
310
for _ , testcase := range benchmarkSamples {
311
311
b .Run (testcase .numString , func (b * testing.B ) {
312
- decNum , err := NewDecimalFromString (testcase .numString )
312
+ decNum , err := MakeDecimalFromString (testcase .numString )
313
313
if err != nil {
314
314
b .Fatal (err )
315
315
}
316
316
b .ResetTimer ()
317
317
for i := 0 ; i < b .N ; i ++ {
318
- msgpack .Marshal (decNum )
318
+ if _ , err := msgpack .Marshal (decNum ); err != nil {
319
+ b .Fatal (err )
320
+ }
319
321
}
320
322
})
321
323
}
@@ -324,20 +326,20 @@ func BenchmarkMPEncodeDecimal(b *testing.B) {
324
326
func BenchmarkMPDecodeDecimal (b * testing.B ) {
325
327
for _ , testcase := range benchmarkSamples {
326
328
b .Run (testcase .numString , func (b * testing.B ) {
327
- decNum , err := NewDecimalFromString (testcase .numString )
329
+ decNum , err := MakeDecimalFromString (testcase .numString )
328
330
if err != nil {
329
331
b .Fatal (err )
330
332
}
331
- var buf [] byte
332
- if buf , err = msgpack . Marshal ( decNum ); err != nil {
333
+ buf , err := msgpack . Marshal ( decNum )
334
+ if err != nil {
333
335
b .Fatal (err )
334
336
}
335
337
b .ResetTimer ()
336
- var v TupleDecimal
337
338
for i := 0 ; i < b .N ; i ++ {
338
- msgpack .Unmarshal (buf , & v )
339
+ if err := msgpack .Unmarshal (buf , & decNum ); err != nil {
340
+ b .Fatal (err )
341
+ }
339
342
}
340
-
341
343
})
342
344
}
343
345
}
@@ -353,7 +355,7 @@ func tupleValueIsDecimal(t *testing.T, tuples []interface{}, number decimal.Deci
353
355
if len (tpl ) != 1 {
354
356
t .Fatalf ("Unexpected return value body (tuple len)" )
355
357
}
356
- if val , ok := tpl [0 ].(* Decimal ); ! ok || ! val .Equal (number ) {
358
+ if val , ok := tpl [0 ].(Decimal ); ! ok || ! val .Equal (number ) {
357
359
t .Fatalf ("Unexpected return value body (tuple 0 field)" )
358
360
}
359
361
}
@@ -418,9 +420,9 @@ func TestMPEncode(t *testing.T) {
418
420
samples = append (samples , benchmarkSamples ... )
419
421
for _ , testcase := range samples {
420
422
t .Run (testcase .numString , func (t * testing.T ) {
421
- dec , err := NewDecimalFromString (testcase .numString )
423
+ dec , err := MakeDecimalFromString (testcase .numString )
422
424
if err != nil {
423
- t .Fatalf ("NewDecimalFromString () failed: %s" , err .Error ())
425
+ t .Fatalf ("MakeDecimalFromString () failed: %s" , err .Error ())
424
426
}
425
427
buf , err := msgpack .Marshal (dec )
426
428
if err != nil {
@@ -451,7 +453,7 @@ func TestMPDecode(t *testing.T) {
451
453
if err != nil {
452
454
t .Fatalf ("Unmsgpack.Marshalling failed: %s" , err .Error ())
453
455
}
454
- decActual , ok := v .(* Decimal )
456
+ decActual , ok := v .(Decimal )
455
457
if ! ok {
456
458
t .Fatalf ("Unable to convert to Decimal" )
457
459
}
@@ -502,7 +504,7 @@ func TestSelect(t *testing.T) {
502
504
t .Fatalf ("Failed to prepare test decimal: %s" , err )
503
505
}
504
506
505
- ins := NewInsertRequest (space ).Tuple ([]interface {}{NewDecimal (number )})
507
+ ins := NewInsertRequest (space ).Tuple ([]interface {}{MakeDecimal (number )})
506
508
resp , err := conn .Do (ins ).Get ()
507
509
if err != nil {
508
510
t .Fatalf ("Decimal insert failed: %s" , err )
@@ -519,7 +521,7 @@ func TestSelect(t *testing.T) {
519
521
Offset (offset ).
520
522
Limit (limit ).
521
523
Iterator (IterEq ).
522
- Key ([]interface {}{NewDecimal (number )})
524
+ Key ([]interface {}{MakeDecimal (number )})
523
525
resp , err = conn .Do (sel ).Get ()
524
526
if err != nil {
525
527
t .Fatalf ("Decimal select failed: %s" , err .Error ())
@@ -529,7 +531,7 @@ func TestSelect(t *testing.T) {
529
531
}
530
532
tupleValueIsDecimal (t , resp .Data , number )
531
533
532
- del := NewDeleteRequest (space ).Index (index ).Key ([]interface {}{NewDecimal (number )})
534
+ del := NewDeleteRequest (space ).Index (index ).Key ([]interface {}{MakeDecimal (number )})
533
535
resp , err = conn .Do (del ).Get ()
534
536
if err != nil {
535
537
t .Fatalf ("Decimal delete failed: %s" , err )
@@ -543,7 +545,7 @@ func assertInsert(t *testing.T, conn *Connection, numString string) {
543
545
t .Fatalf ("Failed to prepare test decimal: %s" , err )
544
546
}
545
547
546
- ins := NewInsertRequest (space ).Tuple ([]interface {}{NewDecimal (number )})
548
+ ins := NewInsertRequest (space ).Tuple ([]interface {}{MakeDecimal (number )})
547
549
resp , err := conn .Do (ins ).Get ()
548
550
if err != nil {
549
551
t .Fatalf ("Decimal insert failed: %s" , err )
@@ -553,7 +555,7 @@ func assertInsert(t *testing.T, conn *Connection, numString string) {
553
555
}
554
556
tupleValueIsDecimal (t , resp .Data , number )
555
557
556
- del := NewDeleteRequest (space ).Index (index ).Key ([]interface {}{NewDecimal (number )})
558
+ del := NewDeleteRequest (space ).Index (index ).Key ([]interface {}{MakeDecimal (number )})
557
559
resp , err = conn .Do (del ).Get ()
558
560
if err != nil {
559
561
t .Fatalf ("Decimal delete failed: %s" , err )
@@ -586,7 +588,7 @@ func TestReplace(t *testing.T) {
586
588
t .Fatalf ("Failed to prepare test decimal: %s" , err )
587
589
}
588
590
589
- rep := NewReplaceRequest (space ).Tuple ([]interface {}{NewDecimal (number )})
591
+ rep := NewReplaceRequest (space ).Tuple ([]interface {}{MakeDecimal (number )})
590
592
respRep , errRep := conn .Do (rep ).Get ()
591
593
if errRep != nil {
592
594
t .Fatalf ("Decimal replace failed: %s" , errRep )
@@ -600,7 +602,7 @@ func TestReplace(t *testing.T) {
600
602
Index (index ).
601
603
Limit (1 ).
602
604
Iterator (IterEq ).
603
- Key ([]interface {}{NewDecimal (number )})
605
+ Key ([]interface {}{MakeDecimal (number )})
604
606
respSel , errSel := conn .Do (sel ).Get ()
605
607
if errSel != nil {
606
608
t .Fatalf ("Decimal select failed: %s" , errSel )
0 commit comments