Search code examples
javaflashprotocol-buffers

Does protobuf (protocol buffers) allow custom types?


I want to use protobuf in Java and Flash. All of them has protobuf implementation. I want to create the following structure:

class UserDetails
{
  int age;
  int weight;
  int lenght;
}

class User
{
  string firstName;
  string lastName;
  UserDetails details;
}

The question about UserDetails details; Is it allowed in Google protocol buffer?


Solution

  • Yes, you can even define nested messages:

    message User {
        required string firstName = 1;
        required string secondName = 2;
    
        message UserDetails {
            required int age = 1;
            required int weight = 2;
            required int lenght = 3;
        }
    
        required UserDetails details = 3;
    }
    

    You can get much more information about messages here.