tiziano88 / elm-protobuf

protobuf plugin for elm
https://package.elm-lang.org/packages/tiziano88/elm-protobuf/latest/
MIT License
94 stars 28 forks source link

LIst of items not decoding #4

Closed donpdonp closed 7 years ago

donpdonp commented 7 years ago

First thanks for the elm protobuf compiler, its fantastic and lets me roll my own websocket/json-rpc with protobuf+elm on one side and protobuf+go on the other. The compiled elm has been trouble-free until I tried to decode a list of objects (a "Schedule").

the js console shows elm received some json of apparently the right format

response: { id = "90de-18f43f9f486f", method = "ScheduleListResponse", object = { Ok = True, Schedules = { 0 = { Id = "schedules-877d-76499fe253ae", AccountId = "accounts-b8b0-6d34a035a65e", AlgorithmId = "noop", Status = "active" } } } }

after calling scheduleListResponseDecoder response.object, the decoded object, always has an empty array for Schedules.

ScheduleListResponseMsg { ok = True, message = "", schedules = [] }

the ScheduleListResponse protbuf is defined as

import "proto/schedule.proto";

message ScheduleListResponse {
  bool Ok = 1;
  string Message = 2;
  repeated Schedule Schedules = 3;
}

and the Schedule is

message Schedule {
  string Id = 1;
  string AccountId = 2;
  string AlgorithmId = 3;
  string Status = 4;
}

the Elm for ScheduleListResponse also looks good

type alias ScheduleListResponse =
    { ok : Bool -- 1
    , message : String -- 2
    , schedules : List Schedule -- 3
    }

scheduleListResponseDecoder : JD.Decoder ScheduleListResponse
scheduleListResponseDecoder =
    JD.lazy <| \_ -> decode ScheduleListResponse
        |> required "Ok" JD.bool False
        |> required "Message" JD.string ""
        |> repeated "Schedules" scheduleDecoder

any ideas what might be wrong?

tiziano88 commented 7 years ago

Should be fixed now, thanks a lot!