@@ -97,16 +97,27 @@ var errEmptyJSONContextStack = NewTProtocolExceptionWithType(INVALID_DATA, error
97
97
type TSimpleJSONProtocol struct {
98
98
trans TTransport
99
99
100
+ cfg * TConfiguration
101
+
100
102
parseContextStack jsonContextStack
101
103
dumpContext jsonContextStack
102
104
103
105
writer * bufio.Writer
104
106
reader * bufio.Reader
105
107
}
106
108
107
- // Constructor
109
+ // Deprecated: Use NewTSimpleJSONProtocolConf instead.:
108
110
func NewTSimpleJSONProtocol (t TTransport ) * TSimpleJSONProtocol {
109
- v := & TSimpleJSONProtocol {trans : t ,
111
+ return NewTSimpleJSONProtocolConf (t , & TConfiguration {
112
+ noPropagation : true ,
113
+ })
114
+ }
115
+
116
+ func NewTSimpleJSONProtocolConf (t TTransport , conf * TConfiguration ) * TSimpleJSONProtocol {
117
+ PropagateTConfiguration (t , conf )
118
+ v := & TSimpleJSONProtocol {
119
+ trans : t ,
120
+ cfg : conf ,
110
121
writer : bufio .NewWriter (t ),
111
122
reader : bufio .NewReader (t ),
112
123
}
@@ -116,14 +127,32 @@ func NewTSimpleJSONProtocol(t TTransport) *TSimpleJSONProtocol {
116
127
}
117
128
118
129
// Factory
119
- type TSimpleJSONProtocolFactory struct {}
130
+ type TSimpleJSONProtocolFactory struct {
131
+ cfg * TConfiguration
132
+ }
120
133
121
134
func (p * TSimpleJSONProtocolFactory ) GetProtocol (trans TTransport ) TProtocol {
122
- return NewTSimpleJSONProtocol (trans )
135
+ return NewTSimpleJSONProtocolConf (trans , p . cfg )
123
136
}
124
137
138
+ // SetTConfiguration implements TConfigurationSetter for propagation.
139
+ func (p * TSimpleJSONProtocolFactory ) SetTConfiguration (conf * TConfiguration ) {
140
+ p .cfg = conf
141
+ }
142
+
143
+ // Deprecated: Use NewTSimpleJSONProtocolFactoryConf instead.
125
144
func NewTSimpleJSONProtocolFactory () * TSimpleJSONProtocolFactory {
126
- return & TSimpleJSONProtocolFactory {}
145
+ return & TSimpleJSONProtocolFactory {
146
+ cfg : & TConfiguration {
147
+ noPropagation : true ,
148
+ },
149
+ }
150
+ }
151
+
152
+ func NewTSimpleJSONProtocolFactoryConf (conf * TConfiguration ) * TSimpleJSONProtocolFactory {
153
+ return & TSimpleJSONProtocolFactory {
154
+ cfg : conf ,
155
+ }
127
156
}
128
157
129
158
var (
@@ -399,6 +428,13 @@ func (p *TSimpleJSONProtocol) ReadMapBegin(ctx context.Context) (keyType TType,
399
428
400
429
// read size
401
430
iSize , err := p .ReadI64 (ctx )
431
+ if err != nil {
432
+ return keyType , valueType , 0 , err
433
+ }
434
+ err = checkSizeForProtocol (int32 (size ), p .cfg )
435
+ if err != nil {
436
+ return keyType , valueType , 0 , err
437
+ }
402
438
size = int (iSize )
403
439
return keyType , valueType , size , err
404
440
}
@@ -1070,9 +1106,16 @@ func (p *TSimpleJSONProtocol) ParseElemListBegin() (elemType TType, size int, e
1070
1106
if err != nil {
1071
1107
return elemType , size , err
1072
1108
}
1073
- nSize , _ , err2 := p .ParseI64 ()
1109
+ nSize , _ , err := p .ParseI64 ()
1110
+ if err != nil {
1111
+ return elemType , 0 , err
1112
+ }
1113
+ err = checkSizeForProtocol (int32 (nSize ), p .cfg )
1114
+ if err != nil {
1115
+ return elemType , 0 , err
1116
+ }
1074
1117
size = int (nSize )
1075
- return elemType , size , err2
1118
+ return elemType , size , nil
1076
1119
}
1077
1120
1078
1121
func (p * TSimpleJSONProtocol ) ParseListEnd () error {
@@ -1368,6 +1411,10 @@ func (p *TSimpleJSONProtocol) write(b []byte) (int, error) {
1368
1411
// SetTConfiguration implements TConfigurationSetter for propagation.
1369
1412
func (p * TSimpleJSONProtocol ) SetTConfiguration (conf * TConfiguration ) {
1370
1413
PropagateTConfiguration (p .trans , conf )
1414
+ p .cfg = conf
1371
1415
}
1372
1416
1373
- var _ TConfigurationSetter = (* TSimpleJSONProtocol )(nil )
1417
+ var (
1418
+ _ TConfigurationSetter = (* TSimpleJSONProtocol )(nil )
1419
+ _ TConfigurationSetter = (* TSimpleJSONProtocolFactory )(nil )
1420
+ )
0 commit comments