anerjan / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Enum of Type Long not working #134

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
==============

email : andre.vermeulen@standardbank.com

It seems the protobuf-net version Release 282 - NET30 doesn't support long 
values for enums.

What steps will reproduce the problem?
1. Create a long enum 

2. Ensure the values in the enum is actually assigned to a long bigger than 2^32

3. Create an class the use the long enum - instantiate the class and and then 
try to serialize it

For example:

var e = new MyEnum {Personality = MyEnum.Character.Wasp};
using(var ms = new MemoryStream())
{
   Serializer.Serialize(ms, e);
}

It will fail with...

System.OverflowException was unhandled
  Message="Value was either too large or too small for an Int32."
  Source="protobuf-net"
  StackTrace:
       at ProtoBuf.Serializer.ThrowInner(Exception exception) in c:\software\protobuf-net\branches\v1\protobuf-net\Serializer.cs:line 951
       at ProtoBuf.Serializer.ThrowInner(Exception exception) in c:\software\protobuf-net\branches\v1\protobuf-net\Serializer.cs:line 950
       at ProtoBuf.Serializer.Serialize[T](Stream destination, T instance) in c:\software\protobuf-net\branches\v1\protobuf-net\Serializer.cs:line 671
       at QuickStart.EnumSupport.Go() in c:\software\protobuf-net\branches\v1\QuickStart\EnumSupport.cs:line 40
       at QuickStart.Program.Main() in c:\software\protobuf-net\branches\v1\QuickStart\Program.cs:line 11
  InnerException: 

What is the expected output? What do you see instead?

long to be supported in enums - created .proto file to have a long mapping.

What version of the product are you using? On what operating system?

Release 282

Please provide any additional information below.

See the attached file for the problem.

Original issue reported on code.google.com by andre.ve...@gmail.com on 16 Sep 2010 at 4:10

Attachments:

GoogleCodeExporter commented 9 years ago
enums in the protobuf spec are 32-bit, not 64-bit - hence my options are 
limited. A v1 workaround would be to add a private shim property that simply 
casts to/from long:

    public YourEnum Foo {get;set;}
    private long FooSerialized {
        get {return (long)Foo;} set {Foo=(YourEnum)value;}
    }

In v2 I am adding support for (otpionally) treating enums as primitives, 
without any of the usual protobuf logic/constraints that surround enums.

Original comment by marc.gravell on 16 Sep 2010 at 6:53

GoogleCodeExporter commented 9 years ago
Hello,

"In v2 I am adding support for (otpionally) treating enums as primitives, 
without any of the usual protobuf logic/constraints that surround enums."

Was that feature ever added to v2?

Regards,

Chris.

Original comment by chris.lo...@gmail.com on 14 Oct 2011 at 5:13

GoogleCodeExporter commented 9 years ago
This has been unanswered for a long time, so it seems worth asking the question 
again -  is there a way in v2 to serialize long enums?

Original comment by paulbsm...@gmail.com on 3 Jan 2014 at 5:19