Last active
August 29, 2015 14:03
-
-
Save ismith/b17e9b31d696195169df to your computer and use it in GitHub Desktop.
This file contains 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
require 'protobuf' | |
class SampleEnum < ::Protobuf::Enum | |
define :NEGATIVE, -1 | |
define :ZERO, 0 | |
define :POSITIVE, 1 | |
end | |
class SampleMessage < ::Protobuf::Message | |
required SampleEnum, :my_enum, 1 | |
end | |
def roundtrip(msg) | |
begin | |
encoded_msg = msg.encode | |
decoded_msg = SampleMessage.decode(encoded_msg) | |
puts "Successful round trip" | |
rescue StandardError => e | |
puts "Failed round trip: #{e.message}, #{e.backtrace}" | |
end | |
end | |
if __FILE__ == $0 | |
puts "About to round trip a message with an enum with a positive value:" | |
roundtrip(SampleMessage.new(:my_enum => SampleEnum::POSITIVE)) | |
puts "About to round trip a message with an enum with a zero value:" | |
roundtrip(SampleMessage.new(:my_enum => SampleEnum::ZERO)) | |
puts "About to round trip a message with an enum with a negative value:" | |
roundtrip(SampleMessage.new(:my_enum => SampleEnum::NEGATIVE)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment