protocol-zmtp 0.7.0 → 0.7.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/protocol/zmtp/codec/frame.rb +26 -7
- data/lib/protocol/zmtp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e17c453960d40efb63134468319f184e1751a1812a42e72b4b10de4f10c08f7a
|
|
4
|
+
data.tar.gz: 3aa77f8983e7b737bc9c896d4ff7b0a476805e51d1bd2668d4399c4547beb2ca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c325ce9ad10043d55875304bf4267f5ef7ab286945126620fe43f0ec5eeedb228804ed1c6bb97a6dc135adc017124add12b56a1475bfb1ff37d74a0dc7536abc
|
|
7
|
+
data.tar.gz: 1cdd5b8fd5abb3471c6e4147850b7e5d20c5bc47cec6fb4233c7e38845f8e5b8df2fd73463e618a128d07316c184facf678fa718674b8ba6e1cb70e9390310d5
|
|
@@ -98,17 +98,17 @@ module Protocol
|
|
|
98
98
|
# @raise [Error] on invalid frame
|
|
99
99
|
# @raise [EOFError] if the connection is closed
|
|
100
100
|
def self.read_from(io, max_message_size: nil)
|
|
101
|
-
flags
|
|
101
|
+
# Every valid frame has at least 2 header bytes (flags + 1 size
|
|
102
|
+
# byte for short frames, or flags + first size byte for long).
|
|
103
|
+
# Fetching both up-front gives short frames a 2-call read path
|
|
104
|
+
# (header + body) instead of 3.
|
|
105
|
+
head = io.read_exactly(2)
|
|
106
|
+
flags = head.getbyte(0)
|
|
102
107
|
|
|
103
108
|
more = (flags & FLAGS_MORE) != 0
|
|
104
109
|
long = (flags & FLAGS_LONG) != 0
|
|
105
110
|
command = (flags & FLAGS_COMMAND) != 0
|
|
106
|
-
|
|
107
|
-
size = if long
|
|
108
|
-
io.read_exactly(8).unpack1("Q>")
|
|
109
|
-
else
|
|
110
|
-
io.read_exactly(1).getbyte(0)
|
|
111
|
-
end
|
|
111
|
+
size = long ? read_long_size(io, head.getbyte(1)) : head.getbyte(1)
|
|
112
112
|
|
|
113
113
|
if max_message_size && size > max_message_size
|
|
114
114
|
raise Error, "frame size #{size} exceeds max_message_size #{max_message_size}"
|
|
@@ -118,6 +118,25 @@ module Protocol
|
|
|
118
118
|
|
|
119
119
|
new(body, more: more, command: command)
|
|
120
120
|
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# Reads the remaining 7 bytes of a long frame's 8-byte big-endian
|
|
124
|
+
# size field and combines them with +msb+ (already consumed as the
|
|
125
|
+
# second byte of the 2-byte speculative header read).
|
|
126
|
+
#
|
|
127
|
+
# @param io [#read_exactly]
|
|
128
|
+
# @param msb [Integer] first (most-significant) byte of the size
|
|
129
|
+
# @return [Integer] full 64-bit frame size
|
|
130
|
+
#
|
|
131
|
+
def self.read_long_size(io, msb)
|
|
132
|
+
rest = io.read_exactly(7)
|
|
133
|
+
|
|
134
|
+
(msb << 56) |
|
|
135
|
+
(rest.getbyte(0) << 48) | (rest.getbyte(1) << 40) |
|
|
136
|
+
(rest.getbyte(2) << 32) | (rest.getbyte(3) << 24) |
|
|
137
|
+
(rest.getbyte(4) << 16) | (rest.getbyte(5) << 8) |
|
|
138
|
+
rest.getbyte(6)
|
|
139
|
+
end
|
|
121
140
|
end
|
|
122
141
|
end
|
|
123
142
|
end
|