[Haskell-cafe] Things I would like to see in protocol-buffers

Mads Lindstrøm mads.lindstroem at gmail.com
Wed Oct 13 12:46:17 EDT 2010


Hi

I have been trying to use protocol-buffers[2], and I have some ideas
which would have improved the protocol-buffers package for my usage (and
maybe for others):

* hprotoc should have an option to generate messages with [Char], Int
and [] in stead of Utf8, Int32 and Seq. While some people may need the
speed of bytestrings, for others they are just cumbersome. And if you
need to convert bytestring to [Char] anyway (maybe some other library
requires [Char]) you really do not gain any performance anyway.

* Integration with System.IO.Handle, so that I would have a simpler
interface like:

readDelimitedMessage :: System.IO.Handle -> IO MessageType
writeDelimitedMessage :: System.IO.Handle -> MessageType -> IO ()

* Union types. A common protocol buffers idiom for union types is[3]:

message Foo {
  enum FooType { SOME_FOO_MESSAGE = 0; ANOTHER_FOO_MESSAGE = 1; }
  
  message SomeFoo {
    ...
  }

  message AnotherFoo {
     ...
  }

  required FooType fooType = 1;

  optional SomeFoo someFoo = 2;
  optional AnotherFoo anotherFoo = 3;
}

While the message can (statically) contain both someFoo and anotherFoo,
it would be a runtime error. In reality it is a union type, that must
either contain someFoo or antoherFoo. It would be nice if one could mark
in the .proto file that hprotec should see Foo as a union type. Hprotoc
should then generate the Foo type as:

data Foo = SomeFoo ...
         | AnotherFoo ...

Maybe the custom option mechanism[1] can be used in the .proto file, to
implement this feature.

What do people think of these ideas?

Regards,


Mads Lindstrøm


[1] http://code.google.com/apis/protocolbuffers/docs/proto.html#options

[2] http://hackage.haskell.org/package/protocol-buffers

[3]
http://code.google.com/apis/protocolbuffers/docs/techniques.html#union



More information about the Haskell-Cafe mailing list