Skip to content

Commit 69e53e0

Browse files
committed
Add doc comments to ExpectedJSONSize
1 parent b8a03aa commit 69e53e0

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

types/json_size.go

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package types
22

33
type ExpectedJSONSize interface {
4+
// ExpectedJSONSize returns the expected JSON size in bytes when using
5+
// json.Marshal with the given value.
6+
// Since JSON marshalling does not have a guaranteed output format,
7+
// this should be understood as a best guess and correct in most cases.
8+
// Do not use it when a precise value is required.
49
ExpectedJSONSize() int
510
}
611

12+
// ExpectedJSONSizeString returns the expected JSON size in bytes when using
13+
// json.Marshal with the given value.
14+
// Since JSON marshalling does not have a guaranteed output format,
15+
// this should be understood as a best guess and correct in most cases.
16+
// Do not use it when a precise value is required.
717
func ExpectedJSONSizeString(s string) int {
818
// 2x quote + length of string + escaping overhead
919
var out int = quotes + len(s)
@@ -25,6 +35,11 @@ func ExpectedJSONSizeString(s string) int {
2535
return out
2636
}
2737

38+
// ExpectedJSONSizeBinary returns the expected JSON size in bytes when using
39+
// json.Marshal with the given value.
40+
// Since JSON marshalling does not have a guaranteed output format,
41+
// this should be understood as a best guess and correct in most cases.
42+
// Do not use it when a precise value is required.
2843
func ExpectedJSONSizeBinary(b []byte) int {
2944
if b == nil {
3045
return null
@@ -34,6 +49,11 @@ func ExpectedJSONSizeBinary(b []byte) int {
3449
return b64Len + quotes
3550
}
3651

52+
// ExpectedJSONSizeInt returns the expected JSON size in bytes when using
53+
// json.Marshal with the given value.
54+
// Since JSON marshalling does not have a guaranteed output format,
55+
// this should be understood as a best guess and correct in most cases.
56+
// Do not use it when a precise value is required.
3757
func ExpectedJSONSizeInt(i int) int {
3858
out := 0
3959
// minus sign or zero
@@ -48,6 +68,11 @@ func ExpectedJSONSizeInt(i int) int {
4868
return out
4969
}
5070

71+
// ExpectedJSONSizeUint64 returns the expected JSON size in bytes when using
72+
// json.Marshal with the given value.
73+
// Since JSON marshalling does not have a guaranteed output format,
74+
// this should be understood as a best guess and correct in most cases.
75+
// Do not use it when a precise value is required.
5176
func ExpectedJSONSizeUint64(i uint64) int {
5277
if i == 0 {
5378
return 1
@@ -61,6 +86,11 @@ func ExpectedJSONSizeUint64(i uint64) int {
6186
return out
6287
}
6388

89+
// ExpectedJSONSizeBool returns the expected JSON size in bytes when using
90+
// json.Marshal with the given value.
91+
// Since JSON marshalling does not have a guaranteed output format,
92+
// this should be understood as a best guess and correct in most cases.
93+
// Do not use it when a precise value is required.
6494
func ExpectedJSONSizeBool(b bool) int {
6595
if b {
6696
return 4 // true
@@ -78,6 +108,11 @@ const (
78108
null int = 4 // null
79109
)
80110

111+
// ExpectedJSONSize returns the expected JSON size in bytes when using
112+
// json.Marshal with the given value.
113+
// Since JSON marshalling does not have a guaranteed output format,
114+
// this should be understood as a best guess and correct in most cases.
115+
// Do not use it when a precise value is required.
81116
func (t IBCEndpoint) ExpectedJSONSize() int {
82117
// PortID string `json:"port_id"`
83118
// ChannelID string `json:"channel_id"`
@@ -86,6 +121,11 @@ func (t IBCEndpoint) ExpectedJSONSize() int {
86121
12 + colon + ExpectedJSONSizeString(t.ChannelID)
87122
}
88123

124+
// ExpectedJSONSize returns the expected JSON size in bytes when using
125+
// json.Marshal with the given value.
126+
// Since JSON marshalling does not have a guaranteed output format,
127+
// this should be understood as a best guess and correct in most cases.
128+
// Do not use it when a precise value is required.
89129
func (t IBCChannel) ExpectedJSONSize() int {
90130
// Endpoint IBCEndpoint `json:"endpoint"`
91131
// CounterpartyEndpoint IBCEndpoint `json:"counterparty_endpoint"`
@@ -100,11 +140,21 @@ func (t IBCChannel) ExpectedJSONSize() int {
100140
15 + colon + ExpectedJSONSizeString(t.ConnectionID)
101141
}
102142

143+
// ExpectedJSONSize returns the expected JSON size in bytes when using
144+
// json.Marshal with the given value.
145+
// Since JSON marshalling does not have a guaranteed output format,
146+
// this should be understood as a best guess and correct in most cases.
147+
// Do not use it when a precise value is required.
103148
func (t IBCOpenInit) ExpectedJSONSize() int {
104149
// Channel IBCChannel `json:"channel"`
105150
return brackets + 9 + colon + t.Channel.ExpectedJSONSize()
106151
}
107152

153+
// ExpectedJSONSize returns the expected JSON size in bytes when using
154+
// json.Marshal with the given value.
155+
// Since JSON marshalling does not have a guaranteed output format,
156+
// this should be understood as a best guess and correct in most cases.
157+
// Do not use it when a precise value is required.
108158
func (t IBCOpenTry) ExpectedJSONSize() int {
109159
// Channel IBCChannel `json:"channel"`
110160
// CounterpartyVersion string `json:"counterparty_version"`
@@ -113,6 +163,11 @@ func (t IBCOpenTry) ExpectedJSONSize() int {
113163
22 + colon + ExpectedJSONSizeString(t.CounterpartyVersion)
114164
}
115165

166+
// ExpectedJSONSize returns the expected JSON size in bytes when using
167+
// json.Marshal with the given value.
168+
// Since JSON marshalling does not have a guaranteed output format,
169+
// this should be understood as a best guess and correct in most cases.
170+
// Do not use it when a precise value is required.
116171
func (t IBCChannelOpenMsg) ExpectedJSONSize() int {
117172
// OpenInit *IBCOpenInit `json:"open_init,omitempty"`
118173
// OpenTry *IBCOpenTry `json:"open_try,omitempty"`
@@ -130,6 +185,11 @@ func (t IBCChannelOpenMsg) ExpectedJSONSize() int {
130185
return out
131186
}
132187

188+
// ExpectedJSONSize returns the expected JSON size in bytes when using
189+
// json.Marshal with the given value.
190+
// Since JSON marshalling does not have a guaranteed output format,
191+
// this should be understood as a best guess and correct in most cases.
192+
// Do not use it when a precise value is required.
133193
func (t IBCOpenAck) ExpectedJSONSize() int {
134194
// Channel IBCChannel `json:"channel"`
135195
// CounterpartyVersion string `json:"counterparty_version"`
@@ -138,11 +198,21 @@ func (t IBCOpenAck) ExpectedJSONSize() int {
138198
22 + colon + ExpectedJSONSizeString(t.CounterpartyVersion)
139199
}
140200

201+
// ExpectedJSONSize returns the expected JSON size in bytes when using
202+
// json.Marshal with the given value.
203+
// Since JSON marshalling does not have a guaranteed output format,
204+
// this should be understood as a best guess and correct in most cases.
205+
// Do not use it when a precise value is required.
141206
func (t IBCOpenConfirm) ExpectedJSONSize() int {
142207
// Channel IBCChannel `json:"channel"`
143208
return brackets + 9 + colon + t.Channel.ExpectedJSONSize()
144209
}
145210

211+
// ExpectedJSONSize returns the expected JSON size in bytes when using
212+
// json.Marshal with the given value.
213+
// Since JSON marshalling does not have a guaranteed output format,
214+
// this should be understood as a best guess and correct in most cases.
215+
// Do not use it when a precise value is required.
146216
func (t IBCChannelConnectMsg) ExpectedJSONSize() int {
147217
// OpenAck *IBCOpenAck `json:"open_ack,omitempty"`
148218
// OpenConfirm *IBCOpenConfirm `json:"open_confirm,omitempty"`
@@ -160,16 +230,31 @@ func (t IBCChannelConnectMsg) ExpectedJSONSize() int {
160230
return out
161231
}
162232

233+
// ExpectedJSONSize returns the expected JSON size in bytes when using
234+
// json.Marshal with the given value.
235+
// Since JSON marshalling does not have a guaranteed output format,
236+
// this should be understood as a best guess and correct in most cases.
237+
// Do not use it when a precise value is required.
163238
func (t IBCCloseInit) ExpectedJSONSize() int {
164239
// Channel IBCChannel `json:"channel"`
165240
return brackets + 9 + colon + t.Channel.ExpectedJSONSize()
166241
}
167242

243+
// ExpectedJSONSize returns the expected JSON size in bytes when using
244+
// json.Marshal with the given value.
245+
// Since JSON marshalling does not have a guaranteed output format,
246+
// this should be understood as a best guess and correct in most cases.
247+
// Do not use it when a precise value is required.
168248
func (t IBCCloseConfirm) ExpectedJSONSize() int {
169249
// Channel IBCChannel `json:"channel"`
170250
return brackets + 9 + colon + t.Channel.ExpectedJSONSize()
171251
}
172252

253+
// ExpectedJSONSize returns the expected JSON size in bytes when using
254+
// json.Marshal with the given value.
255+
// Since JSON marshalling does not have a guaranteed output format,
256+
// this should be understood as a best guess and correct in most cases.
257+
// Do not use it when a precise value is required.
173258
func (t IBCChannelCloseMsg) ExpectedJSONSize() int {
174259
// CloseInit *IBCCloseInit `json:"close_init,omitempty"`
175260
// CloseConfirm *IBCCloseConfirm `json:"close_confirm,omitempty"`
@@ -187,6 +272,11 @@ func (t IBCChannelCloseMsg) ExpectedJSONSize() int {
187272
return out
188273
}
189274

275+
// ExpectedJSONSize returns the expected JSON size in bytes when using
276+
// json.Marshal with the given value.
277+
// Since JSON marshalling does not have a guaranteed output format,
278+
// this should be understood as a best guess and correct in most cases.
279+
// Do not use it when a precise value is required.
190280
func (t IBCTimeoutBlock) ExpectedJSONSize() int {
191281
// Revision uint64 `json:"revision"`
192282
// Height uint64 `json:"height"`
@@ -195,6 +285,11 @@ func (t IBCTimeoutBlock) ExpectedJSONSize() int {
195285
8 + colon + ExpectedJSONSizeUint64(t.Height)
196286
}
197287

288+
// ExpectedJSONSize returns the expected JSON size in bytes when using
289+
// json.Marshal with the given value.
290+
// Since JSON marshalling does not have a guaranteed output format,
291+
// this should be understood as a best guess and correct in most cases.
292+
// Do not use it when a precise value is required.
198293
func (t IBCTimeout) ExpectedJSONSize() int {
199294
// Block *IBCTimeoutBlock `json:"block"`
200295
// Timestamp uint64 `json:"timestamp,string,omitempty"`
@@ -213,6 +308,11 @@ func (t IBCTimeout) ExpectedJSONSize() int {
213308
return out
214309
}
215310

311+
// ExpectedJSONSize returns the expected JSON size in bytes when using
312+
// json.Marshal with the given value.
313+
// Since JSON marshalling does not have a guaranteed output format,
314+
// this should be understood as a best guess and correct in most cases.
315+
// Do not use it when a precise value is required.
216316
func (t IBCPacket) ExpectedJSONSize() int {
217317
// Data []byte `json:"data"`
218318
// Src IBCEndpoint `json:"src"`
@@ -227,12 +327,22 @@ func (t IBCPacket) ExpectedJSONSize() int {
227327
9 + colon + t.Timeout.ExpectedJSONSize()
228328
}
229329

330+
// ExpectedJSONSize returns the expected JSON size in bytes when using
331+
// json.Marshal with the given value.
332+
// Since JSON marshalling does not have a guaranteed output format,
333+
// this should be understood as a best guess and correct in most cases.
334+
// Do not use it when a precise value is required.
230335
func (t IBCAcknowledgement) ExpectedJSONSize() int {
231336
// Data []byte `json:"data"`
232337
return brackets +
233338
6 + colon + ExpectedJSONSizeBinary(t.Data)
234339
}
235340

341+
// ExpectedJSONSize returns the expected JSON size in bytes when using
342+
// json.Marshal with the given value.
343+
// Since JSON marshalling does not have a guaranteed output format,
344+
// this should be understood as a best guess and correct in most cases.
345+
// Do not use it when a precise value is required.
236346
func (t IBCPacketReceiveMsg) ExpectedJSONSize() int {
237347
// Packet IBCPacket `json:"packet"`
238348
// Relayer string `json:"relayer"`
@@ -241,6 +351,11 @@ func (t IBCPacketReceiveMsg) ExpectedJSONSize() int {
241351
9 + colon + ExpectedJSONSizeString(t.Relayer)
242352
}
243353

354+
// ExpectedJSONSize returns the expected JSON size in bytes when using
355+
// json.Marshal with the given value.
356+
// Since JSON marshalling does not have a guaranteed output format,
357+
// this should be understood as a best guess and correct in most cases.
358+
// Do not use it when a precise value is required.
244359
func (t IBCPacketAckMsg) ExpectedJSONSize() int {
245360
// Acknowledgement IBCAcknowledgement `json:"acknowledgement"`
246361
// OriginalPacket IBCPacket `json:"original_packet"`
@@ -251,6 +366,11 @@ func (t IBCPacketAckMsg) ExpectedJSONSize() int {
251366
9 + colon + ExpectedJSONSizeString(t.Relayer)
252367
}
253368

369+
// ExpectedJSONSize returns the expected JSON size in bytes when using
370+
// json.Marshal with the given value.
371+
// Since JSON marshalling does not have a guaranteed output format,
372+
// this should be understood as a best guess and correct in most cases.
373+
// Do not use it when a precise value is required.
254374
func (t IBCPacketTimeoutMsg) ExpectedJSONSize() int {
255375
// Packet IBCPacket `json:"packet"`
256376
// Relayer string `json:"relayer"`
@@ -259,6 +379,11 @@ func (t IBCPacketTimeoutMsg) ExpectedJSONSize() int {
259379
9 + colon + ExpectedJSONSizeString(t.Relayer)
260380
}
261381

382+
// ExpectedJSONSize returns the expected JSON size in bytes when using
383+
// json.Marshal with the given value.
384+
// Since JSON marshalling does not have a guaranteed output format,
385+
// this should be understood as a best guess and correct in most cases.
386+
// Do not use it when a precise value is required.
262387
func (t IBCAckCallbackMsg) ExpectedJSONSize() int {
263388
// Acknowledgement IBCAcknowledgement `json:"acknowledgement"`
264389
// OriginalPacket IBCPacket `json:"original_packet"`
@@ -269,6 +394,11 @@ func (t IBCAckCallbackMsg) ExpectedJSONSize() int {
269394
9 + colon + ExpectedJSONSizeString(t.Relayer)
270395
}
271396

397+
// ExpectedJSONSize returns the expected JSON size in bytes when using
398+
// json.Marshal with the given value.
399+
// Since JSON marshalling does not have a guaranteed output format,
400+
// this should be understood as a best guess and correct in most cases.
401+
// Do not use it when a precise value is required.
272402
func (t IBCTimeoutCallbackMsg) ExpectedJSONSize() int {
273403
// Packet IBCPacket `json:"packet"`
274404
// Relayer string `json:"relayer"`
@@ -277,6 +407,11 @@ func (t IBCTimeoutCallbackMsg) ExpectedJSONSize() int {
277407
9 + colon + ExpectedJSONSizeString(t.Relayer)
278408
}
279409

410+
// ExpectedJSONSize returns the expected JSON size in bytes when using
411+
// json.Marshal with the given value.
412+
// Since JSON marshalling does not have a guaranteed output format,
413+
// this should be understood as a best guess and correct in most cases.
414+
// Do not use it when a precise value is required.
280415
func (t IBCSourceCallbackMsg) ExpectedJSONSize() int {
281416
// Acknowledgement *IBCAckCallbackMsg `json:"acknowledgement,omitempty"`
282417
// Timeout *IBCTimeoutCallbackMsg `json:"timeout,omitempty"`
@@ -297,6 +432,11 @@ func (t IBCSourceCallbackMsg) ExpectedJSONSize() int {
297432
return out
298433
}
299434

435+
// ExpectedJSONSize returns the expected JSON size in bytes when using
436+
// json.Marshal with the given value.
437+
// Since JSON marshalling does not have a guaranteed output format,
438+
// this should be understood as a best guess and correct in most cases.
439+
// Do not use it when a precise value is required.
300440
func (t IBCDestinationCallbackMsg) ExpectedJSONSize() int {
301441
// Ack IBCAcknowledgement `json:"ack"`
302442
// Packet IBCPacket `json:"packet"`

0 commit comments

Comments
 (0)