rxio 0.12.0 → 0.12.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/lib/rxio/io_filters/bin_delim.rb +15 -15
- data/lib/rxio/io_filters/msg_size.rb +13 -13
- data/lib/rxio/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6f34344e2ac47e8498e3ef3c86d65ada23b7817
|
4
|
+
data.tar.gz: f77ce7121deb254fadc3c37b4a55322aafa8bac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd75cb72c3db49d10e894b7f1795f2a2f22f37eb1176f6e865ff01bc5ae8dc19dacf5dd2f0ca822bec5946b547c4413dbe808295a8b92c3e6743ecae85263c67
|
7
|
+
data.tar.gz: 390df2da1ecd9d2bd4059d2825bf9ef826745b0397ed94cb93bf090546bb0eee221799d9e102b1289cadf51ac68023130038f84079974067245c46c8ede2f8b3
|
@@ -28,43 +28,43 @@ module RxIO
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# Filter Input
|
31
|
-
# Buffers data chunks sent by the
|
32
|
-
# @param [Hash]
|
31
|
+
# Buffers data chunks sent by the endpoint and extracts messages from them, according to the delimiter defined through _msg_delim_.
|
32
|
+
# @param [Hash] endpoint
|
33
33
|
# @param [String] chunk
|
34
|
-
def filter_input
|
34
|
+
def filter_input endpoint, chunk
|
35
35
|
|
36
36
|
# Buffer dat shit
|
37
|
-
buffer_input
|
37
|
+
buffer_input endpoint, chunk
|
38
38
|
|
39
39
|
# Ensure Last Position is available
|
40
|
-
|
41
|
-
|
40
|
+
endpoint[:bin_delim] ||= {}
|
41
|
+
endpoint[:bin_delim][:last_pos] ||= 0
|
42
42
|
|
43
43
|
# Loop over Messages
|
44
44
|
while true
|
45
45
|
|
46
46
|
# Find Delimiter
|
47
|
-
d =
|
48
|
-
|
47
|
+
d = endpoint[:ibuf].index @msg_delim, endpoint[:bin_delim][:last_pos]
|
48
|
+
endpoint[:bin_delim][:last_pos] = endpoint[:ibuf].bytesize
|
49
49
|
|
50
50
|
# Check Delimiter
|
51
51
|
break unless d
|
52
52
|
|
53
53
|
# Slice out Message from Input Buffer
|
54
|
-
m =
|
55
|
-
|
54
|
+
m = endpoint[:ibuf].slice!(0, d + @msg_delim.bytesize).slice 0, d
|
55
|
+
endpoint[:bin_delim][:last_pos] = 0
|
56
56
|
|
57
57
|
# Register Message
|
58
|
-
|
58
|
+
endpoint[:msgs] << m
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
# Send Message
|
63
|
-
# Buffers a message to be sent to the
|
64
|
-
# @param [Hash]
|
63
|
+
# Buffers a message to be sent to the endpoint, after wrapping it according to the delimiter defined through _msg_delim_.
|
64
|
+
# @param [Hash] endpoint
|
65
65
|
# @param [String] msg
|
66
|
-
def send_msg
|
67
|
-
write
|
66
|
+
def send_msg endpoint, msg
|
67
|
+
write endpoint, msg, @msg_delim
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -21,40 +21,40 @@ module RxIO
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# Filter Input
|
24
|
-
# Buffers data chunks sent by the
|
25
|
-
# @param [Hash]
|
24
|
+
# Buffers data chunks sent by the endpoint and extracts messages from them, according to the *size* field present at the beginning of each message.
|
25
|
+
# @param [Hash] endpoint
|
26
26
|
# @param [String] chunk
|
27
|
-
def filter_input
|
27
|
+
def filter_input endpoint, chunk
|
28
28
|
|
29
29
|
# Buffer dat shit
|
30
|
-
buffer_input
|
30
|
+
buffer_input endpoint, chunk
|
31
31
|
|
32
32
|
# Loop over Messages
|
33
33
|
while true
|
34
34
|
|
35
35
|
# Check Buffer Size (can we at least determine the next message size?)
|
36
|
-
break unless
|
36
|
+
break unless endpoint[:ibuf].bytesize >= 4
|
37
37
|
|
38
38
|
# Acquire Message Size
|
39
|
-
size =
|
39
|
+
size = endpoint[:ibuf][0, 4].unpack 'N'
|
40
40
|
|
41
41
|
# Check Buffer Size again (is the complete message present in the buffer?)
|
42
|
-
break unless
|
42
|
+
break unless endpoint[:ibuf].bytesize >= 4 + size
|
43
43
|
|
44
44
|
# Slice out Message from Input Buffer
|
45
|
-
m =
|
45
|
+
m = endpoint[:ibuf].slice!(0, 4 + size)[4, size]
|
46
46
|
|
47
47
|
# Register Message
|
48
|
-
|
48
|
+
endpoint[:msgs] << m
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
# Send Message
|
53
|
-
# Buffers a message to be sent to the
|
54
|
-
# @param [Hash]
|
53
|
+
# Buffers a message to be sent to the endpoint, after prefixing it with a _size_ field.
|
54
|
+
# @param [Hash] endpoint
|
55
55
|
# @param [String] msg
|
56
|
-
def send_msg
|
57
|
-
write
|
56
|
+
def send_msg endpoint, msg
|
57
|
+
write endpoint, [msg.bytesize].pack('N'), msg
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
data/lib/rxio/version.rb
CHANGED