Created
August 31, 2018 16:52
-
-
Save zvkemp/a0da07de853878ee92a7dfff7982ef16 to your computer and use it in GitHub Desktop.
protobuf-decoding server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Requires `protoc` to be installed and available on PATH. | |
# See https://developers.google.com/protocol-buffers/ | |
require 'bundler/inline' | |
require 'open3' | |
gemfile do | |
gem 'puma' | |
end | |
class Decoder | |
def call(env) | |
result, status = Open3.capture2('protoc', '--decode_raw', stdin_data: env['rack.input']) | |
puts result if status.success? | |
[201, {}, ['']] | |
end | |
end | |
server = Puma::Server.new(Decoder.new, Puma::Events.new(STDOUT, STDERR)) | |
server.add_tcp_listener('127.0.0.1', 9000) | |
server.run.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment