@@ -108,6 +108,37 @@ const (
108
108
null int = 4 // null
109
109
)
110
110
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.
116
+ func (c Coin ) ExpectedJSONSize () int {
117
+ // Denom string `json:"denom"`
118
+ // Amount string `json:"amount"`
119
+ return brackets +
120
+ 7 + colon + ExpectedJSONSizeString (c .Denom ) + comma +
121
+ 8 + colon + ExpectedJSONSizeString (c .Amount )
122
+ }
123
+
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.
129
+ //
130
+ // This is a free-standing function because methods don't support constraining the generic type.
131
+ func ExpectedJSONSizeArray [T ExpectedJSONSize ](a Array [T ]) int {
132
+ out := brackets
133
+ for i , v := range a {
134
+ if i > 0 {
135
+ out += comma
136
+ }
137
+ out += v .ExpectedJSONSize ()
138
+ }
139
+ return out
140
+ }
141
+
111
142
// ExpectedJSONSize returns the expected JSON size in bytes when using
112
143
// json.Marshal with the given value.
113
144
// Since JSON marshalling does not have a guaranteed output format,
@@ -440,7 +471,29 @@ func (t IBCSourceCallbackMsg) ExpectedJSONSize() int {
440
471
func (t IBCDestinationCallbackMsg ) ExpectedJSONSize () int {
441
472
// Ack IBCAcknowledgement `json:"ack"`
442
473
// Packet IBCPacket `json:"packet"`
443
- return brackets +
474
+ // Transfer *IBCTransfer `json:"transfer,omitempty"`
475
+ out := brackets +
444
476
5 + colon + t .Ack .ExpectedJSONSize () + comma +
445
477
8 + colon + t .Packet .ExpectedJSONSize ()
478
+
479
+ if t .Transfer != nil {
480
+ out += comma + 10 + colon + t .Transfer .ExpectedJSONSize ()
481
+ }
482
+
483
+ return out
484
+ }
485
+
486
+ // ExpectedJSONSize returns the expected JSON size in bytes when using
487
+ // json.Marshal with the given value.
488
+ // Since JSON marshalling does not have a guaranteed output format,
489
+ // this should be understood as a best guess and correct in most cases.
490
+ // Do not use it when a precise value is required.
491
+ func (t IBCTransferCallback ) ExpectedJSONSize () int {
492
+ // Funds Array[Coin] `json:"funds"`
493
+ // Receiver string `json:"receiver"`
494
+ // Sender string `json:"sender"`
495
+ return brackets +
496
+ 7 + colon + ExpectedJSONSizeArray (t .Funds ) + comma +
497
+ 10 + colon + ExpectedJSONSizeString (t .Receiver ) + comma +
498
+ 8 + colon + ExpectedJSONSizeString (t .Sender )
446
499
}
0 commit comments