protobuf-cucumber 3.10.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rubocop.yml +70 -0
- data/.rubocop_todo.yml +145 -0
- data/.travis.yml +40 -0
- data/.yardopts +5 -0
- data/CHANGES.md +344 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +64 -0
- data/bin/protoc-gen-ruby +22 -0
- data/bin/rpc_server +5 -0
- data/install-protobuf.sh +28 -0
- data/lib/protobuf.rb +129 -0
- data/lib/protobuf/cli.rb +257 -0
- data/lib/protobuf/code_generator.rb +120 -0
- data/lib/protobuf/decoder.rb +28 -0
- data/lib/protobuf/deprecation.rb +117 -0
- data/lib/protobuf/descriptors.rb +3 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +62 -0
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +301 -0
- data/lib/protobuf/encoder.rb +11 -0
- data/lib/protobuf/enum.rb +365 -0
- data/lib/protobuf/exceptions.rb +9 -0
- data/lib/protobuf/field.rb +74 -0
- data/lib/protobuf/field/base_field.rb +380 -0
- data/lib/protobuf/field/base_field_object_definitions.rb +504 -0
- data/lib/protobuf/field/bool_field.rb +64 -0
- data/lib/protobuf/field/bytes_field.rb +78 -0
- data/lib/protobuf/field/double_field.rb +25 -0
- data/lib/protobuf/field/enum_field.rb +61 -0
- data/lib/protobuf/field/field_array.rb +104 -0
- data/lib/protobuf/field/field_hash.rb +122 -0
- data/lib/protobuf/field/fixed32_field.rb +25 -0
- data/lib/protobuf/field/fixed64_field.rb +28 -0
- data/lib/protobuf/field/float_field.rb +43 -0
- data/lib/protobuf/field/int32_field.rb +21 -0
- data/lib/protobuf/field/int64_field.rb +34 -0
- data/lib/protobuf/field/integer_field.rb +23 -0
- data/lib/protobuf/field/message_field.rb +51 -0
- data/lib/protobuf/field/sfixed32_field.rb +27 -0
- data/lib/protobuf/field/sfixed64_field.rb +28 -0
- data/lib/protobuf/field/signed_integer_field.rb +29 -0
- data/lib/protobuf/field/sint32_field.rb +21 -0
- data/lib/protobuf/field/sint64_field.rb +21 -0
- data/lib/protobuf/field/string_field.rb +51 -0
- data/lib/protobuf/field/uint32_field.rb +21 -0
- data/lib/protobuf/field/uint64_field.rb +21 -0
- data/lib/protobuf/field/varint_field.rb +77 -0
- data/lib/protobuf/generators/base.rb +85 -0
- data/lib/protobuf/generators/enum_generator.rb +39 -0
- data/lib/protobuf/generators/extension_generator.rb +27 -0
- data/lib/protobuf/generators/field_generator.rb +193 -0
- data/lib/protobuf/generators/file_generator.rb +262 -0
- data/lib/protobuf/generators/group_generator.rb +122 -0
- data/lib/protobuf/generators/message_generator.rb +104 -0
- data/lib/protobuf/generators/option_generator.rb +17 -0
- data/lib/protobuf/generators/printable.rb +160 -0
- data/lib/protobuf/generators/service_generator.rb +50 -0
- data/lib/protobuf/lifecycle.rb +33 -0
- data/lib/protobuf/logging.rb +39 -0
- data/lib/protobuf/message.rb +260 -0
- data/lib/protobuf/message/fields.rb +233 -0
- data/lib/protobuf/message/serialization.rb +85 -0
- data/lib/protobuf/optionable.rb +70 -0
- data/lib/protobuf/rpc/buffer.rb +78 -0
- data/lib/protobuf/rpc/client.rb +140 -0
- data/lib/protobuf/rpc/connectors/base.rb +221 -0
- data/lib/protobuf/rpc/connectors/ping.rb +89 -0
- data/lib/protobuf/rpc/connectors/socket.rb +78 -0
- data/lib/protobuf/rpc/connectors/zmq.rb +319 -0
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +50 -0
- data/lib/protobuf/rpc/env.rb +60 -0
- data/lib/protobuf/rpc/error.rb +28 -0
- data/lib/protobuf/rpc/error/client_error.rb +31 -0
- data/lib/protobuf/rpc/error/server_error.rb +43 -0
- data/lib/protobuf/rpc/middleware.rb +25 -0
- data/lib/protobuf/rpc/middleware/exception_handler.rb +40 -0
- data/lib/protobuf/rpc/middleware/logger.rb +95 -0
- data/lib/protobuf/rpc/middleware/request_decoder.rb +79 -0
- data/lib/protobuf/rpc/middleware/response_encoder.rb +83 -0
- data/lib/protobuf/rpc/middleware/runner.rb +18 -0
- data/lib/protobuf/rpc/rpc.pb.rb +64 -0
- data/lib/protobuf/rpc/rpc_method.rb +16 -0
- data/lib/protobuf/rpc/server.rb +39 -0
- data/lib/protobuf/rpc/servers/socket/server.rb +121 -0
- data/lib/protobuf/rpc/servers/socket/worker.rb +56 -0
- data/lib/protobuf/rpc/servers/socket_runner.rb +46 -0
- data/lib/protobuf/rpc/servers/zmq/broker.rb +194 -0
- data/lib/protobuf/rpc/servers/zmq/server.rb +321 -0
- data/lib/protobuf/rpc/servers/zmq/util.rb +48 -0
- data/lib/protobuf/rpc/servers/zmq/worker.rb +105 -0
- data/lib/protobuf/rpc/servers/zmq_runner.rb +70 -0
- data/lib/protobuf/rpc/service.rb +172 -0
- data/lib/protobuf/rpc/service_directory.rb +261 -0
- data/lib/protobuf/rpc/service_dispatcher.rb +45 -0
- data/lib/protobuf/rpc/service_filters.rb +250 -0
- data/lib/protobuf/rpc/stat.rb +119 -0
- data/lib/protobuf/socket.rb +21 -0
- data/lib/protobuf/tasks.rb +1 -0
- data/lib/protobuf/tasks/compile.rake +80 -0
- data/lib/protobuf/varint.rb +20 -0
- data/lib/protobuf/varint_pure.rb +31 -0
- data/lib/protobuf/version.rb +3 -0
- data/lib/protobuf/wire_type.rb +10 -0
- data/lib/protobuf/zmq.rb +21 -0
- data/profile.html +5103 -0
- data/proto/dynamic_discovery.proto +44 -0
- data/proto/google/protobuf/compiler/plugin.proto +147 -0
- data/proto/google/protobuf/descriptor.proto +779 -0
- data/proto/rpc.proto +69 -0
- data/protobuf-cucumber.gemspec +57 -0
- data/spec/benchmark/tasks.rb +143 -0
- data/spec/bin/protoc-gen-ruby_spec.rb +23 -0
- data/spec/encoding/all_types_spec.rb +103 -0
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/functional/class_inheritance_spec.rb +52 -0
- data/spec/functional/code_generator_spec.rb +58 -0
- data/spec/functional/socket_server_spec.rb +59 -0
- data/spec/functional/zmq_server_spec.rb +105 -0
- data/spec/lib/protobuf/cli_spec.rb +317 -0
- data/spec/lib/protobuf/code_generator_spec.rb +87 -0
- data/spec/lib/protobuf/enum_spec.rb +307 -0
- data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
- data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/enum_field_spec.rb +44 -0
- data/spec/lib/protobuf/field/field_array_spec.rb +105 -0
- data/spec/lib/protobuf/field/field_hash_spec.rb +168 -0
- data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
- data/spec/lib/protobuf/field/int32_field_spec.rb +120 -0
- data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
- data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/string_field_spec.rb +79 -0
- data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field_spec.rb +192 -0
- data/spec/lib/protobuf/generators/base_spec.rb +154 -0
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +82 -0
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +42 -0
- data/spec/lib/protobuf/generators/field_generator_spec.rb +197 -0
- data/spec/lib/protobuf/generators/file_generator_spec.rb +119 -0
- data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
- data/spec/lib/protobuf/generators/service_generator_spec.rb +99 -0
- data/spec/lib/protobuf/lifecycle_spec.rb +94 -0
- data/spec/lib/protobuf/message_spec.rb +944 -0
- data/spec/lib/protobuf/optionable_spec.rb +265 -0
- data/spec/lib/protobuf/rpc/client_spec.rb +66 -0
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +226 -0
- data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +34 -0
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +110 -0
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +91 -0
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +38 -0
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +43 -0
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +55 -0
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +35 -0
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +293 -0
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +35 -0
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +517 -0
- data/spec/lib/protobuf/rpc/service_spec.rb +162 -0
- data/spec/lib/protobuf/rpc/stat_spec.rb +101 -0
- data/spec/lib/protobuf/varint_spec.rb +29 -0
- data/spec/lib/protobuf_spec.rb +105 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/all.rb +6 -0
- data/spec/support/packed_field.rb +23 -0
- data/spec/support/protos/all_types.data.bin +0 -0
- data/spec/support/protos/all_types.data.txt +119 -0
- data/spec/support/protos/enum.pb.rb +63 -0
- data/spec/support/protos/enum.proto +37 -0
- data/spec/support/protos/extreme_values.data.bin +0 -0
- data/spec/support/protos/google_unittest.bin +0 -0
- data/spec/support/protos/google_unittest.pb.rb +798 -0
- data/spec/support/protos/google_unittest.proto +884 -0
- data/spec/support/protos/google_unittest_custom_options.bin +0 -0
- data/spec/support/protos/google_unittest_custom_options.pb.rb +361 -0
- data/spec/support/protos/google_unittest_custom_options.proto +424 -0
- data/spec/support/protos/google_unittest_import.pb.rb +55 -0
- data/spec/support/protos/google_unittest_import.proto +73 -0
- data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
- data/spec/support/protos/google_unittest_import_public.proto +41 -0
- data/spec/support/protos/map-test.bin +157 -0
- data/spec/support/protos/map-test.pb.rb +85 -0
- data/spec/support/protos/map-test.proto +68 -0
- data/spec/support/protos/multi_field_extensions.pb.rb +59 -0
- data/spec/support/protos/multi_field_extensions.proto +35 -0
- data/spec/support/protos/resource.pb.rb +172 -0
- data/spec/support/protos/resource.proto +137 -0
- data/spec/support/resource_service.rb +23 -0
- data/spec/support/server.rb +65 -0
- data/spec/support/test_app_file.rb +2 -0
- data/varint_prof.rb +82 -0
- metadata +579 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'protobuf/field/uint32_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class Fixed32Field < Uint32Field
|
6
|
+
|
7
|
+
##
|
8
|
+
# Public Instance Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def decode(bytes)
|
12
|
+
bytes.unpack('V').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def encode(value)
|
16
|
+
[value].pack('V')
|
17
|
+
end
|
18
|
+
|
19
|
+
def wire_type
|
20
|
+
::Protobuf::WireType::FIXED32
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'protobuf/field/uint64_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class Fixed64Field < Uint64Field
|
6
|
+
|
7
|
+
##
|
8
|
+
# Public Instance Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def decode(bytes)
|
12
|
+
# we don't use 'Q' for pack/unpack. 'Q' is machine-dependent.
|
13
|
+
values = bytes.unpack('VV')
|
14
|
+
values[0] + (values[1] << 32)
|
15
|
+
end
|
16
|
+
|
17
|
+
def encode(value)
|
18
|
+
# we don't use 'Q' for pack/unpack. 'Q' is machine-dependent.
|
19
|
+
[value & 0xffff_ffff, value >> 32].pack('VV')
|
20
|
+
end
|
21
|
+
|
22
|
+
def wire_type
|
23
|
+
::Protobuf::WireType::FIXED64
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'protobuf/field/base_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class FloatField < BaseField
|
6
|
+
|
7
|
+
##
|
8
|
+
# Class Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def self.default
|
12
|
+
0.0
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Public Instance Methods
|
17
|
+
#
|
18
|
+
|
19
|
+
def acceptable?(val)
|
20
|
+
val.respond_to?(:to_f)
|
21
|
+
end
|
22
|
+
|
23
|
+
def coerce!(val)
|
24
|
+
Float(val)
|
25
|
+
rescue ArgumentError
|
26
|
+
fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'"
|
27
|
+
end
|
28
|
+
|
29
|
+
def decode(bytes)
|
30
|
+
bytes.unpack('e').first
|
31
|
+
end
|
32
|
+
|
33
|
+
def encode(value)
|
34
|
+
[value].pack('e')
|
35
|
+
end
|
36
|
+
|
37
|
+
def wire_type
|
38
|
+
WireType::FIXED32
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'protobuf/field/integer_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class Int64Field < IntegerField
|
6
|
+
|
7
|
+
##
|
8
|
+
# Class Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def self.max
|
12
|
+
INT64_MAX
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.min
|
16
|
+
INT64_MIN
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Instance Methods
|
21
|
+
#
|
22
|
+
def acceptable?(val)
|
23
|
+
if val.is_a?(Integer) || val.is_a?(Numeric)
|
24
|
+
val >= INT64_MIN && val <= INT64_MAX
|
25
|
+
else
|
26
|
+
Integer(val, 10) >= INT64_MIN && Integer(val, 10) <= INT64_MAX
|
27
|
+
end
|
28
|
+
rescue
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'protobuf/field/varint_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class IntegerField < VarintField
|
6
|
+
|
7
|
+
##
|
8
|
+
# Public Instance Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def decode(value)
|
12
|
+
value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero?
|
13
|
+
value
|
14
|
+
end
|
15
|
+
|
16
|
+
def encode(value)
|
17
|
+
# original Google's library uses 64bits integer for negative value
|
18
|
+
::Protobuf::Field::VarintField.encode(value & 0xffff_ffff_ffff_ffff)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'protobuf/field/base_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class MessageField < BaseField
|
6
|
+
|
7
|
+
##
|
8
|
+
# Public Instance Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def acceptable?(val)
|
12
|
+
val.is_a?(type_class) || val.respond_to?(:to_hash) || val.respond_to?(:to_proto)
|
13
|
+
end
|
14
|
+
|
15
|
+
def decode(bytes)
|
16
|
+
type_class.decode(bytes)
|
17
|
+
end
|
18
|
+
|
19
|
+
def encode(value)
|
20
|
+
bytes = value.encode
|
21
|
+
result = ::Protobuf::Field::VarintField.encode(bytes.bytesize)
|
22
|
+
result << bytes
|
23
|
+
end
|
24
|
+
|
25
|
+
def message?
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def wire_type
|
30
|
+
::Protobuf::WireType::LENGTH_DELIMITED
|
31
|
+
end
|
32
|
+
|
33
|
+
def coerce!(value)
|
34
|
+
return nil if value.nil?
|
35
|
+
|
36
|
+
coerced_value = if value.respond_to?(:to_proto)
|
37
|
+
value.to_proto
|
38
|
+
elsif value.respond_to?(:to_hash)
|
39
|
+
type_class.new(value.to_hash)
|
40
|
+
else
|
41
|
+
value
|
42
|
+
end
|
43
|
+
|
44
|
+
return coerced_value if coerced_value.is_a?(type_class)
|
45
|
+
|
46
|
+
fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{value.class}'"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'protobuf/field/int32_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class Sfixed32Field < Int32Field
|
6
|
+
|
7
|
+
##
|
8
|
+
# Public Instance Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def decode(bytes)
|
12
|
+
value = bytes.unpack('V').first
|
13
|
+
value -= 0x1_0000_0000 if (value & 0x8000_0000).nonzero?
|
14
|
+
value
|
15
|
+
end
|
16
|
+
|
17
|
+
def encode(value)
|
18
|
+
[value].pack('V')
|
19
|
+
end
|
20
|
+
|
21
|
+
def wire_type
|
22
|
+
::Protobuf::WireType::FIXED32
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'protobuf/field/int64_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class Sfixed64Field < Int64Field
|
6
|
+
|
7
|
+
##
|
8
|
+
# Public Instance Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def decode(bytes)
|
12
|
+
values = bytes.unpack('VV') # 'Q' is machine-dependent, don't use
|
13
|
+
value = values[0] + (values[1] << 32)
|
14
|
+
value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero?
|
15
|
+
value
|
16
|
+
end
|
17
|
+
|
18
|
+
def encode(value)
|
19
|
+
[value & 0xffff_ffff, value >> 32].pack('VV') # 'Q' is machine-dependent, don't use
|
20
|
+
end
|
21
|
+
|
22
|
+
def wire_type
|
23
|
+
::Protobuf::WireType::FIXED64
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'protobuf/field/varint_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class SignedIntegerField < VarintField
|
6
|
+
|
7
|
+
##
|
8
|
+
# Public Instance Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def decode(value)
|
12
|
+
if (value & 1).zero?
|
13
|
+
value >> 1 # positive value
|
14
|
+
else
|
15
|
+
~value >> 1 # negative value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def encode(value)
|
20
|
+
if value >= 0
|
21
|
+
VarintField.encode(value << 1)
|
22
|
+
else
|
23
|
+
VarintField.encode(~(value << 1))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'protobuf/field/signed_integer_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class Sint32Field < SignedIntegerField
|
6
|
+
|
7
|
+
##
|
8
|
+
# Class Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def self.max
|
12
|
+
INT32_MAX
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.min
|
16
|
+
INT32_MIN
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'protobuf/field/signed_integer_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class Sint64Field < SignedIntegerField
|
6
|
+
|
7
|
+
##
|
8
|
+
# Class Methods
|
9
|
+
#
|
10
|
+
|
11
|
+
def self.max
|
12
|
+
INT64_MAX
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.min
|
16
|
+
INT64_MIN
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'protobuf/field/bytes_field'
|
2
|
+
|
3
|
+
module Protobuf
|
4
|
+
module Field
|
5
|
+
class StringField < BytesField
|
6
|
+
|
7
|
+
##
|
8
|
+
# Constants
|
9
|
+
#
|
10
|
+
|
11
|
+
ENCODING = Encoding::UTF_8
|
12
|
+
|
13
|
+
##
|
14
|
+
# Public Instance Methods
|
15
|
+
#
|
16
|
+
|
17
|
+
def acceptable?(val)
|
18
|
+
val.is_a?(String) || val.nil? || val.is_a?(Symbol)
|
19
|
+
end
|
20
|
+
|
21
|
+
def coerce!(value)
|
22
|
+
if value.nil?
|
23
|
+
nil
|
24
|
+
elsif acceptable?(value)
|
25
|
+
value.to_s
|
26
|
+
else
|
27
|
+
fail TypeError, "Unacceptable value #{value} for field #{name} of type #{type_class}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def decode(bytes)
|
32
|
+
bytes.force_encoding(::Protobuf::Field::StringField::ENCODING)
|
33
|
+
bytes
|
34
|
+
end
|
35
|
+
|
36
|
+
def encode(value)
|
37
|
+
value_to_encode = "" + value # dup is slower
|
38
|
+
unless value_to_encode.encoding == ENCODING
|
39
|
+
value_to_encode.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "")
|
40
|
+
end
|
41
|
+
value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING)
|
42
|
+
|
43
|
+
"#{::Protobuf::Field::VarintField.encode(value_to_encode.bytesize)}#{value_to_encode}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def json_encode(value)
|
47
|
+
value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|