Define services nested in proto messages

966 views
Skip to first unread message

ahmet...@gmail.com

unread,
Feb 6, 2019, 4:54:16 AM2/6/19
to Protocol Buffers
Hi,

I want to define services inside proto messages as below.

Example of a proto file.

syntax = "proto2";

message Sample {
//
}

message Example {
//
   service Service {
      rpc someMethod(Sample) returns Sample;
   }
}

So I can refer to that rpc as 'Example.Service.someMethod'.

There may be another services, methods with the same name as 'AnotherExample.Service.
somMethod' nested in other messages.

This provides a logical relationship between proto
messages and rpc's for me. 
For example, each proto message can have a method called 'init".

Protoc does not support this,  my proto file fails to compile.

How can I achieve this?

Derek Perez

unread,
Feb 6, 2019, 11:27:05 AM2/6/19
to ahmet...@gmail.com, Protocol Buffers
That's not how it's intended to be used, perhaps you want to define a package instead?

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

ahmet...@gmail.com

unread,
Feb 6, 2019, 11:32:04 PM2/6/19
to Protocol Buffers
This is what I have in mind.
This is not supported, I'm investigating whether I can enchance the syntax
of protobuf compiler to achieve this.


syntax ="proto2";

message Sample {

}

message Example {
//
    message SubgMsg {

    //
        service Service {
            rpc someMethod(Sample) returns Sample;
        }
    }

    message AnotherSubMsg {

    //   
        service Service {
            rpc someMethod(Sample) returns Sample;
        }
    }

}

I can refer to them as 'Example.SubgMsg.someMethod' and
'Example.AnotherSubMsg.someMethod'.
Reply all
Reply to author
Forward
0 new messages