This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
forked from aerospike/aerospike-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
value.go
1129 lines (946 loc) · 30.4 KB
/
value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2013-2019 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package aerospike
import (
"fmt"
"reflect"
"strconv"
. "github.com/aerospike/aerospike-client-go/types"
ParticleType "github.com/aerospike/aerospike-client-go/types/particle_type"
Buffer "github.com/aerospike/aerospike-client-go/utils/buffer"
)
// this function will be set in value_slow file if included
var newValueReflect func(interface{}) Value
// Map pair is used when the client returns sorted maps from the server
// Since the default map in Go is a hash map, we will use a slice
// to return the results in server order
type MapPair struct{ Key, Value interface{} }
// Value interface is used to efficiently serialize objects into the wire protocol.
type Value interface {
// Calculate number of vl.bytes necessary to serialize the value in the wire protocol.
estimateSize() (int, error)
// Serialize the value in the wire protocol.
write(cmd BufferEx) (int, error)
// Serialize the value using MessagePack.
pack(cmd BufferEx) (int, error)
// GetType returns wire protocol value type.
GetType() int
// GetObject returns original value as an interface{}.
GetObject() interface{}
// String implements Stringer interface.
String() string
}
type AerospikeBlob interface {
// EncodeBlob returns a byte slice representing the encoding of the
// receiver for transmission to a Decoder, usually of the same
// concrete type.
EncodeBlob() ([]byte, error)
}
// tryConcreteValue will return an aerospike value.
// If the encoder does not exists, it will not try to use reflection.
func tryConcreteValue(v interface{}) Value {
switch val := v.(type) {
case Value:
return val
case int:
return IntegerValue(val)
case int64:
return LongValue(val)
case string:
return StringValue(val)
case []interface{}:
return ListValue(val)
case map[string]interface{}:
return JsonValue(val)
case map[interface{}]interface{}:
return NewMapValue(val)
case nil:
return nullValue
case []Value:
return NewValueArray(val)
case []byte:
return BytesValue(val)
case int8:
return IntegerValue(int(val))
case int16:
return IntegerValue(int(val))
case int32:
return IntegerValue(int(val))
case uint8: // byte supported here
return IntegerValue(int(val))
case uint16:
return IntegerValue(int(val))
case uint32:
return IntegerValue(int(val))
case float32:
return FloatValue(float64(val))
case float64:
return FloatValue(val)
case uint:
// if it doesn't overflow int64, it is OK
if int64(val) >= 0 {
return LongValue(int64(val))
}
case MapIter:
return NewMapperValue(val)
case ListIter:
return NewListerValue(val)
case AerospikeBlob:
return NewBlobValue(val)
/*
The following cases will try to avoid using reflection by matching against the
internal generic types.
If you have custom type aliases in your code, you can use the same aerospike types to cast your type into,
to avoid hitting the generics.
*/
case []string:
return NewListerValue(stringSlice(val))
case []int:
return NewListerValue(intSlice(val))
case []int8:
return NewListerValue(int8Slice(val))
case []int16:
return NewListerValue(int16Slice(val))
case []int32:
return NewListerValue(int32Slice(val))
case []int64:
return NewListerValue(int64Slice(val))
case []uint16:
return NewListerValue(uint16Slice(val))
case []uint32:
return NewListerValue(uint32Slice(val))
case []uint64:
return NewListerValue(uint64Slice(val))
case []float32:
return NewListerValue(float32Slice(val))
case []float64:
return NewListerValue(float64Slice(val))
case map[string]string:
return NewMapperValue(stringStringMap(val))
case map[string]int:
return NewMapperValue(stringIntMap(val))
case map[string]int8:
return NewMapperValue(stringInt8Map(val))
case map[string]int16:
return NewMapperValue(stringInt16Map(val))
case map[string]int32:
return NewMapperValue(stringInt32Map(val))
case map[string]int64:
return NewMapperValue(stringInt64Map(val))
case map[string]uint16:
return NewMapperValue(stringUint16Map(val))
case map[string]uint32:
return NewMapperValue(stringUint32Map(val))
case map[string]float32:
return NewMapperValue(stringFloat32Map(val))
case map[string]float64:
return NewMapperValue(stringFloat64Map(val))
case map[int]string:
return NewMapperValue(intStringMap(val))
case map[int]int:
return NewMapperValue(intIntMap(val))
case map[int]int8:
return NewMapperValue(intInt8Map(val))
case map[int]int16:
return NewMapperValue(intInt16Map(val))
case map[int]int32:
return NewMapperValue(intInt32Map(val))
case map[int]int64:
return NewMapperValue(intInt64Map(val))
case map[int]uint16:
return NewMapperValue(intUint16Map(val))
case map[int]uint32:
return NewMapperValue(intUint32Map(val))
case map[int]float32:
return NewMapperValue(intFloat32Map(val))
case map[int]float64:
return NewMapperValue(intFloat64Map(val))
case map[int]interface{}:
return NewMapperValue(intInterfaceMap(val))
case map[int8]string:
return NewMapperValue(int8StringMap(val))
case map[int8]int:
return NewMapperValue(int8IntMap(val))
case map[int8]int8:
return NewMapperValue(int8Int8Map(val))
case map[int8]int16:
return NewMapperValue(int8Int16Map(val))
case map[int8]int32:
return NewMapperValue(int8Int32Map(val))
case map[int8]int64:
return NewMapperValue(int8Int64Map(val))
case map[int8]uint16:
return NewMapperValue(int8Uint16Map(val))
case map[int8]uint32:
return NewMapperValue(int8Uint32Map(val))
case map[int8]float32:
return NewMapperValue(int8Float32Map(val))
case map[int8]float64:
return NewMapperValue(int8Float64Map(val))
case map[int8]interface{}:
return NewMapperValue(int8InterfaceMap(val))
case map[int16]string:
return NewMapperValue(int16StringMap(val))
case map[int16]int:
return NewMapperValue(int16IntMap(val))
case map[int16]int8:
return NewMapperValue(int16Int8Map(val))
case map[int16]int16:
return NewMapperValue(int16Int16Map(val))
case map[int16]int32:
return NewMapperValue(int16Int32Map(val))
case map[int16]int64:
return NewMapperValue(int16Int64Map(val))
case map[int16]uint16:
return NewMapperValue(int16Uint16Map(val))
case map[int16]uint32:
return NewMapperValue(int16Uint32Map(val))
case map[int16]float32:
return NewMapperValue(int16Float32Map(val))
case map[int16]float64:
return NewMapperValue(int16Float64Map(val))
case map[int16]interface{}:
return NewMapperValue(int16InterfaceMap(val))
case map[int32]string:
return NewMapperValue(int32StringMap(val))
case map[int32]int:
return NewMapperValue(int32IntMap(val))
case map[int32]int8:
return NewMapperValue(int32Int8Map(val))
case map[int32]int16:
return NewMapperValue(int32Int16Map(val))
case map[int32]int32:
return NewMapperValue(int32Int32Map(val))
case map[int32]int64:
return NewMapperValue(int32Int64Map(val))
case map[int32]uint16:
return NewMapperValue(int32Uint16Map(val))
case map[int32]uint32:
return NewMapperValue(int32Uint32Map(val))
case map[int32]float32:
return NewMapperValue(int32Float32Map(val))
case map[int32]float64:
return NewMapperValue(int32Float64Map(val))
case map[int32]interface{}:
return NewMapperValue(int32InterfaceMap(val))
case map[int64]string:
return NewMapperValue(int64StringMap(val))
case map[int64]int:
return NewMapperValue(int64IntMap(val))
case map[int64]int8:
return NewMapperValue(int64Int8Map(val))
case map[int64]int16:
return NewMapperValue(int64Int16Map(val))
case map[int64]int32:
return NewMapperValue(int64Int32Map(val))
case map[int64]int64:
return NewMapperValue(int64Int64Map(val))
case map[int64]uint16:
return NewMapperValue(int64Uint16Map(val))
case map[int64]uint32:
return NewMapperValue(int64Uint32Map(val))
case map[int64]float32:
return NewMapperValue(int64Float32Map(val))
case map[int64]float64:
return NewMapperValue(int64Float64Map(val))
case map[int64]interface{}:
return NewMapperValue(int64InterfaceMap(val))
case map[uint16]string:
return NewMapperValue(uint16StringMap(val))
case map[uint16]int:
return NewMapperValue(uint16IntMap(val))
case map[uint16]int8:
return NewMapperValue(uint16Int8Map(val))
case map[uint16]int16:
return NewMapperValue(uint16Int16Map(val))
case map[uint16]int32:
return NewMapperValue(uint16Int32Map(val))
case map[uint16]int64:
return NewMapperValue(uint16Int64Map(val))
case map[uint16]uint16:
return NewMapperValue(uint16Uint16Map(val))
case map[uint16]uint32:
return NewMapperValue(uint16Uint32Map(val))
case map[uint16]float32:
return NewMapperValue(uint16Float32Map(val))
case map[uint16]float64:
return NewMapperValue(uint16Float64Map(val))
case map[uint16]interface{}:
return NewMapperValue(uint16InterfaceMap(val))
case map[uint32]string:
return NewMapperValue(uint32StringMap(val))
case map[uint32]int:
return NewMapperValue(uint32IntMap(val))
case map[uint32]int8:
return NewMapperValue(uint32Int8Map(val))
case map[uint32]int16:
return NewMapperValue(uint32Int16Map(val))
case map[uint32]int32:
return NewMapperValue(uint32Int32Map(val))
case map[uint32]int64:
return NewMapperValue(uint32Int64Map(val))
case map[uint32]uint16:
return NewMapperValue(uint32Uint16Map(val))
case map[uint32]uint32:
return NewMapperValue(uint32Uint32Map(val))
case map[uint32]float32:
return NewMapperValue(uint32Float32Map(val))
case map[uint32]float64:
return NewMapperValue(uint32Float64Map(val))
case map[uint32]interface{}:
return NewMapperValue(uint32InterfaceMap(val))
case map[float32]string:
return NewMapperValue(float32StringMap(val))
case map[float32]int:
return NewMapperValue(float32IntMap(val))
case map[float32]int8:
return NewMapperValue(float32Int8Map(val))
case map[float32]int16:
return NewMapperValue(float32Int16Map(val))
case map[float32]int32:
return NewMapperValue(float32Int32Map(val))
case map[float32]int64:
return NewMapperValue(float32Int64Map(val))
case map[float32]uint16:
return NewMapperValue(float32Uint16Map(val))
case map[float32]uint32:
return NewMapperValue(float32Uint32Map(val))
case map[float32]float32:
return NewMapperValue(float32Float32Map(val))
case map[float32]float64:
return NewMapperValue(float32Float64Map(val))
case map[float32]interface{}:
return NewMapperValue(float32InterfaceMap(val))
case map[float64]string:
return NewMapperValue(float64StringMap(val))
case map[float64]int:
return NewMapperValue(float64IntMap(val))
case map[float64]int8:
return NewMapperValue(float64Int8Map(val))
case map[float64]int16:
return NewMapperValue(float64Int16Map(val))
case map[float64]int32:
return NewMapperValue(float64Int32Map(val))
case map[float64]int64:
return NewMapperValue(float64Int64Map(val))
case map[float64]uint16:
return NewMapperValue(float64Uint16Map(val))
case map[float64]uint32:
return NewMapperValue(float64Uint32Map(val))
case map[float64]float32:
return NewMapperValue(float64Float32Map(val))
case map[float64]float64:
return NewMapperValue(float64Float64Map(val))
case map[float64]interface{}:
return NewMapperValue(float64InterfaceMap(val))
case map[string]uint64:
return NewMapperValue(stringUint64Map(val))
case map[int]uint64:
return NewMapperValue(intUint64Map(val))
case map[int8]uint64:
return NewMapperValue(int8Uint64Map(val))
case map[int16]uint64:
return NewMapperValue(int16Uint64Map(val))
case map[int32]uint64:
return NewMapperValue(int32Uint64Map(val))
case map[int64]uint64:
return NewMapperValue(int64Uint64Map(val))
case map[uint16]uint64:
return NewMapperValue(uint16Uint64Map(val))
case map[uint32]uint64:
return NewMapperValue(uint32Uint64Map(val))
case map[float32]uint64:
return NewMapperValue(float32Uint64Map(val))
case map[float64]uint64:
return NewMapperValue(float64Uint64Map(val))
case map[uint64]string:
return NewMapperValue(uint64StringMap(val))
case map[uint64]int:
return NewMapperValue(uint64IntMap(val))
case map[uint64]int8:
return NewMapperValue(uint64Int8Map(val))
case map[uint64]int16:
return NewMapperValue(uint64Int16Map(val))
case map[uint64]int32:
return NewMapperValue(uint64Int32Map(val))
case map[uint64]int64:
return NewMapperValue(uint64Int64Map(val))
case map[uint64]uint16:
return NewMapperValue(uint64Uint16Map(val))
case map[uint64]uint32:
return NewMapperValue(uint64Uint32Map(val))
case map[uint64]uint64:
return NewMapperValue(uint64Uint64Map(val))
case map[uint64]float32:
return NewMapperValue(uint64Float32Map(val))
case map[uint64]float64:
return NewMapperValue(uint64Float64Map(val))
case map[uint64]interface{}:
return NewMapperValue(uint64InterfaceMap(val))
}
return nil
}
// NewValue generates a new Value object based on the type.
// If the type is not supported, NewValue will panic.
// This method is a convenience method, and should not be used
// when absolute performance is required unless for the reason mentioned below.
//
// If you have custom maps or slices like:
// type MyMap map[primitive1]primitive2, eg: map[int]string
// or
// type MySlice []primitive, eg: []float64
// cast them to their primitive type when passing them to this method:
// v := NewValue(map[int]string(myVar))
// v := NewValue([]float64(myVar))
// This way you will avoid hitting reflection.
// To completely avoid reflection in the library,
// use the build tag: as_performance while building your program.
func NewValue(v interface{}) Value {
if value := tryConcreteValue(v); value != nil {
return value
}
if newValueReflect != nil {
if res := newValueReflect(v); res != nil {
return res
}
}
// panic for anything that is not supported.
panic(NewAerospikeError(TYPE_NOT_SUPPORTED, fmt.Sprintf("Value type '%v' (%s) not supported (if you are compiling via 'as_performance' tag, use cast either to primitives, or use ListIter or MapIter interfaces.)", v, reflect.TypeOf(v).String())))
}
// NullValue is an empty value.
type NullValue struct{}
var nullValue NullValue
// NewNullValue generates a NullValue instance.
func NewNullValue() NullValue {
return nullValue
}
func (vl NullValue) estimateSize() (int, error) {
return 0, nil
}
func (vl NullValue) write(cmd BufferEx) (int, error) {
return 0, nil
}
func (vl NullValue) pack(cmd BufferEx) (int, error) {
return __PackNil(cmd)
}
// GetType returns wire protocol value type.
func (vl NullValue) GetType() int {
return ParticleType.NULL
}
// GetObject returns original value as an interface{}.
func (vl NullValue) GetObject() interface{} {
return nil
}
func (vl NullValue) String() string {
return ""
}
///////////////////////////////////////////////////////////////////////////////
// InfinityValue is an empty value.
type InfinityValue struct{}
var infinityValue InfinityValue
// NewInfinityValue generates a InfinityValue instance.
func NewInfinityValue() InfinityValue {
return infinityValue
}
func (vl InfinityValue) estimateSize() (int, error) {
return 0, nil
}
func (vl InfinityValue) write(cmd BufferEx) (int, error) {
return 0, nil
}
func (vl InfinityValue) pack(cmd BufferEx) (int, error) {
return __PackInfinity(cmd)
}
// GetType returns wire protocol value type.
func (vl InfinityValue) GetType() int {
panic("Invalid particle type: INF")
}
// GetObject returns original value as an interface{}.
func (vl InfinityValue) GetObject() interface{} {
return nil
}
func (vl InfinityValue) String() string {
return "INF"
}
///////////////////////////////////////////////////////////////////////////////
// InfinityValue is an empty value.
type WildCardValue struct{}
var wildCardValue WildCardValue
// NewWildCardValue generates a WildCardValue instance.
func NewWildCardValue() WildCardValue {
return wildCardValue
}
func (vl WildCardValue) estimateSize() (int, error) {
return 0, nil
}
func (vl WildCardValue) write(cmd BufferEx) (int, error) {
return 0, nil
}
func (vl WildCardValue) pack(cmd BufferEx) (int, error) {
return __PackWildCard(cmd)
}
// GetType returns wire protocol value type.
func (vl WildCardValue) GetType() int {
panic("Invalid particle type: WildCard")
}
// GetObject returns original value as an interface{}.
func (vl WildCardValue) GetObject() interface{} {
return nil
}
func (vl WildCardValue) String() string {
return "*"
}
///////////////////////////////////////////////////////////////////////////////
// BytesValue encapsulates an array of bytes.
type BytesValue []byte
// NewBytesValue generates a ByteValue instance.
func NewBytesValue(bytes []byte) BytesValue {
return BytesValue(bytes)
}
// NewBlobValue accepts an AerospikeBlob interface, and automatically
// converts it to a BytesValue.
// If Encode returns an err, it will panic.
func NewBlobValue(object AerospikeBlob) BytesValue {
buf, err := object.EncodeBlob()
if err != nil {
panic(err)
}
return NewBytesValue(buf)
}
func (vl BytesValue) estimateSize() (int, error) {
return len(vl), nil
}
func (vl BytesValue) write(cmd BufferEx) (int, error) {
return cmd.Write(vl)
}
func (vl BytesValue) pack(cmd BufferEx) (int, error) {
return __PackBytes(cmd, vl)
}
// GetType returns wire protocol value type.
func (vl BytesValue) GetType() int {
return ParticleType.BLOB
}
// GetObject returns original value as an interface{}.
func (vl BytesValue) GetObject() interface{} {
return []byte(vl)
}
// String implements Stringer interface.
func (vl BytesValue) String() string {
return Buffer.BytesToHexString(vl)
}
///////////////////////////////////////////////////////////////////////////////
// StringValue encapsulates a string value.
type StringValue string
// NewStringValue generates a StringValue instance.
func NewStringValue(value string) StringValue {
return StringValue(value)
}
func (vl StringValue) estimateSize() (int, error) {
return len(vl), nil
}
func (vl StringValue) write(cmd BufferEx) (int, error) {
return cmd.WriteString(string(vl))
}
func (vl StringValue) pack(cmd BufferEx) (int, error) {
return __PackString(cmd, string(vl))
}
// GetType returns wire protocol value type.
func (vl StringValue) GetType() int {
return ParticleType.STRING
}
// GetObject returns original value as an interface{}.
func (vl StringValue) GetObject() interface{} {
return string(vl)
}
// String implements Stringer interface.
func (vl StringValue) String() string {
return string(vl)
}
///////////////////////////////////////////////////////////////////////////////
// IntegerValue encapsulates an integer value.
type IntegerValue int
// NewIntegerValue generates an IntegerValue instance.
func NewIntegerValue(value int) IntegerValue {
return IntegerValue(value)
}
func (vl IntegerValue) estimateSize() (int, error) {
return 8, nil
}
func (vl IntegerValue) write(cmd BufferEx) (int, error) {
return cmd.WriteInt64(int64(vl))
}
func (vl IntegerValue) pack(cmd BufferEx) (int, error) {
return __PackAInt64(cmd, int64(vl))
}
// GetType returns wire protocol value type.
func (vl IntegerValue) GetType() int {
return ParticleType.INTEGER
}
// GetObject returns original value as an interface{}.
func (vl IntegerValue) GetObject() interface{} {
return int(vl)
}
// String implements Stringer interface.
func (vl IntegerValue) String() string {
return strconv.Itoa(int(vl))
}
///////////////////////////////////////////////////////////////////////////////
// LongValue encapsulates an int64 value.
type LongValue int64
// NewLongValue generates a LongValue instance.
func NewLongValue(value int64) LongValue {
return LongValue(value)
}
func (vl LongValue) estimateSize() (int, error) {
return 8, nil
}
func (vl LongValue) write(cmd BufferEx) (int, error) {
return cmd.WriteInt64(int64(vl))
}
func (vl LongValue) pack(cmd BufferEx) (int, error) {
return __PackAInt64(cmd, int64(vl))
}
// GetType returns wire protocol value type.
func (vl LongValue) GetType() int {
return ParticleType.INTEGER
}
// GetObject returns original value as an interface{}.
func (vl LongValue) GetObject() interface{} {
return int64(vl)
}
// String implements Stringer interface.
func (vl LongValue) String() string {
return strconv.Itoa(int(vl))
}
///////////////////////////////////////////////////////////////////////////////
// FloatValue encapsulates an float64 value.
type FloatValue float64
// NewFloatValue generates a FloatValue instance.
func NewFloatValue(value float64) FloatValue {
return FloatValue(value)
}
func (vl FloatValue) estimateSize() (int, error) {
return 8, nil
}
func (vl FloatValue) write(cmd BufferEx) (int, error) {
return cmd.WriteFloat64(float64(vl))
}
func (vl FloatValue) pack(cmd BufferEx) (int, error) {
return __PackFloat64(cmd, float64(vl))
}
// GetType returns wire protocol value type.
func (vl FloatValue) GetType() int {
return ParticleType.FLOAT
}
// GetObject returns original value as an interface{}.
func (vl FloatValue) GetObject() interface{} {
return float64(vl)
}
// String implements Stringer interface.
func (vl FloatValue) String() string {
return (fmt.Sprintf("%f", vl))
}
///////////////////////////////////////////////////////////////////////////////
// ValueArray encapsulates an array of Value.
// Supported by Aerospike 3 servers only.
type ValueArray []Value
// ToValueSlice converts a []interface{} to []Value.
// It will panic if any of array element types are not supported.
func ToValueSlice(array []interface{}) []Value {
// TODO: Do something about this method
res := make([]Value, 0, len(array))
for i := range array {
res = append(res, NewValue(array[i]))
}
return res
}
// ToValueArray converts a []interface{} to a ValueArray type.
// It will panic if any of array element types are not supported.
func ToValueArray(array []interface{}) *ValueArray {
return NewValueArray(ToValueSlice(array))
}
// NewValueArray generates a ValueArray instance.
func NewValueArray(array []Value) *ValueArray {
// return &ValueArray{*NewListerValue(valueList(array))}
res := ValueArray(array)
return &res
}
func (va ValueArray) estimateSize() (int, error) {
return __PackValueArray(nil, va)
}
func (va ValueArray) write(cmd BufferEx) (int, error) {
return __PackValueArray(cmd, va)
}
func (va ValueArray) pack(cmd BufferEx) (int, error) {
return __PackValueArray(cmd, []Value(va))
}
// GetType returns wire protocol value type.
func (va ValueArray) GetType() int {
return ParticleType.LIST
}
// GetObject returns original value as an interface{}.
func (va ValueArray) GetObject() interface{} {
return va
}
// String implements Stringer interface.
func (va ValueArray) String() string {
return fmt.Sprintf("%v", []Value(va))
}
///////////////////////////////////////////////////////////////////////////////
// ListValue encapsulates any arbitrary array.
// Supported by Aerospike 3 servers only.
type ListValue []interface{}
// NewListValue generates a ListValue instance.
func NewListValue(list []interface{}) ListValue {
return ListValue(list)
}
func (vl ListValue) estimateSize() (int, error) {
return __PackIfcList(nil, vl)
}
func (vl ListValue) write(cmd BufferEx) (int, error) {
return __PackIfcList(cmd, vl)
}
func (vl ListValue) pack(cmd BufferEx) (int, error) {
return __PackIfcList(cmd, []interface{}(vl))
}
// GetType returns wire protocol value type.
func (vl ListValue) GetType() int {
return ParticleType.LIST
}
// GetObject returns original value as an interface{}.
func (vl ListValue) GetObject() interface{} {
return vl
}
// String implements Stringer interface.
func (vl ListValue) String() string {
return fmt.Sprintf("%v", []interface{}(vl))
}
///////////////////////////////////////////////////////////////////////////////
// ListValue encapsulates any arbitrary array.
// Supported by Aerospike 3 servers only.
type ListerValue struct {
list ListIter
}
// NewListValue generates a ListValue instance.
func NewListerValue(list ListIter) *ListerValue {
res := &ListerValue{
list: list,
}
return res
}
func (vl *ListerValue) estimateSize() (int, error) {
return __PackList(nil, vl.list)
}
func (vl *ListerValue) write(cmd BufferEx) (int, error) {
return __PackList(cmd, vl.list)
}
func (vl *ListerValue) pack(cmd BufferEx) (int, error) {
return __PackList(cmd, vl.list)
}
// GetType returns wire protocol value type.
func (vl *ListerValue) GetType() int {
return ParticleType.LIST
}
// GetObject returns original value as an interface{}.
func (vl *ListerValue) GetObject() interface{} {
return vl.list
}
// String implements Stringer interface.
func (vl *ListerValue) String() string {
return fmt.Sprintf("%v", vl.list)
}
///////////////////////////////////////////////////////////////////////////////
// MapValue encapsulates an arbitrary map.
// Supported by Aerospike 3 servers only.
type MapValue map[interface{}]interface{}
// NewMapValue generates a MapValue instance.
func NewMapValue(vmap map[interface{}]interface{}) MapValue {
return MapValue(vmap)
}
func (vl MapValue) estimateSize() (int, error) {
return __PackIfcMap(nil, vl)
}
func (vl MapValue) write(cmd BufferEx) (int, error) {
return __PackIfcMap(cmd, vl)
}
func (vl MapValue) pack(cmd BufferEx) (int, error) {
return __PackIfcMap(cmd, vl)
}
// GetType returns wire protocol value type.
func (vl MapValue) GetType() int {
return ParticleType.MAP
}
// GetObject returns original value as an interface{}.
func (vl MapValue) GetObject() interface{} {
return vl
}
func (vl MapValue) String() string {
return fmt.Sprintf("%v", map[interface{}]interface{}(vl))
}
///////////////////////////////////////////////////////////////////////////////
// JsonValue encapsulates a Json map.
// Supported by Aerospike 3 servers only.
type JsonValue map[string]interface{}
// NewMapValue generates a JsonValue instance.
func NewJsonValue(vmap map[string]interface{}) JsonValue {
return JsonValue(vmap)
}
func (vl JsonValue) estimateSize() (int, error) {
return __PackJsonMap(nil, vl)
}
func (vl JsonValue) write(cmd BufferEx) (int, error) {
return __PackJsonMap(cmd, vl)
}
func (vl JsonValue) pack(cmd BufferEx) (int, error) {
return __PackJsonMap(cmd, vl)
}
// GetType returns wire protocol value type.
func (vl JsonValue) GetType() int {
return ParticleType.MAP
}
// GetObject returns original value as an interface{}.
func (vl JsonValue) GetObject() interface{} {
return vl
}
func (vl JsonValue) String() string {
return fmt.Sprintf("%v", map[string]interface{}(vl))
}
///////////////////////////////////////////////////////////////////////////////
// MapperValue encapsulates an arbitrary map which implements a MapIter interface.
// Supported by Aerospike 3 servers only.
type MapperValue struct {
vmap MapIter
}
// NewMapValue generates a MapperValue instance.
func NewMapperValue(vmap MapIter) *MapperValue {
res := &MapperValue{
vmap: vmap,
}
return res
}
func (vl *MapperValue) estimateSize() (int, error) {
return __PackMap(nil, vl.vmap)
}
func (vl *MapperValue) write(cmd BufferEx) (int, error) {
return __PackMap(cmd, vl.vmap)
}
func (vl *MapperValue) pack(cmd BufferEx) (int, error) {
return __PackMap(cmd, vl.vmap)
}
// GetType returns wire protocol value type.
func (vl *MapperValue) GetType() int {
return ParticleType.MAP
}
// GetObject returns original value as an interface{}.
func (vl *MapperValue) GetObject() interface{} {
return vl.vmap
}