-
Notifications
You must be signed in to change notification settings - Fork 114
/
array.go
254 lines (220 loc) · 5.44 KB
/
array.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
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 hessian
import (
"strings"
)
// BooleanArray Boolean[]
// Deprecated: it will not be supported in next major version, being replaced by a slice type instead.
type BooleanArray struct {
Values []bool
}
// nolint
func (ba *BooleanArray) Get() []interface{} {
res := make([]interface{}, len(ba.Values))
for i, v := range ba.Values {
res[i] = v
}
return res
}
// nolint
func (ba *BooleanArray) Set(vs []interface{}) {
values := make([]bool, len(vs))
for i, v := range vs {
values[i] = v.(bool)
}
ba.Values = values
}
// nolint
func (*BooleanArray) JavaClassName() string {
return "[java.lang.Boolean"
}
// IntegerArray Integer[].
// Deprecated: it will not be supported in next major version, being replaced by a slice type instead.
type IntegerArray struct {
Values []int32
}
// nolint
func (ia *IntegerArray) Get() []interface{} {
res := make([]interface{}, len(ia.Values))
for i, v := range ia.Values {
res[i] = v
}
return res
}
// nolint
func (ia *IntegerArray) Set(vs []interface{}) {
values := make([]int32, len(vs))
for i, v := range vs {
values[i] = v.(int32)
}
ia.Values = values
}
// nolint
func (*IntegerArray) JavaClassName() string {
return "[java.lang.Integer"
}
// ByteArray Byte[]
// Deprecated: it will not be supported in next major version, being replaced by a slice type instead.
type ByteArray struct {
Values []uint8
}
// nolint
func (ba *ByteArray) Get() []interface{} {
res := make([]interface{}, len(ba.Values))
for i, v := range ba.Values {
res[i] = v
}
return res
}
// nolint
func (ba *ByteArray) Set(vs []interface{}) {
values := make([]uint8, len(vs))
for i, v := range vs {
values[i] = uint8(v.(int32))
}
ba.Values = values
}
// nolint
func (*ByteArray) JavaClassName() string {
return "[java.lang.Byte"
}
// ShortArray Short[]
// Deprecated: it will not be supported in next major version, being replaced by a slice type instead.
type ShortArray struct {
Values []int16
}
// nolint
func (sa *ShortArray) Get() []interface{} {
res := make([]interface{}, len(sa.Values))
for i, v := range sa.Values {
res[i] = v
}
return res
}
// nolint
func (sa *ShortArray) Set(vs []interface{}) {
values := make([]int16, len(vs))
for i, v := range vs {
values[i] = int16(v.(int32))
}
sa.Values = values
}
// nolint
func (*ShortArray) JavaClassName() string {
return "[java.lang.Short"
}
// LongArray Long[]
// Deprecated: it will not be supported in next major version, being replaced by a slice type instead.
type LongArray struct {
Values []int64
}
// nolint
func (ba *LongArray) Get() []interface{} {
res := make([]interface{}, len(ba.Values))
for i, v := range ba.Values {
res[i] = v
}
return res
}
// nolint
func (ba *LongArray) Set(vs []interface{}) {
values := make([]int64, len(vs))
for i, v := range vs {
values[i] = v.(int64)
}
ba.Values = values
}
// nolint
func (*LongArray) JavaClassName() string {
return "[java.lang.Long"
}
// FloatArray Float[]
// Deprecated: it will not be supported in next major version, being replaced by a slice type instead.
type FloatArray struct {
Values []float32
}
// nolint
func (fa *FloatArray) Get() []interface{} {
res := make([]interface{}, len(fa.Values))
for i, v := range fa.Values {
res[i] = v
}
return res
}
// nolint
func (fa *FloatArray) Set(vs []interface{}) {
values := make([]float32, len(vs))
for i, v := range vs {
values[i] = float32(v.(float64))
}
fa.Values = values
}
// nolint
func (*FloatArray) JavaClassName() string {
return "[java.lang.Float"
}
// DoubleArray Double[]
// Deprecated: it will not be supported in next major version, being replaced by a slice type instead.
type DoubleArray struct {
Values []float64
}
// nolint
func (da *DoubleArray) Get() []interface{} {
res := make([]interface{}, len(da.Values))
for i, v := range da.Values {
res[i] = v
}
return res
}
// nolint
func (da *DoubleArray) Set(vs []interface{}) {
values := make([]float64, len(vs))
for i, v := range vs {
values[i] = v.(float64)
}
da.Values = values
}
// nolint
func (*DoubleArray) JavaClassName() string {
return "[java.lang.Double"
}
// CharacterArray Character[]
// Deprecated: it will not be supported in next major version, being replaced by a slice type instead.
type CharacterArray struct {
Values string
}
// nolint
func (ca *CharacterArray) Get() []interface{} {
length := len(ca.Values)
charArr := strings.Split(ca.Values, "")
res := make([]interface{}, length)
for i := 0; i < length; i++ {
res[i] = charArr[i]
}
return res
}
// nolint
func (ca *CharacterArray) Set(vs []interface{}) {
for _, v := range vs {
ca.Values = ca.Values + v.(string)
}
}
// nolint
func (*CharacterArray) JavaClassName() string {
return "[java.lang.Character"
}