do the protocol buffer support java generics?

1,709 views
Skip to first unread message

kso

unread,
Mar 19, 2010, 4:06:25 AM3/19/10
to Protocol Buffers, sun...@feinno.com
hi protobuf team!

do the protocol buffer support java generics? if support, how can I
define the .proto file ?


thanks!

Henner Zeller

unread,
Mar 19, 2010, 2:55:13 PM3/19/10
to kso, Protocol Buffers, sun...@feinno.com
Hi,

> do the protocol buffer support java generics? if support, how can I
> define the .proto file ?

Not sure what you mean here. Lists for instance you pass to the
builder or get from a proto buff object have the type of the content
as generic parameter.

There are no 'template parameters' for proto buffer message
definitions in .proto files if you mean that.
Can you expand a bit what you would like to do ?

-h

Kenton Varda

unread,
Mar 19, 2010, 2:55:57 PM3/19/10
to kso, Protocol Buffers, sun...@feinno.com
No, the .proto language has no concept of type parameterization.


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


sun stenpher

unread,
Mar 20, 2010, 4:36:06 AM3/20/10
to sunxing, Kenton Varda, Protocol Buffers
Hi!
Thanks for your reply. and sorry for my tarrible English..
I mean that :
Does protobuf support java generic type?
I saw some code in .Net like this:
     ...
    [ProtoContract]
    public class IMASResults<T>
    {
        [ProtoMember(1)]
        [DataMember]
        public int ResultCode;
        [ProtoMember(2)]
        [DataMember]
        public T ResultValue;
        public IMASResults()
        {
 
        }
        public IMASResults(int resultCode, T value)
        {
            ResultCode = resultCode;
            ResultValue = value;
        }
        public IMASResults(IMASResultCode resultCode, T value)
        {
            ResultCode = (int)resultCode;
            ResultValue = value;
        }
        public IMASResults(int resultCode)
        {
            ResultCode = resultCode;
            ResultValue = default(T);
        }
        public IMASResults(IMASResultCode resultCode)
        {
            ResultCode = (int)resultCode;
            ResultValue = default(T);
        }
    }
....
 
the "public T ResultValue" is a generic type in .Net I think, and now I have to communicate with the .Net system in Java, so I want to know: How can I defin the "ResultValue" in the .proto file use to generate java code.
 
thanks!

在 2010年3月20日 下午2:51,sunxing <sun...@feinno.com>写道:
thank you very much!
 
 
2010-03-20

sunxing

发件人: Kenton Varda
发送时间: 2010-03-20  02:56:04
收件人: kso
抄送: Protocol Buffers; 孙星
主题: Re: [protobuf] do the protocol buffer support java generics?

Marc Gravell

unread,
Mar 20, 2010, 5:22:06 PM3/20/10
to sun stenpher, sunxing, Protocol Buffers
Hi; that is protobuf-net, which has a very different API to some of the core google libs. It supports use frmo .proto, but is also intended to work reasonably nicely with common / existing .NET types (that /aren't/ generated from .proto).

To that end - it indeed supports generics at runtime; this largely works like templates. To reproduce this in .proto, you'd need a different message (or family of messages) per "T" that you expect.

Marc


2010/3/20 sun stenpher <sten...@gmail.com>



--
Regards,

Marc
Reply all
Reply to author
Forward
0 new messages