Saturday, 6 May 2017

Protocol Buffer

I'm trying to get my head around protocol buffers. I understood the basic stuff, but now I'm trying to define the following javascript object as a .proto. Using the Node.js gRPC Library

const listsSchema = new Schema({
    id: { type: String, required: true },
  id_str: { type: String, required: true, index: { unique: true } },
  name: { type: String, required: true },
  description: { type: String, required: true },
  slug: { type: String, required: true },
  createdAt: { type: Date, 'default': Date.now },
  updatedAt: { type: Date, 'default': Date.now },
  track: { type: Boolean, 'default': false },
  lastTrackedTweet: [
    { 
      id: { type: String, required: true },
      id_str: { type: String, required: true },
      createdAt: { type: Date, 'default': Date.now },
      updatedAt: { type: Date, 'default': Date.now }
        }
    ]
});

This is what I have come up with, but it is getting rejected.

syntax = "proto3";

package lists;

service Lists {
  rpc FindLists (ListRequest) returns (ListReply) {}
}

message ListRequest {
  struct params = 1;
}

message ListReply {
  repeated struct List = 1;
}

message List {
 int64 id = 1;
 string id_str = 2;
 string name = 3;
 string description = 4;
 string slug = 5;
 Timestamp createdAt = 6;
 Timestamp updatedAt = 7;
 bool track = 8;
 repeated struct LastTrackedTweet = 9;
}

message LastTrackedTweet {
  int64 id = 1;
  string id_str = 2;
  Timestamp createdAt = 3;
  Timestamp updatedAt = 4;
}



via Tino

No comments:

Post a Comment