@@ -60,12 +60,17 @@ func (u *unmarshalGen) Execute(p Elem) ([]string, error) {
60
60
u .p .printf ("\n return ((*(%s))(%s)).UnmarshalMsg(bts)" , baseType , c )
61
61
u .p .printf ("\n }" )
62
62
63
+ u .p .printf ("\n func (%s %s) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) ([]byte, error) {" , c , methodRecv )
64
+ u .p .printf ("\n return ((*(%s))(%s)).UnmarshalMsgWithState(bts, st)" , baseType , c )
65
+ u .p .printf ("\n }" )
66
+
63
67
u .p .printf ("\n func (_ %[2]s) CanUnmarshalMsg(%[1]s interface{}) bool {" , c , methodRecv )
64
68
u .p .printf ("\n _, ok := (%s).(%s)" , c , methodRecv )
65
69
u .p .printf ("\n return ok" )
66
70
u .p .printf ("\n }" )
67
71
68
72
u .topics .Add (methodRecv , "UnmarshalMsg" )
73
+ u .topics .Add (methodRecv , "UnmarshalMsgWithState" )
69
74
u .topics .Add (methodRecv , "CanUnmarshalMsg" )
70
75
71
76
return u .msgs , u .p .err
@@ -75,7 +80,12 @@ func (u *unmarshalGen) Execute(p Elem) ([]string, error) {
75
80
c := p .Varname ()
76
81
methodRecv := methodReceiver (p )
77
82
78
- u .p .printf ("\n func (%s %s) UnmarshalMsg(bts []byte) (o []byte, err error) {" , c , methodRecv )
83
+ u .p .printf ("\n func (%s %s) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error) {" , c , methodRecv )
84
+ u .p .printf ("\n if st.Depth == 0 {" )
85
+ u .p .printf ("\n err = msgp.ErrMaxDepthExceeded{}" )
86
+ u .p .printf ("\n return" )
87
+ u .p .printf ("\n }" )
88
+ u .p .printf ("\n st.Depth--" )
79
89
next (u , p )
80
90
u .p .print ("\n o = bts" )
81
91
@@ -91,12 +101,17 @@ func (u *unmarshalGen) Execute(p Elem) ([]string, error) {
91
101
}
92
102
u .p .nakedReturn ()
93
103
104
+ u .p .printf ("\n func (%s %s) UnmarshalMsg(bts []byte) (o []byte, err error) {" , c , methodRecv )
105
+ u .p .printf ("\n return %s.UnmarshalMsgWithState(bts, msgp.DefaultUnmarshalState)" , c )
106
+ u .p .printf ("\n }" )
107
+
94
108
u .p .printf ("\n func (_ %[2]s) CanUnmarshalMsg(%[1]s interface{}) bool {" , c , methodRecv )
95
109
u .p .printf ("\n _, ok := (%s).(%s)" , c , methodRecv )
96
110
u .p .printf ("\n return ok" )
97
111
u .p .printf ("\n }" )
98
112
99
113
u .topics .Add (methodRecv , "UnmarshalMsg" )
114
+ u .topics .Add (methodRecv , "UnmarshalMsgWithState" )
100
115
u .topics .Add (methodRecv , "CanUnmarshalMsg" )
101
116
102
117
return u .msgs , u .p .err
@@ -236,7 +251,7 @@ func (u *unmarshalGen) gBase(b *BaseElem) {
236
251
case Ext :
237
252
u .p .printf ("\n bts, err = msgp.ReadExtensionBytes(bts, %s)" , lowered )
238
253
case IDENT :
239
- u .p .printf ("\n bts, err = %s.UnmarshalMsg (bts)" , lowered )
254
+ u .p .printf ("\n bts, err = %s.UnmarshalMsgWithState (bts, st )" , lowered )
240
255
case String :
241
256
if b .common .AllocBound () != "" {
242
257
sz := randIdent ()
0 commit comments