structured_noise 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c37af47cfc1772e00d2dc684e3cab55bf37a88a3
4
- data.tar.gz: 0ccc71e9453778a823bc65aec19f3833ee5ff7b5
3
+ metadata.gz: b18009ac9fd6664b030787bef74af2fe40104034
4
+ data.tar.gz: 04d543770e5fead6db17a08e6001b965a555f505
5
5
  SHA512:
6
- metadata.gz: e1292d4988b80d3a9cac27a074934cd81999fe1a2e3472e3acc69d8e537ec0ed9cd9c54f16ab4e213b597cf3790666e6c03cdcedd2c21966001e523d25480ef2
7
- data.tar.gz: edba0577dc1e1cbfde9eddb33f51ccda23eca2a290d859ca98e7ef2c63e7b7d3b41348bf2f087a2ff196b729388d6466aae11048950cacee7f481b1f9409b190
6
+ metadata.gz: 29a1d3a6456a2e95b0be8242bafb7b7be82a8abb423678c801408d7965520eec7cf6c29a0904f6d6caeb7e58b1e298861f008ff51b3752a01adae69cdd95809d
7
+ data.tar.gz: c2596d56ad101f348a103d56af2cb9d666295a8ed20f36e084b026d383e1ed799e41a9b4cd934024dd53b32891bacd0cfade4af3966a43c9b8e9a8a288389ec0
data/README.md CHANGED
@@ -9,6 +9,7 @@ README-driven development ;)
9
9
  * Reads an avro scheme indicated by `--schema` and writes noise to STDOUT
10
10
  * If given `--base64` it converts the avro binary data to Basee64 before sending it to STDOUT
11
11
  * Respects a `--messages-per-second` command
12
+ * Outputs data conforming to the [Avro Single Object Message](http://avro.apache.org/docs/1.8.2/spec.html#single_object_encoding) spec
12
13
 
13
14
  ####TODO FEATURES:
14
15
 
@@ -2,7 +2,9 @@ require 'json'
2
2
  require 'avro'
3
3
  require 'avro-patches'
4
4
  require 'base64'
5
+ require 'avro_pinions'
5
6
  module StructuredNoise
7
+
6
8
  class Generator
7
9
  MAGIC_BYTE = [0].pack("C").freeze
8
10
 
@@ -11,6 +13,23 @@ module StructuredNoise
11
13
  @output_base64 = base64
12
14
  @messages_per_second = messages_per_second
13
15
  @schemas = {}
16
+
17
+ AvroPinions.configure({ wire_format: :single_object })
18
+
19
+ @message = Class.new(AvroPinions::Message) do
20
+ def initialize(avro_schema, data)
21
+ @avro_schema = avro_schema
22
+ @data = data
23
+ end
24
+
25
+ def record
26
+ @data
27
+ end
28
+
29
+ def avro_schema
30
+ @avro_schema
31
+ end
32
+ end
14
33
  end
15
34
 
16
35
  def load_schema
@@ -23,11 +42,11 @@ module StructuredNoise
23
42
 
24
43
  def generate_output
25
44
  with_timing do
26
- message = encode(generate_random_fields)
45
+ msg = @message.new(@avro_schema, generate_random_fields).encode
27
46
  if @output_base64
28
- message = Base64.encode64(message)
47
+ msg = Base64.encode64(msg)
29
48
  end
30
- puts message
49
+ puts msg
31
50
  end
32
51
  end
33
52
 
@@ -39,25 +58,6 @@ module StructuredNoise
39
58
  end
40
59
  end
41
60
 
42
- def encode(fields)
43
- stream = StringIO.new
44
- writer = Avro::IO::DatumWriter.new(@avro_schema)
45
- encoder = Avro::IO::BinaryEncoder.new(stream)
46
-
47
- # Always start with the magic byte.
48
- encoder.write(MAGIC_BYTE)
49
-
50
- # The schema id is encoded as a 4-byte big-endian integer.
51
- fullname = Avro::Name.make_fullname(@schema_name, @namespace)
52
- #encoder.write([fullname].pack("N"))
53
- encoder.write([1].pack("N"))
54
-
55
- # The actual message comes last.
56
- writer.write(fields, encoder)
57
-
58
- stream.string
59
- end
60
-
61
61
  def with_timing
62
62
  while true
63
63
  yield
@@ -1,3 +1,3 @@
1
1
  module StructuredNoise
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -21,10 +21,12 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_dependency "avro", "~> 1.8"
25
- spec.add_dependency "avro-patches", "~> 0.3"
24
+ spec.add_dependency "avro_pinions", "~> 1.0"
25
+
26
26
  spec.add_development_dependency "bundler", "~> 1.14"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
  spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "guard"
31
+ spec.add_development_dependency "guard-rspec"
30
32
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structured_noise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jess Szmajda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-15 00:00:00.000000000 Z
11
+ date: 2017-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: avro
14
+ name: avro_pinions
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.8'
27
- - !ruby/object:Gem::Dependency
28
- name: avro-patches
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.3'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.3'
26
+ version: '1.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +80,34 @@ dependencies:
94
80
  - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Tool to generate Avro-encoded noise
98
112
  email:
99
113
  - jess@optoro.com