Class: Protobuf::CodeGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/code_generator.rb

Constant Summary collapse

CodeGeneratorFatalError =
Class.new(RuntimeError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_bytes) ⇒ CodeGenerator

Returns a new instance of CodeGenerator.



27
28
29
# File 'lib/protobuf/code_generator.rb', line 27

def initialize(request_bytes)
  self.request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes)
end

Class Method Details

.fatal(message) ⇒ Object



8
9
10
# File 'lib/protobuf/code_generator.rb', line 8

def self.fatal(message)
  fail CodeGeneratorFatalError, message
end


12
13
14
15
# File 'lib/protobuf/code_generator.rb', line 12

def self.print_tag_warning_suppress
  STDERR.puts "Suppress tag warning output with PB_NO_TAG_WARNINGS=1."
  def self.print_tag_warning_suppress; end
end

.warn(message) ⇒ Object



17
18
19
# File 'lib/protobuf/code_generator.rb', line 17

def self.warn(message)
  STDERR.puts("[WARN] #{message}")
end

Instance Method Details

#generate_file(file_descriptor) ⇒ Object



31
32
33
# File 'lib/protobuf/code_generator.rb', line 31

def generate_file(file_descriptor)
  ::Protobuf::Generators::FileGenerator.new(file_descriptor).generate_output_file
end

#response_bytesObject



35
36
37
38
39
40
41
# File 'lib/protobuf/code_generator.rb', line 35

def response_bytes
  generated_files = request.proto_file.map do |file_descriptor|
    generate_file(file_descriptor)
  end

  ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => generated_files)
end