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 !

Where Next?

Popular in Questions Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
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
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement