Skip to content

Instantly share code, notes, and snippets.

@dangreenisrael
Created March 1, 2019 03:12
Show Gist options
  • Save dangreenisrael/a695295c444de8dccb6b23d9c73745f7 to your computer and use it in GitHub Desktop.
Save dangreenisrael/a695295c444de8dccb6b23d9c73745f7 to your computer and use it in GitHub Desktop.
Protobuf => Typescript
// protobuf
// model.proto
syntax = "proto3";
package model;
message Collection {
optional string id = 1;
optional string name = 2;
optional string description = 3;
optional int64 created_ts_micros = 4;
repeated string subscriber_ids = 5;
repeated string items = 6;
}
message User {
optional string id = 1;
}
message Item {
optional string id = 1;
optional string url = 2;
optional int64 created_ts_micros = 3;
optional string author_id = 4;
}
// ts
import * as $protobuf from "protobufjs";
export namespace model {
interface ICollection {
id?: (string|null);
name?: (string|null);
description?: (string|null);
createdTsMicros?: (number|Long|null);
subscriberIds?: (string[]|null);
items?: (string[]|null);
}
class Collection implements ICollection {
constructor(properties?: model.ICollection);
public id: string;
public name: string;
public description: string;
public createdTsMicros: (number|Long);
public subscriberIds: string[];
public items: string[];
public static create(properties?: model.ICollection): model.Collection;
public static encode(message: model.ICollection, writer?: $protobuf.Writer): $protobuf.Writer;
public static encodeDelimited(message: model.ICollection, writer?: $protobuf.Writer): $protobuf.Writer;
public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): model.Collection;
public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): model.Collection;
public static verify(message: { [k: string]: any }): (string|null);
public static fromObject(object: { [k: string]: any }): model.Collection;
public static toObject(message: model.Collection, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
}
interface IUser {
id?: (string|null);
}
class User implements IUser {
constructor(properties?: model.IUser);
public id: string;
public static create(properties?: model.IUser): model.User;
public static encode(message: model.IUser, writer?: $protobuf.Writer): $protobuf.Writer;
public static encodeDelimited(message: model.IUser, writer?: $protobuf.Writer): $protobuf.Writer;
public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): model.User;
public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): model.User;
public static verify(message: { [k: string]: any }): (string|null);
public static fromObject(object: { [k: string]: any }): model.User;
public static toObject(message: model.User, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
}
interface IItem {
id?: (string|null);
url?: (string|null);
createdTsMicros?: (number|Long|null);
authorId?: (string|null);
}
class Item implements IItem {
constructor(properties?: model.IItem);
public id: string;
public url: string;
public createdTsMicros: (number|Long);
public authorId: string;
public static create(properties?: model.IItem): model.Item;
public static encode(message: model.IItem, writer?: $protobuf.Writer): $protobuf.Writer;
public static encodeDelimited(message: model.IItem, writer?: $protobuf.Writer): $protobuf.Writer;
public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): model.Item;
public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): model.Item;
public static verify(message: { [k: string]: any }): (string|null);
public static fromObject(object: { [k: string]: any }): model.Item;
public static toObject(message: model.Item, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment