cucumber-messages 13.2.1 → 17.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +0,0 @@
1
- require 'cucumber/messages/varint'
2
-
3
- module Cucumber
4
- module Messages
5
- class BinaryToMessageEnumerator < Enumerator
6
- def initialize(io)
7
- super() do |yielder|
8
- while !io.eof?
9
- yielder.yield(Cucumber::Messages::Envelope.parse_delimited_from(io))
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,21 +0,0 @@
1
- require 'cucumber/messages/varint'
2
-
3
- module Cucumber
4
- module Messages
5
- module WriteDelimited
6
- def write_delimited_to(io)
7
- proto = self.class.encode(self)
8
- Varint.encode_varint(io, proto.length)
9
- io.write(proto)
10
- end
11
- end
12
-
13
- module ParseDelimited
14
- def parse_delimited_from(io)
15
- len = Varint.decode_varint(io)
16
- buf = io.read(len)
17
- self.decode(buf)
18
- end
19
- end
20
- end
21
- end
@@ -1,12 +0,0 @@
1
- require 'json'
2
-
3
- module Cucumber
4
- module Messages
5
- module WriteNdjson
6
- def write_ndjson_to(io)
7
- io.write(self.to_json(proto3: true))
8
- io.write("\n")
9
- end
10
- end
11
- end
12
- end
@@ -1,37 +0,0 @@
1
- module Cucumber
2
- module Messages
3
- # Varint (variable byte-length int) is an encoding format commonly used
4
- # to encode the length of Protocol Buffer message frames.
5
- module Varint
6
-
7
- def self.decode_varint(io)
8
- # https://github.com/ruby-protobuf/protobuf/blob/master/lib/protobuf/varint_pure.rb
9
- value = index = 0
10
- begin
11
- byte = io.readbyte
12
- value |= (byte & 0x7f) << (7 * index)
13
- index += 1
14
- end while (byte & 0x80).nonzero?
15
- value
16
- end
17
-
18
- # https://www.rubydoc.info/gems/ruby-protocol-buffers/1.2.2/ProtocolBuffers%2FVarint.encode
19
- def self.encode_varint(io, int_val)
20
- if int_val < 0
21
- # negative varints are always encoded with the full 10 bytes
22
- int_val = int_val & 0xffffffff_ffffffff
23
- end
24
- loop do
25
- byte = int_val & 0x7f
26
- int_val >>= 7
27
- if int_val == 0
28
- io << byte.chr
29
- break
30
- else
31
- io << (byte | 0x80).chr
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,29 +0,0 @@
1
- require 'cucumber/messages'
2
-
3
- module Cucumber
4
- module Messages
5
- describe Messages do
6
-
7
- it "can be serialised over a binary stream" do
8
- outgoing_messages = [
9
- Envelope.new(source: Source.new(data: 'Feature: Hello')),
10
- Envelope.new(attachment: Attachment.new(body: "JALLA"))
11
- ]
12
-
13
- io = StringIO.new
14
- write_outgoing_messages(outgoing_messages, io)
15
-
16
- io.rewind
17
- incoming_messages = BinaryToMessageEnumerator.new(io)
18
-
19
- expect(incoming_messages.to_a).to(eq(outgoing_messages))
20
- end
21
-
22
- def write_outgoing_messages(messages, out)
23
- messages.each do |message|
24
- message.write_delimited_to(out)
25
- end
26
- end
27
- end
28
- end
29
- end