|
|
@ -7,7 +7,24 @@ require 'google/protobuf/descriptor_pb' |
|
|
|
module Google |
|
|
|
module Google |
|
|
|
module Protobuf |
|
|
|
module Protobuf |
|
|
|
module Internal |
|
|
|
module Internal |
|
|
|
|
|
|
|
class AtomicCounter |
|
|
|
|
|
|
|
def initialize |
|
|
|
|
|
|
|
@n = 0 |
|
|
|
|
|
|
|
@mu = Mutex.new |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_and_increment |
|
|
|
|
|
|
|
n = @n |
|
|
|
|
|
|
|
@mu.synchronize { |
|
|
|
|
|
|
|
@n += 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return n |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
class Builder |
|
|
|
class Builder |
|
|
|
|
|
|
|
@@file_number = AtomicCounter.new |
|
|
|
|
|
|
|
|
|
|
|
def initialize(pool) |
|
|
|
def initialize(pool) |
|
|
|
@pool = pool |
|
|
|
@pool = pool |
|
|
|
@default_file = nil # Constructed lazily |
|
|
|
@default_file = nil # Constructed lazily |
|
|
@ -42,7 +59,9 @@ module Google |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
private def internal_default_file |
|
|
|
private def internal_default_file |
|
|
|
@default_file ||= FileBuilder.new(@pool, "ruby_default_file.proto") |
|
|
|
number = @@file_number.get_and_increment |
|
|
|
|
|
|
|
filename = "ruby_default_file#{number}.proto" |
|
|
|
|
|
|
|
@default_file ||= FileBuilder.new(@pool, filename) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|