-
Notifications
You must be signed in to change notification settings - Fork 1
/
haberdasher.pb.ts
183 lines (167 loc) · 3.92 KB
/
haberdasher.pb.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
// Source: src/haberdasher.proto
/* eslint-disable */
import type { ByteSource, PartialDeep } from "protoscript";
import * as protoscript from "protoscript";
import * as srcSize from "./size.pb";
//========================================//
// Types //
//========================================//
/**
* A Hat is a piece of headwear made by a Haberdasher.
*/
export interface Hat {
size: srcSize.Size;
/**
* anything but "invisible"
*/
color: string;
/**
* i.e. "bowler"
*/
name: string;
}
//========================================//
// Protobuf Encode / Decode //
//========================================//
export const Hat = {
/**
* Serializes Hat to protobuf.
*/
encode: function (msg: PartialDeep<Hat>): Uint8Array {
return Hat._writeMessage(
msg,
new protoscript.BinaryWriter(),
).getResultBuffer();
},
/**
* Deserializes Hat from protobuf.
*/
decode: function (bytes: ByteSource): Hat {
return Hat._readMessage(
Hat.initialize(),
new protoscript.BinaryReader(bytes),
);
},
/**
* Initializes Hat with all fields set to their default value.
*/
initialize: function (msg?: Partial<Hat>): Hat {
return {
size: srcSize.Size.initialize(),
color: "",
name: "",
...msg,
};
},
/**
* @private
*/
_writeMessage: function (
msg: PartialDeep<Hat>,
writer: protoscript.BinaryWriter,
): protoscript.BinaryWriter {
if (msg.size) {
writer.writeMessage(1, msg.size, srcSize.Size._writeMessage);
}
if (msg.color) {
writer.writeString(2, msg.color);
}
if (msg.name) {
writer.writeString(3, msg.name);
}
return writer;
},
/**
* @private
*/
_readMessage: function (msg: Hat, reader: protoscript.BinaryReader): Hat {
while (reader.nextField()) {
const field = reader.getFieldNumber();
switch (field) {
case 1: {
reader.readMessage(msg.size, srcSize.Size._readMessage);
break;
}
case 2: {
msg.color = reader.readString();
break;
}
case 3: {
msg.name = reader.readString();
break;
}
default: {
reader.skipField();
break;
}
}
}
return msg;
},
};
//========================================//
// JSON Encode / Decode //
//========================================//
export const HatJSON = {
/**
* Serializes Hat to JSON.
*/
encode: function (msg: PartialDeep<Hat>): string {
return JSON.stringify(HatJSON._writeMessage(msg));
},
/**
* Deserializes Hat from JSON.
*/
decode: function (json: string): Hat {
return HatJSON._readMessage(HatJSON.initialize(), JSON.parse(json));
},
/**
* Initializes Hat with all fields set to their default value.
*/
initialize: function (msg?: Partial<Hat>): Hat {
return {
size: srcSize.SizeJSON.initialize(),
color: "",
name: "",
...msg,
};
},
/**
* @private
*/
_writeMessage: function (msg: PartialDeep<Hat>): Record<string, unknown> {
const json: Record<string, unknown> = {};
if (msg.size) {
const _size_ = srcSize.SizeJSON._writeMessage(msg.size);
if (Object.keys(_size_).length > 0) {
json["size"] = _size_;
}
}
if (msg.color) {
json["color"] = msg.color;
}
if (msg.name) {
json["name"] = msg.name;
}
return json;
},
/**
* @private
*/
_readMessage: function (msg: Hat, json: any): Hat {
const _size_ = json["size"];
if (_size_) {
srcSize.SizeJSON._readMessage(msg.size, _size_);
}
const _color_ = json["color"];
if (_color_) {
msg.color = _color_;
}
const _name_ = json["name"];
if (_name_) {
msg.name = _name_;
}
return msg;
},
};