Fl4m3Ph03n1x

Fl4m3Ph03n1x

.proto file for exprotobuf

Background

I am trying to use protobuff for one of our apps by using exprotobuf, but I am having trouble understanding the protocol and I need help creating a .proto file.

Data

The data I need to encode is a list of maps, with the following structure:

[
  {
    "AwayTeam": "Osasuna",
    "Date": "2017-05-07",
    "Div": "SP1",
    "FTAG": 1,
    "FTHG": 4,
    "FTR": "H",
    "HTAG": 0,
    "HTHG": 2,
    "HTR": "H",
    "HomeTeam": "Valencia",
    "Season": 201617
  },
  {
    "AwayTeam": "Osasuna",
    "Date": "2016-02-27",
    "Div": "SP2",
    "FTAG": 1,
    "FTHG": 0,
    "FTR": "A",
    "HTAG": 0,
    "HTHG": 0,
    "HTR": "D",
    "HomeTeam": "Cordoba",
    "Season": 201516
  }
]

Each map has the following structure:

{
  "AwayTeam": string,  required: true
  "Date":     string,  required: true
  "Div":      string,  required: true
  "FTAG":     integer, required: true
  "FTHG":     integer, required: true
  "FTR":      string,  required: true
  "HTAG":     integer, required: true
  "HTHG":     integer, required: true
  "HTR":      string,  required: true
  "HomeTeam": string,  required: true
  "Season":   integer, required: true
}

Research

My goal is to create .proto file using proto3. So I decided to read the documentation for .proto3 files:

But I was even more confused. According to the docs, I cannot have a map holding values of different types:

For that I would need the equivalent of the JSON object type and check the docs for .struct.proto but that page doesn’t mention anything about it.

Question

So I am rather lost here. How do I represent the mentioned data structure in a .proto?

Marked As Solved

massimo

massimo

relying on my memory here

it should be something like this

message Result {
    string AwayTeam = 1
    string Date = 2
    string Div = 3
    int32 FTAG = 4
    int32 FTHG = 5
    string FTR = 6
    int32 HTAG = 7
    int32 HTHG = 8
    string HTR = 9
    string HomeTeam = 10
    int32 Season = 11
}

# Your final response type

message Response {
  repeated Result results = 1
}

# empty request 
message Request {}

# example service definition

service ServiceName  {
  rpc method_name (Request) returns (Reponse) {}
}


Also Liked

Fl4m3Ph03n1x

Fl4m3Ph03n1x

Your code is 99% accurate! You were only missing the semi-colons at the end:


"""
    syntax = "proto3";

    message Result {
      string AwayTeam = 1;
      string Date = 2;
      string Div = 3;
      int32 FTAG = 4;
      int32 FTHG = 5;
      string FTR = 6;
      int32 HTAG = 7;
      int32 HTHG = 8;
      string HTR = 9;
      string HomeTeam = 10;
      int32 Season = 11;
  }

  message Response {
    repeated Result results = 1;
  }

  message Request {}
  """

Now, while I don’t know if this will work as expected, I am happy that at least now it compiles !

Last Post!

Fl4m3Ph03n1x

Fl4m3Ph03n1x

Your code is 99% accurate! You were only missing the semi-colons at the end:


"""
    syntax = "proto3";

    message Result {
      string AwayTeam = 1;
      string Date = 2;
      string Div = 3;
      int32 FTAG = 4;
      int32 FTHG = 5;
      string FTR = 6;
      int32 HTAG = 7;
      int32 HTHG = 8;
      string HTR = 9;
      string HomeTeam = 10;
      int32 Season = 11;
  }

  message Response {
    repeated Result results = 1;
  }

  message Request {}
  """

Now, while I don’t know if this will work as expected, I am happy that at least now it compiles !

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement