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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c147d32b0109fa000aadcd519b73c1e808996aee42b0565e4fd1840af28c984d
4
- data.tar.gz: 83ec8f366229b893b6347f5cb62a2651980d1408da473e2c629a9a01098feeeb
3
+ metadata.gz: e17c453960d40efb63134468319f184e1751a1812a42e72b4b10de4f10c08f7a
4
+ data.tar.gz: 3aa77f8983e7b737bc9c896d4ff7b0a476805e51d1bd2668d4399c4547beb2ca
5
5
  SHA512:
6
- metadata.gz: 96984a2b7e2a30b792ca73b066fdcaf79a1661b65397d139e97bf6e92f4ad9b234357e0610bd7025dff29812fad88753b0875f2b7f3be8c3bffffe4ae042274c
7
- data.tar.gz: a320a61ed574017490604a1fd80959a11655292135e3f370321c07eefdbf00e2b1f21bd0e3df712d3d3d3158399c8128c7515eb91641c53bca543874fa0467ca
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 = io.read_exactly(1).getbyte(0)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Protocol
4
4
  module ZMTP
5
- VERSION = "0.7.0"
5
+ VERSION = "0.7.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-zmtp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger