@@ -298,7 +298,6 @@ func transRiakToSlice(sliceValue reflect.Value, registerName string, data *riak.
298
298
299
299
// Override the Slice from "Userland"
300
300
sliceValue .Set (finalSliceValue )
301
-
302
301
}
303
302
304
303
return nil
@@ -317,58 +316,72 @@ func bytesToValue(input []byte, outputType reflect.Type) (reflect.Value, error)
317
316
318
317
outputKind := outputType .Kind ()
319
318
319
+ // The final type (can be a custom type for example)
320
+ newWithSameType := reflect .New (outputType ).Elem ()
321
+
320
322
switch outputKind {
321
323
case reflect .String :
322
- return reflect .ValueOf (string (input )), nil
324
+ newWithSameType .SetString (string (input ))
325
+ return newWithSameType , nil
323
326
324
327
case reflect .Int :
325
328
if i , err := strconv .ParseInt (string (input ), 10 , 0 ); err == nil {
326
- return reflect .ValueOf (int (i )), nil
329
+ newWithSameType .SetInt (i )
330
+ return newWithSameType , nil
327
331
}
328
332
329
333
case reflect .Int8 :
330
334
if i , err := strconv .ParseInt (string (input ), 10 , 8 ); err == nil {
331
- return reflect .ValueOf (int8 (i )), nil
335
+ newWithSameType .SetInt (i )
336
+ return newWithSameType , nil
332
337
}
333
338
334
339
case reflect .Int16 :
335
340
if i , err := strconv .ParseInt (string (input ), 10 , 16 ); err == nil {
336
- return reflect .ValueOf (int16 (i )), nil
341
+ newWithSameType .SetInt (i )
342
+ return newWithSameType , nil
337
343
}
338
344
339
345
case reflect .Int32 :
340
346
if i , err := strconv .ParseInt (string (input ), 10 , 32 ); err == nil {
341
- return reflect .ValueOf (int32 (i )), nil
347
+ newWithSameType .SetInt (i )
348
+ return newWithSameType , nil
342
349
}
343
350
344
351
case reflect .Int64 :
345
352
if i , err := strconv .ParseInt (string (input ), 10 , 64 ); err == nil {
346
- return reflect .ValueOf (int64 (i )), nil
353
+ newWithSameType .SetInt (i )
354
+ return newWithSameType , nil
347
355
}
348
356
349
357
case reflect .Uint :
350
358
if i , err := strconv .ParseUint (string (input ), 10 , 0 ); err == nil {
351
- return reflect .ValueOf (uint (i )), nil
359
+ newWithSameType .SetUint (i )
360
+ return newWithSameType , nil
352
361
}
353
362
354
363
case reflect .Uint8 :
355
364
if i , err := strconv .ParseUint (string (input ), 10 , 8 ); err == nil {
356
- return reflect .ValueOf (uint8 (i )), nil
365
+ newWithSameType .SetUint (i )
366
+ return newWithSameType , nil
357
367
}
358
368
359
369
case reflect .Uint16 :
360
370
if i , err := strconv .ParseUint (string (input ), 10 , 16 ); err == nil {
361
- return reflect .ValueOf (uint16 (i )), nil
371
+ newWithSameType .SetUint (i )
372
+ return newWithSameType , nil
362
373
}
363
374
364
375
case reflect .Uint32 :
365
376
if i , err := strconv .ParseUint (string (input ), 10 , 32 ); err == nil {
366
- return reflect .ValueOf (uint32 (i )), nil
377
+ newWithSameType .SetUint (i )
378
+ return newWithSameType , nil
367
379
}
368
380
369
381
case reflect .Uint64 :
370
382
if i , err := strconv .ParseUint (string (input ), 10 , 64 ); err == nil {
371
- return reflect .ValueOf (uint64 (i )), nil
383
+ newWithSameType .SetUint (i )
384
+ return newWithSameType , nil
372
385
}
373
386
374
387
case reflect .Slice :
0 commit comments