ctaggart / froto

Froto: F# Protocol Buffers
MIT License
146 stars 27 forks source link

Add support for protobuf-net bcl-Types #66

Open Schwem opened 8 years ago

Schwem commented 8 years ago

The following .proto (created with protobuf-net)

import "bcl.proto"; // schema for protobuf-net's handling of core .NET types

message ClassA {
   optional string ID;
   optional string Name = 1 [default = aa];
   optional bcl.Guid mGuid = 2 [default = 00000000-0000-0000-0000-000000000000];
}

crashes with this message:

Error in Ln: 6 Col: 51
  optional bcl.Guid mGuid = 3 [default = 00000000-0000-0000-0000-000000000000];
                                                 ^
Expecting: newline, tab, ' ', ',', '/*', '//' or ']'

I try to parse it like this: FSharpList<Ast.PStatement> s = Parse.fromString(proto);

jhugard commented 8 years ago

The GUID data type bcl.Guid is a protobuf-net extension and not supported by the Google language spec, nor the protoc compiler. Can you rename this issue to something like "Add support for protobuf-net GUID values"?

One work around would be to modify (hand-edit) the field from "bcl.Guid" to "binary" and encode the binary as a string; e.g., "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0". I am fairly certain that this would be wire-compatible with protobuf-net code, and should interoperate with no problem.

Otherwise, it will be some work to modify Froto to accept this: the parser currently uses a Parsec helper function to parse numeric values and I'm pretty sure that function cannot be taught to handle GUID/UUID format. So, that means writing a complete numeric parser that also can consume GUID's.

Can you just use the work-around, instead?

Schwem commented 8 years ago

Thanks jhugard for your quick response. We created a little parser only for our necessary types now.

So, should I close it or leave it open as new Task?

jhugard commented 8 years ago

Go ahead and leave it open.

Karamell commented 6 years ago

I managed to decode a DateTime and a Guid from Protobuf.net. If anyone is interested I could try and convert the code to fit Froto.