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.



21
22
23
24
# File 'lib/protobuf/code_generator.rb', line 21

def initialize(request_bytes)
  @request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes)
  @generated_files = []
end

Class Method Details

.fatal(message) ⇒ Object



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

def self.fatal(message)
  raise 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



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

def generate_file(file_descriptor)
  file_generator = ::Protobuf::Generators::FileGenerator.new(file_descriptor)
  @generated_files << file_generator.generate_output_file
end

#response_bytesObject



31
32
33
34
35
36
37
# File 'lib/protobuf/code_generator.rb', line 31

def response_bytes
  @request.proto_file.each do |file_descriptor|
    generate_file(file_descriptor)
  end

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