ignite-client 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -2
- data/lib/ignite.rb +2 -0
- data/lib/ignite/pack_formats.rb +17 -0
- data/lib/ignite/request.rb +53 -18
- data/lib/ignite/response.rb +53 -22
- data/lib/ignite/type_codes.rb +28 -0
- data/lib/ignite/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a81b15f9a00bf89eb585f8065bd6e660ecb19e21e1b75a63b5e41df7302806dd
|
4
|
+
data.tar.gz: 2894eb97340f58a8f8f40aa67a1aa3f7e3d6a2932b565339e551ec6b1b593204
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8813cce5db934323a6d32a922f85a2ab10b3acd0738d8b6899230ab261bedf2f95058bb6d40ae426581c75de635702a5bee42bef9ed7ac2ca54e7ab6c357f8f4
|
7
|
+
data.tar.gz: 3f5798dace62b573e02b7c6b11859e1d607f4ae85a859b9bde29169b5e1b55f0d59000dad14940be4763636b3b721d53ae1e330353163cf099c968dd0e193596
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -89,7 +89,7 @@ client.query("SELECT * FROM products WHERE name = ?", ["Ignite"])
|
|
89
89
|
|
90
90
|
## Connection Options
|
91
91
|
|
92
|
-
Specify
|
92
|
+
Specify the host and port
|
93
93
|
|
94
94
|
```ruby
|
95
95
|
Ignite::Client.new(host: "localhost", port: 10800)
|
@@ -117,7 +117,6 @@ For [SSL/TLS](https://ignite.apache.org/docs/latest/security/ssl-tls#ssl-for-cli
|
|
117
117
|
Ignite::Client.new(
|
118
118
|
use_ssl: true,
|
119
119
|
ssl_params: {
|
120
|
-
verify_mode: OpenSSL::SSL::VERIFY_PEER,
|
121
120
|
ca_file: "ca.pem"
|
122
121
|
}
|
123
122
|
)
|
data/lib/ignite.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Ignite
|
2
|
+
PACK_BYTE = "C"
|
3
|
+
PACK_CHAR = "c"
|
4
|
+
PACK_SHORT = "s!<"
|
5
|
+
PACK_INT = "i!<"
|
6
|
+
PACK_LONG = "l!<"
|
7
|
+
PACK_FLOAT = "e"
|
8
|
+
PACK_DOUBLE = "E"
|
9
|
+
|
10
|
+
SIZE_BYTE = 1
|
11
|
+
SIZE_CHAR = 1
|
12
|
+
SIZE_SHORT = 2
|
13
|
+
SIZE_INT = 4
|
14
|
+
SIZE_LONG = 8
|
15
|
+
SIZE_FLOAT = 4
|
16
|
+
SIZE_DOUBLE = 8
|
17
|
+
end
|
data/lib/ignite/request.rb
CHANGED
@@ -4,7 +4,9 @@ module Ignite
|
|
4
4
|
MAX_LONG = 9223372036854775807 # 2**63-1
|
5
5
|
|
6
6
|
def initialize(op_code)
|
7
|
-
@
|
7
|
+
@format = String.new
|
8
|
+
@values = []
|
9
|
+
|
8
10
|
int 0 # length placeholder
|
9
11
|
|
10
12
|
if op_code != OP_HANDSHAKE
|
@@ -13,10 +15,14 @@ module Ignite
|
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
18
|
+
# reduce allocations by packing together
|
19
|
+
# but need to make sure values aren't modified
|
20
|
+
# between when they are added and packed
|
16
21
|
def to_bytes
|
22
|
+
buffer = @values.pack(@format)
|
17
23
|
# update length
|
18
|
-
|
19
|
-
|
24
|
+
buffer[0..3] = [buffer.bytesize - 4].pack(PACK_INT)
|
25
|
+
buffer
|
20
26
|
end
|
21
27
|
|
22
28
|
def bool(value)
|
@@ -24,61 +30,90 @@ module Ignite
|
|
24
30
|
end
|
25
31
|
|
26
32
|
def byte(value)
|
27
|
-
|
33
|
+
@format << PACK_BYTE
|
34
|
+
@values << value
|
28
35
|
end
|
29
36
|
|
30
37
|
def short(value)
|
31
|
-
|
38
|
+
@format << PACK_SHORT
|
39
|
+
@values << value
|
32
40
|
end
|
33
41
|
|
34
42
|
def int(value)
|
35
|
-
|
43
|
+
@format << PACK_INT
|
44
|
+
@values << value
|
36
45
|
end
|
37
46
|
|
38
47
|
def long(value)
|
39
|
-
|
48
|
+
@format << PACK_LONG
|
49
|
+
@values << value
|
40
50
|
end
|
41
51
|
|
42
52
|
def float(value)
|
43
|
-
|
53
|
+
@format << PACK_FLOAT
|
54
|
+
@values << value
|
44
55
|
end
|
45
56
|
|
46
57
|
def double(value)
|
47
|
-
|
58
|
+
@format << PACK_DOUBLE
|
59
|
+
@values << value
|
48
60
|
end
|
49
61
|
|
50
62
|
def string(value)
|
51
|
-
byte
|
63
|
+
byte TYPE_STRING
|
52
64
|
int value.bytesize
|
53
|
-
@
|
65
|
+
@format << "a#{value.bytesize}"
|
66
|
+
@values << value
|
54
67
|
end
|
55
68
|
|
56
69
|
def data_object(value)
|
57
70
|
case value
|
58
71
|
when Integer
|
59
|
-
byte
|
72
|
+
byte TYPE_LONG
|
60
73
|
long value
|
61
74
|
when Float
|
62
|
-
byte
|
75
|
+
byte TYPE_DOUBLE
|
63
76
|
double value
|
64
77
|
when TrueClass, FalseClass
|
65
|
-
byte
|
78
|
+
byte TYPE_BOOL
|
66
79
|
bool value
|
67
80
|
when String
|
68
81
|
string value
|
69
82
|
when Date
|
70
|
-
byte
|
83
|
+
byte TYPE_DATE
|
71
84
|
time = value.to_time
|
72
85
|
long(time.to_i * 1000 + (time.nsec / 1000000))
|
86
|
+
when Array
|
87
|
+
array_object(value)
|
73
88
|
when Time
|
74
|
-
byte
|
89
|
+
byte TYPE_TIMESTAMP
|
75
90
|
long(value.to_i * 1000 + (value.nsec / 1000000))
|
76
91
|
int value.nsec % 1000000
|
77
92
|
when NilClass
|
78
|
-
byte
|
93
|
+
byte TYPE_NULL
|
79
94
|
else
|
80
|
-
raise "
|
95
|
+
raise Error, "Unable to cache #{value.class.name}"
|
81
96
|
end
|
82
97
|
end
|
98
|
+
|
99
|
+
def array_object(value)
|
100
|
+
# empty arrays take first path for now
|
101
|
+
if value.all? { |v| v.is_a?(Integer) }
|
102
|
+
array(TYPE_LONG_ARRAY, value, PACK_LONG)
|
103
|
+
elsif value.all? { |v| v.is_a?(Float) }
|
104
|
+
array(TYPE_DOUBLE_ARRAY, value, PACK_DOUBLE)
|
105
|
+
elsif value.all? { |v| v == true || v == false }
|
106
|
+
array(TYPE_BOOL_ARRAY, value.map { |v| v ? 1 : 0 }, PACK_CHAR)
|
107
|
+
else
|
108
|
+
raise Error, "Unable to cache array of #{value.map { |v| v.class.name }.uniq.join(", ")}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def array(type_code, value, pack)
|
113
|
+
byte type_code
|
114
|
+
int value.size
|
115
|
+
@format << "#{pack}#{value.size}"
|
116
|
+
@values.concat(value)
|
117
|
+
end
|
83
118
|
end
|
84
119
|
end
|
data/lib/ignite/response.rb
CHANGED
@@ -6,7 +6,7 @@ module Ignite
|
|
6
6
|
@client = client
|
7
7
|
|
8
8
|
# use buffer so errors don't leave unread data on socket
|
9
|
-
len = client.read(
|
9
|
+
len = client.read(SIZE_INT).unpack1(PACK_INT)
|
10
10
|
@buffer = StringIO.new(client.read(len))
|
11
11
|
end
|
12
12
|
|
@@ -15,31 +15,31 @@ module Ignite
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def read_byte
|
18
|
-
read(
|
18
|
+
read(SIZE_BYTE).unpack1(PACK_BYTE)
|
19
19
|
end
|
20
20
|
|
21
21
|
def read_short
|
22
|
-
read(
|
22
|
+
read(SIZE_SHORT).unpack1(PACK_SHORT)
|
23
23
|
end
|
24
24
|
|
25
25
|
def read_int
|
26
|
-
read(
|
26
|
+
read(SIZE_INT).unpack1(PACK_INT)
|
27
27
|
end
|
28
28
|
|
29
29
|
def read_long
|
30
|
-
read(
|
30
|
+
read(SIZE_LONG).unpack1(PACK_LONG)
|
31
31
|
end
|
32
32
|
|
33
33
|
def read_float
|
34
|
-
read(
|
34
|
+
read(SIZE_FLOAT).unpack1(PACK_FLOAT)
|
35
35
|
end
|
36
36
|
|
37
37
|
def read_double
|
38
|
-
read(
|
38
|
+
read(SIZE_DOUBLE).unpack1(PACK_DOUBLE)
|
39
39
|
end
|
40
40
|
|
41
41
|
def read_char
|
42
|
-
read(
|
42
|
+
read(SIZE_CHAR).unpack1(PACK_CHAR)
|
43
43
|
end
|
44
44
|
|
45
45
|
def read_bool
|
@@ -53,7 +53,7 @@ module Ignite
|
|
53
53
|
|
54
54
|
def read_string_object
|
55
55
|
type = read_byte
|
56
|
-
raise "Expected string, not type #{type}" unless type ==
|
56
|
+
raise Error, "Expected string, not type #{type}" unless type == TYPE_STRING
|
57
57
|
read_string
|
58
58
|
end
|
59
59
|
|
@@ -63,6 +63,22 @@ module Ignite
|
|
63
63
|
Time.at(sec).to_date
|
64
64
|
end
|
65
65
|
|
66
|
+
def read_byte_array
|
67
|
+
read_array(SIZE_BYTE, PACK_BYTE)
|
68
|
+
end
|
69
|
+
|
70
|
+
def read_long_array
|
71
|
+
read_array(SIZE_LONG, PACK_LONG)
|
72
|
+
end
|
73
|
+
|
74
|
+
def read_double_array
|
75
|
+
read_array(SIZE_DOUBLE, PACK_DOUBLE)
|
76
|
+
end
|
77
|
+
|
78
|
+
def read_bool_array
|
79
|
+
read_byte_array.map { |v| v != 0 }
|
80
|
+
end
|
81
|
+
|
66
82
|
# same as Python
|
67
83
|
def read_decimal
|
68
84
|
scale = read_int
|
@@ -93,35 +109,50 @@ module Ignite
|
|
93
109
|
def read_data_object
|
94
110
|
type_code = read_byte
|
95
111
|
case type_code
|
96
|
-
when
|
112
|
+
when TYPE_BYTE
|
97
113
|
read_byte
|
98
|
-
when
|
114
|
+
when TYPE_SHORT
|
99
115
|
read_short
|
100
|
-
when
|
116
|
+
when TYPE_INT
|
101
117
|
read_int
|
102
|
-
when
|
118
|
+
when TYPE_LONG
|
103
119
|
read_long
|
104
|
-
when
|
120
|
+
when TYPE_FLOAT
|
105
121
|
read_float
|
106
|
-
when
|
122
|
+
when TYPE_DOUBLE
|
107
123
|
read_double
|
108
|
-
when
|
124
|
+
when TYPE_CHAR
|
109
125
|
read_char
|
110
|
-
when
|
126
|
+
when TYPE_BOOL
|
111
127
|
read_bool
|
112
|
-
when
|
128
|
+
when TYPE_STRING
|
113
129
|
read_string
|
114
|
-
when
|
130
|
+
when TYPE_DATE
|
115
131
|
read_date
|
116
|
-
when
|
132
|
+
when TYPE_BYTE_ARRAY
|
133
|
+
read_byte_array
|
134
|
+
when TYPE_LONG_ARRAY
|
135
|
+
read_long_array
|
136
|
+
when TYPE_DOUBLE_ARRAY
|
137
|
+
read_double_array
|
138
|
+
when TYPE_BOOL_ARRAY
|
139
|
+
read_bool_array
|
140
|
+
when TYPE_DECIMAL
|
117
141
|
read_decimal
|
118
|
-
when
|
142
|
+
when TYPE_TIMESTAMP
|
119
143
|
read_timestamp
|
120
|
-
when
|
144
|
+
when TYPE_NULL
|
121
145
|
nil
|
122
146
|
else
|
123
147
|
raise Error, "Type not supported yet: #{type_code}. Please create an issue."
|
124
148
|
end
|
125
149
|
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
def read_array(size, pack)
|
154
|
+
len = read_int
|
155
|
+
read(len * size).unpack("#{pack}*")
|
156
|
+
end
|
126
157
|
end
|
127
158
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Ignite
|
2
|
+
TYPE_BYTE = 1
|
3
|
+
TYPE_SHORT = 2
|
4
|
+
TYPE_INT = 3
|
5
|
+
TYPE_LONG = 4
|
6
|
+
TYPE_FLOAT = 5
|
7
|
+
TYPE_DOUBLE = 6
|
8
|
+
TYPE_CHAR = 7
|
9
|
+
TYPE_BOOL = 8
|
10
|
+
TYPE_STRING = 9
|
11
|
+
TYPE_UUID = 10
|
12
|
+
TYPE_DATE = 11
|
13
|
+
|
14
|
+
TYPE_BYTE_ARRAY = 12
|
15
|
+
TYPE_INT_ARRAY = 14
|
16
|
+
TYPE_LONG_ARRAY = 15
|
17
|
+
TYPE_FLOAT_ARRAY = 16
|
18
|
+
TYPE_DOUBLE_ARRAY = 17
|
19
|
+
TYPE_CHAR_ARRAY = 18
|
20
|
+
TYPE_BOOL_ARRAY = 19
|
21
|
+
|
22
|
+
TYPE_ENUM = 28
|
23
|
+
TYPE_DECIMAL = 30
|
24
|
+
TYPE_TIMESTAMP = 33
|
25
|
+
TYPE_TIME = 36
|
26
|
+
|
27
|
+
TYPE_NULL = 101
|
28
|
+
end
|
data/lib/ignite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ignite-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: andrew@ankane.org
|
@@ -23,8 +23,10 @@ files:
|
|
23
23
|
- lib/ignite/cache.rb
|
24
24
|
- lib/ignite/client.rb
|
25
25
|
- lib/ignite/op_codes.rb
|
26
|
+
- lib/ignite/pack_formats.rb
|
26
27
|
- lib/ignite/request.rb
|
27
28
|
- lib/ignite/response.rb
|
29
|
+
- lib/ignite/type_codes.rb
|
28
30
|
- lib/ignite/version.rb
|
29
31
|
homepage: https://github.com/ankane/ignite-ruby
|
30
32
|
licenses:
|