1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20package thrift 21 22import ( 23 "bufio" 24 "bytes" 25 "context" 26 "encoding/base64" 27 "encoding/json" 28 "errors" 29 "fmt" 30 "io" 31 "math" 32 "strconv" 33) 34 35type _ParseContext int 36 37const ( 38 _CONTEXT_INVALID _ParseContext = iota 39 _CONTEXT_IN_TOPLEVEL // 1 40 _CONTEXT_IN_LIST_FIRST // 2 41 _CONTEXT_IN_LIST // 3 42 _CONTEXT_IN_OBJECT_FIRST // 4 43 _CONTEXT_IN_OBJECT_NEXT_KEY // 5 44 _CONTEXT_IN_OBJECT_NEXT_VALUE // 6 45) 46 47func (p _ParseContext) String() string { 48 switch p { 49 case _CONTEXT_IN_TOPLEVEL: 50 return "TOPLEVEL" 51 case _CONTEXT_IN_LIST_FIRST: 52 return "LIST-FIRST" 53 case _CONTEXT_IN_LIST: 54 return "LIST" 55 case _CONTEXT_IN_OBJECT_FIRST: 56 return "OBJECT-FIRST" 57 case _CONTEXT_IN_OBJECT_NEXT_KEY: 58 return "OBJECT-NEXT-KEY" 59 case _CONTEXT_IN_OBJECT_NEXT_VALUE: 60 return "OBJECT-NEXT-VALUE" 61 } 62 return "UNKNOWN-PARSE-CONTEXT" 63} 64 65type jsonContextStack []_ParseContext 66 67func (s *jsonContextStack) push(v _ParseContext) { 68 *s = append(*s, v) 69} 70 71func (s jsonContextStack) peek() (v _ParseContext, ok bool) { 72 l := len(s) 73 if l <= 0 { 74 return 75 } 76 return s[l-1], true 77} 78 79func (s *jsonContextStack) pop() (v _ParseContext, ok bool) { 80 l := len(*s) 81 if l <= 0 { 82 return 83 } 84 v = (*s)[l-1] 85 *s = (*s)[0 : l-1] 86 return v, true 87} 88 89var errEmptyJSONContextStack = NewTProtocolExceptionWithType(INVALID_DATA, errors.New("Unexpected empty json protocol context stack")) 90 91// Simple JSON protocol implementation for thrift. 92// 93// This protocol produces/consumes a simple output format 94// suitable for parsing by scripting languages. It should not be 95// confused with the full-featured TJSONProtocol. 96type TSimpleJSONProtocol struct { 97 trans TTransport 98 99 cfg *TConfiguration 100 101 parseContextStack jsonContextStack 102 dumpContext jsonContextStack 103 104 writer *bufio.Writer 105 reader *bufio.Reader 106} 107 108// Deprecated: Use NewTSimpleJSONProtocolConf instead.: 109func NewTSimpleJSONProtocol(t TTransport) *TSimpleJSONProtocol { 110 return NewTSimpleJSONProtocolConf(t, &TConfiguration{ 111 noPropagation: true, 112 }) 113} 114 115func NewTSimpleJSONProtocolConf(t TTransport, conf *TConfiguration) *TSimpleJSONProtocol { 116 PropagateTConfiguration(t, conf) 117 v := &TSimpleJSONProtocol{ 118 trans: t, 119 cfg: conf, 120 writer: bufio.NewWriter(t), 121 reader: bufio.NewReader(t), 122 } 123 v.resetContextStack() 124 return v 125} 126 127// Factory 128type TSimpleJSONProtocolFactory struct { 129 cfg *TConfiguration 130} 131 132func (p *TSimpleJSONProtocolFactory) GetProtocol(trans TTransport) TProtocol { 133 return NewTSimpleJSONProtocolConf(trans, p.cfg) 134} 135 136// SetTConfiguration implements TConfigurationSetter for propagation. 137func (p *TSimpleJSONProtocolFactory) SetTConfiguration(conf *TConfiguration) { 138 p.cfg = conf 139} 140 141// Deprecated: Use NewTSimpleJSONProtocolFactoryConf instead. 142func NewTSimpleJSONProtocolFactory() *TSimpleJSONProtocolFactory { 143 return &TSimpleJSONProtocolFactory{ 144 cfg: &TConfiguration{ 145 noPropagation: true, 146 }, 147 } 148} 149 150func NewTSimpleJSONProtocolFactoryConf(conf *TConfiguration) *TSimpleJSONProtocolFactory { 151 return &TSimpleJSONProtocolFactory{ 152 cfg: conf, 153 } 154} 155 156var ( 157 JSON_COMMA []byte 158 JSON_COLON []byte 159 JSON_LBRACE []byte 160 JSON_RBRACE []byte 161 JSON_LBRACKET []byte 162 JSON_RBRACKET []byte 163 JSON_QUOTE byte 164 JSON_QUOTE_BYTES []byte 165 JSON_NULL []byte 166 JSON_TRUE []byte 167 JSON_FALSE []byte 168 JSON_INFINITY string 169 JSON_NEGATIVE_INFINITY string 170 JSON_NAN string 171 JSON_INFINITY_BYTES []byte 172 JSON_NEGATIVE_INFINITY_BYTES []byte 173 JSON_NAN_BYTES []byte 174) 175 176func init() { 177 JSON_COMMA = []byte{','} 178 JSON_COLON = []byte{':'} 179 JSON_LBRACE = []byte{'{'} 180 JSON_RBRACE = []byte{'}'} 181 JSON_LBRACKET = []byte{'['} 182 JSON_RBRACKET = []byte{']'} 183 JSON_QUOTE = '"' 184 JSON_QUOTE_BYTES = []byte{'"'} 185 JSON_NULL = []byte{'n', 'u', 'l', 'l'} 186 JSON_TRUE = []byte{'t', 'r', 'u', 'e'} 187 JSON_FALSE = []byte{'f', 'a', 'l', 's', 'e'} 188 JSON_INFINITY = "Infinity" 189 JSON_NEGATIVE_INFINITY = "-Infinity" 190 JSON_NAN = "NaN" 191 JSON_INFINITY_BYTES = []byte{'I', 'n', 'f', 'i', 'n', 'i', 't', 'y'} 192 JSON_NEGATIVE_INFINITY_BYTES = []byte{'-', 'I', 'n', 'f', 'i', 'n', 'i', 't', 'y'} 193 JSON_NAN_BYTES = []byte{'N', 'a', 'N'} 194} 195 196func jsonQuote(s string) string { 197 b, _ := json.Marshal(s) 198 s1 := string(b) 199 return s1 200} 201 202func jsonUnquote(s string) (string, bool) { 203 s1 := new(string) 204 err := json.Unmarshal([]byte(s), s1) 205 return *s1, err == nil 206} 207 208func mismatch(expected, actual string) error { 209 return fmt.Errorf("Expected '%s' but found '%s' while parsing JSON.", expected, actual) 210} 211 212func (p *TSimpleJSONProtocol) WriteMessageBegin(ctx context.Context, name string, typeId TMessageType, seqId int32) error { 213 p.resetContextStack() // THRIFT-3735 214 if e := p.OutputListBegin(); e != nil { 215 return e 216 } 217 if e := p.WriteString(ctx, name); e != nil { 218 return e 219 } 220 if e := p.WriteByte(ctx, int8(typeId)); e != nil { 221 return e 222 } 223 if e := p.WriteI32(ctx, seqId); e != nil { 224 return e 225 } 226 return nil 227} 228 229func (p *TSimpleJSONProtocol) WriteMessageEnd(ctx context.Context) error { 230 return p.OutputListEnd() 231} 232 233func (p *TSimpleJSONProtocol) WriteStructBegin(ctx context.Context, name string) error { 234 if e := p.OutputObjectBegin(); e != nil { 235 return e 236 } 237 return nil 238} 239 240func (p *TSimpleJSONProtocol) WriteStructEnd(ctx context.Context) error { 241 return p.OutputObjectEnd() 242} 243 244func (p *TSimpleJSONProtocol) WriteFieldBegin(ctx context.Context, name string, typeId TType, id int16) error { 245 if e := p.WriteString(ctx, name); e != nil { 246 return e 247 } 248 return nil 249} 250 251func (p *TSimpleJSONProtocol) WriteFieldEnd(ctx context.Context) error { 252 return nil 253} 254 255func (p *TSimpleJSONProtocol) WriteFieldStop(ctx context.Context) error { return nil } 256 257func (p *TSimpleJSONProtocol) WriteMapBegin(ctx context.Context, keyType TType, valueType TType, size int) error { 258 if e := p.OutputListBegin(); e != nil { 259 return e 260 } 261 if e := p.WriteByte(ctx, int8(keyType)); e != nil { 262 return e 263 } 264 if e := p.WriteByte(ctx, int8(valueType)); e != nil { 265 return e 266 } 267 return p.WriteI32(ctx, int32(size)) 268} 269 270func (p *TSimpleJSONProtocol) WriteMapEnd(ctx context.Context) error { 271 return p.OutputListEnd() 272} 273 274func (p *TSimpleJSONProtocol) WriteListBegin(ctx context.Context, elemType TType, size int) error { 275 return p.OutputElemListBegin(elemType, size) 276} 277 278func (p *TSimpleJSONProtocol) WriteListEnd(ctx context.Context) error { 279 return p.OutputListEnd() 280} 281 282func (p *TSimpleJSONProtocol) WriteSetBegin(ctx context.Context, elemType TType, size int) error { 283 return p.OutputElemListBegin(elemType, size) 284} 285 286func (p *TSimpleJSONProtocol) WriteSetEnd(ctx context.Context) error { 287 return p.OutputListEnd() 288} 289 290func (p *TSimpleJSONProtocol) WriteBool(ctx context.Context, b bool) error { 291 return p.OutputBool(b) 292} 293 294func (p *TSimpleJSONProtocol) WriteByte(ctx context.Context, b int8) error { 295 return p.WriteI32(ctx, int32(b)) 296} 297 298func (p *TSimpleJSONProtocol) WriteI16(ctx context.Context, v int16) error { 299 return p.WriteI32(ctx, int32(v)) 300} 301 302func (p *TSimpleJSONProtocol) WriteI32(ctx context.Context, v int32) error { 303 return p.OutputI64(int64(v)) 304} 305 306func (p *TSimpleJSONProtocol) WriteI64(ctx context.Context, v int64) error { 307 return p.OutputI64(int64(v)) 308} 309 310func (p *TSimpleJSONProtocol) WriteDouble(ctx context.Context, v float64) error { 311 return p.OutputF64(v) 312} 313 314func (p *TSimpleJSONProtocol) WriteString(ctx context.Context, v string) error { 315 return p.OutputString(v) 316} 317 318func (p *TSimpleJSONProtocol) WriteBinary(ctx context.Context, v []byte) error { 319 // JSON library only takes in a string, 320 // not an arbitrary byte array, to ensure bytes are transmitted 321 // efficiently we must convert this into a valid JSON string 322 // therefore we use base64 encoding to avoid excessive escaping/quoting 323 if e := p.OutputPreValue(); e != nil { 324 return e 325 } 326 if _, e := p.write(JSON_QUOTE_BYTES); e != nil { 327 return NewTProtocolException(e) 328 } 329 writer := base64.NewEncoder(base64.StdEncoding, p.writer) 330 if _, e := writer.Write(v); e != nil { 331 p.writer.Reset(p.trans) // THRIFT-3735 332 return NewTProtocolException(e) 333 } 334 if e := writer.Close(); e != nil { 335 return NewTProtocolException(e) 336 } 337 if _, e := p.write(JSON_QUOTE_BYTES); e != nil { 338 return NewTProtocolException(e) 339 } 340 return p.OutputPostValue() 341} 342 343func (p *TSimpleJSONProtocol) WriteUUID(ctx context.Context, v Tuuid) error { 344 return p.OutputString(v.String()) 345} 346 347// Reading methods. 348func (p *TSimpleJSONProtocol) ReadMessageBegin(ctx context.Context) (name string, typeId TMessageType, seqId int32, err error) { 349 p.resetContextStack() // THRIFT-3735 350 if isNull, err := p.ParseListBegin(); isNull || err != nil { 351 return name, typeId, seqId, err 352 } 353 if name, err = p.ReadString(ctx); err != nil { 354 return name, typeId, seqId, err 355 } 356 bTypeId, err := p.ReadByte(ctx) 357 typeId = TMessageType(bTypeId) 358 if err != nil { 359 return name, typeId, seqId, err 360 } 361 if seqId, err = p.ReadI32(ctx); err != nil { 362 return name, typeId, seqId, err 363 } 364 return name, typeId, seqId, nil 365} 366 367func (p *TSimpleJSONProtocol) ReadMessageEnd(ctx context.Context) error { 368 return p.ParseListEnd() 369} 370 371func (p *TSimpleJSONProtocol) ReadStructBegin(ctx context.Context) (name string, err error) { 372 _, err = p.ParseObjectStart() 373 return "", err 374} 375 376func (p *TSimpleJSONProtocol) ReadStructEnd(ctx context.Context) error { 377 return p.ParseObjectEnd() 378} 379 380func (p *TSimpleJSONProtocol) ReadFieldBegin(ctx context.Context) (string, TType, int16, error) { 381 if err := p.ParsePreValue(); err != nil { 382 return "", STOP, 0, err 383 } 384 b, _ := p.reader.Peek(1) 385 if len(b) > 0 { 386 switch b[0] { 387 case JSON_RBRACE[0]: 388 return "", STOP, 0, nil 389 case JSON_QUOTE: 390 p.reader.ReadByte() 391 name, err := p.ParseStringBody() 392 // simplejson is not meant to be read back into thrift 393 // - see http://wiki.apache.org/thrift/ThriftUsageJava 394 // - use JSON instead 395 if err != nil { 396 return name, STOP, 0, err 397 } 398 return name, STOP, -1, p.ParsePostValue() 399 } 400 e := fmt.Errorf("Expected \"}\" or '\"', but found: '%s'", string(b)) 401 return "", STOP, 0, NewTProtocolExceptionWithType(INVALID_DATA, e) 402 } 403 return "", STOP, 0, NewTProtocolException(io.EOF) 404} 405 406func (p *TSimpleJSONProtocol) ReadFieldEnd(ctx context.Context) error { 407 return nil 408} 409 410func (p *TSimpleJSONProtocol) ReadMapBegin(ctx context.Context) (keyType TType, valueType TType, size int, e error) { 411 if isNull, e := p.ParseListBegin(); isNull || e != nil { 412 return VOID, VOID, 0, e 413 } 414 415 // read keyType 416 bKeyType, e := p.ReadByte(ctx) 417 keyType = TType(bKeyType) 418 if e != nil { 419 return keyType, valueType, size, e 420 } 421 422 // read valueType 423 bValueType, e := p.ReadByte(ctx) 424 valueType = TType(bValueType) 425 if e != nil { 426 return keyType, valueType, size, e 427 } 428 429 // read size 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 } 438 size = int(iSize) 439 return keyType, valueType, size, err 440} 441 442func (p *TSimpleJSONProtocol) ReadMapEnd(ctx context.Context) error { 443 return p.ParseListEnd() 444} 445 446func (p *TSimpleJSONProtocol) ReadListBegin(ctx context.Context) (elemType TType, size int, e error) { 447 return p.ParseElemListBegin() 448} 449 450func (p *TSimpleJSONProtocol) ReadListEnd(ctx context.Context) error { 451 return p.ParseListEnd() 452} 453 454func (p *TSimpleJSONProtocol) ReadSetBegin(ctx context.Context) (elemType TType, size int, e error) { 455 return p.ParseElemListBegin() 456} 457 458func (p *TSimpleJSONProtocol) ReadSetEnd(ctx context.Context) error { 459 return p.ParseListEnd() 460} 461 462func (p *TSimpleJSONProtocol) ReadBool(ctx context.Context) (bool, error) { 463 var value bool 464 465 if err := p.ParsePreValue(); err != nil { 466 return value, err 467 } 468 f, _ := p.reader.Peek(1) 469 if len(f) > 0 { 470 switch f[0] { 471 case JSON_TRUE[0]: 472 b := make([]byte, len(JSON_TRUE)) 473 _, err := p.reader.Read(b) 474 if err != nil { 475 return false, NewTProtocolException(err) 476 } 477 if string(b) == string(JSON_TRUE) { 478 value = true 479 } else { 480 e := fmt.Errorf("Expected \"true\" but found: %s", string(b)) 481 return value, NewTProtocolExceptionWithType(INVALID_DATA, e) 482 } 483 case JSON_FALSE[0]: 484 b := make([]byte, len(JSON_FALSE)) 485 _, err := p.reader.Read(b) 486 if err != nil { 487 return false, NewTProtocolException(err) 488 } 489 if string(b) == string(JSON_FALSE) { 490 value = false 491 } else { 492 e := fmt.Errorf("Expected \"false\" but found: %s", string(b)) 493 return value, NewTProtocolExceptionWithType(INVALID_DATA, e) 494 } 495 case JSON_NULL[0]: 496 b := make([]byte, len(JSON_NULL)) 497 _, err := p.reader.Read(b) 498 if err != nil { 499 return false, NewTProtocolException(err) 500 } 501 if string(b) == string(JSON_NULL) { 502 value = false 503 } else { 504 e := fmt.Errorf("Expected \"null\" but found: %s", string(b)) 505 return value, NewTProtocolExceptionWithType(INVALID_DATA, e) 506 } 507 default: 508 e := fmt.Errorf("Expected \"true\", \"false\", or \"null\" but found: %s", string(f)) 509 return value, NewTProtocolExceptionWithType(INVALID_DATA, e) 510 } 511 } 512 return value, p.ParsePostValue() 513} 514 515func (p *TSimpleJSONProtocol) ReadByte(ctx context.Context) (int8, error) { 516 v, err := p.ReadI64(ctx) 517 return int8(v), err 518} 519 520func (p *TSimpleJSONProtocol) ReadI16(ctx context.Context) (int16, error) { 521 v, err := p.ReadI64(ctx) 522 return int16(v), err 523} 524 525func (p *TSimpleJSONProtocol) ReadI32(ctx context.Context) (int32, error) { 526 v, err := p.ReadI64(ctx) 527 return int32(v), err 528} 529 530func (p *TSimpleJSONProtocol) ReadI64(ctx context.Context) (int64, error) { 531 v, _, err := p.ParseI64() 532 return v, err 533} 534 535func (p *TSimpleJSONProtocol) ReadDouble(ctx context.Context) (float64, error) { 536 v, _, err := p.ParseF64() 537 return v, err 538} 539 540func (p *TSimpleJSONProtocol) ReadString(ctx context.Context) (string, error) { 541 var v string 542 if err := p.ParsePreValue(); err != nil { 543 return v, err 544 } 545 f, _ := p.reader.Peek(1) 546 if len(f) > 0 && f[0] == JSON_QUOTE { 547 p.reader.ReadByte() 548 value, err := p.ParseStringBody() 549 v = value 550 if err != nil { 551 return v, err 552 } 553 } else if len(f) > 0 && f[0] == JSON_NULL[0] { 554 b := make([]byte, len(JSON_NULL)) 555 _, err := p.reader.Read(b) 556 if err != nil { 557 return v, NewTProtocolException(err) 558 } 559 if string(b) != string(JSON_NULL) { 560 e := fmt.Errorf("Expected a JSON string, found unquoted data started with %s", string(b)) 561 return v, NewTProtocolExceptionWithType(INVALID_DATA, e) 562 } 563 } else { 564 e := fmt.Errorf("Expected a JSON string, found unquoted data started with %s", string(f)) 565 return v, NewTProtocolExceptionWithType(INVALID_DATA, e) 566 } 567 return v, p.ParsePostValue() 568} 569 570func (p *TSimpleJSONProtocol) ReadBinary(ctx context.Context) ([]byte, error) { 571 var v []byte 572 if err := p.ParsePreValue(); err != nil { 573 return nil, err 574 } 575 f, _ := p.reader.Peek(1) 576 if len(f) > 0 && f[0] == JSON_QUOTE { 577 p.reader.ReadByte() 578 value, err := p.ParseBase64EncodedBody() 579 v = value 580 if err != nil { 581 return v, err 582 } 583 } else if len(f) > 0 && f[0] == JSON_NULL[0] { 584 b := make([]byte, len(JSON_NULL)) 585 _, err := p.reader.Read(b) 586 if err != nil { 587 return v, NewTProtocolException(err) 588 } 589 if string(b) != string(JSON_NULL) { 590 e := fmt.Errorf("Expected a JSON string, found unquoted data started with %s", string(b)) 591 return v, NewTProtocolExceptionWithType(INVALID_DATA, e) 592 } 593 } else { 594 e := fmt.Errorf("Expected a JSON string, found unquoted data started with %s", string(f)) 595 return v, NewTProtocolExceptionWithType(INVALID_DATA, e) 596 } 597 598 return v, p.ParsePostValue() 599} 600 601func (p *TSimpleJSONProtocol) ReadUUID(ctx context.Context) (v Tuuid, err error) { 602 var s string 603 s, err = p.ReadString(ctx) 604 if err != nil { 605 return v, err 606 } 607 v, err = ParseTuuid(s) 608 return v, NewTProtocolExceptionWithType(INVALID_DATA, err) 609} 610 611func (p *TSimpleJSONProtocol) Flush(ctx context.Context) (err error) { 612 return NewTProtocolException(p.writer.Flush()) 613} 614 615func (p *TSimpleJSONProtocol) Skip(ctx context.Context, fieldType TType) (err error) { 616 return SkipDefaultDepth(ctx, p, fieldType) 617} 618 619func (p *TSimpleJSONProtocol) Transport() TTransport { 620 return p.trans 621} 622 623func (p *TSimpleJSONProtocol) OutputPreValue() error { 624 cxt, ok := p.dumpContext.peek() 625 if !ok { 626 return errEmptyJSONContextStack 627 } 628 switch cxt { 629 case _CONTEXT_IN_LIST, _CONTEXT_IN_OBJECT_NEXT_KEY: 630 if _, e := p.write(JSON_COMMA); e != nil { 631 return NewTProtocolException(e) 632 } 633 case _CONTEXT_IN_OBJECT_NEXT_VALUE: 634 if _, e := p.write(JSON_COLON); e != nil { 635 return NewTProtocolException(e) 636 } 637 } 638 return nil 639} 640 641func (p *TSimpleJSONProtocol) OutputPostValue() error { 642 cxt, ok := p.dumpContext.peek() 643 if !ok { 644 return errEmptyJSONContextStack 645 } 646 switch cxt { 647 case _CONTEXT_IN_LIST_FIRST: 648 p.dumpContext.pop() 649 p.dumpContext.push(_CONTEXT_IN_LIST) 650 case _CONTEXT_IN_OBJECT_FIRST: 651 p.dumpContext.pop() 652 p.dumpContext.push(_CONTEXT_IN_OBJECT_NEXT_VALUE) 653 case _CONTEXT_IN_OBJECT_NEXT_KEY: 654 p.dumpContext.pop() 655 p.dumpContext.push(_CONTEXT_IN_OBJECT_NEXT_VALUE) 656 case _CONTEXT_IN_OBJECT_NEXT_VALUE: 657 p.dumpContext.pop() 658 p.dumpContext.push(_CONTEXT_IN_OBJECT_NEXT_KEY) 659 } 660 return nil 661} 662 663func (p *TSimpleJSONProtocol) OutputBool(value bool) error { 664 if e := p.OutputPreValue(); e != nil { 665 return e 666 } 667 var v string 668 if value { 669 v = string(JSON_TRUE) 670 } else { 671 v = string(JSON_FALSE) 672 } 673 cxt, ok := p.dumpContext.peek() 674 if !ok { 675 return errEmptyJSONContextStack 676 } 677 switch cxt { 678 case _CONTEXT_IN_OBJECT_FIRST, _CONTEXT_IN_OBJECT_NEXT_KEY: 679 v = jsonQuote(v) 680 } 681 if e := p.OutputStringData(v); e != nil { 682 return e 683 } 684 return p.OutputPostValue() 685} 686 687func (p *TSimpleJSONProtocol) OutputNull() error { 688 if e := p.OutputPreValue(); e != nil { 689 return e 690 } 691 if _, e := p.write(JSON_NULL); e != nil { 692 return NewTProtocolException(e) 693 } 694 return p.OutputPostValue() 695} 696 697func (p *TSimpleJSONProtocol) OutputF64(value float64) error { 698 if e := p.OutputPreValue(); e != nil { 699 return e 700 } 701 var v string 702 if math.IsNaN(value) { 703 v = string(JSON_QUOTE) + JSON_NAN + string(JSON_QUOTE) 704 } else if math.IsInf(value, 1) { 705 v = string(JSON_QUOTE) + JSON_INFINITY + string(JSON_QUOTE) 706 } else if math.IsInf(value, -1) { 707 v = string(JSON_QUOTE) + JSON_NEGATIVE_INFINITY + string(JSON_QUOTE) 708 } else { 709 cxt, ok := p.dumpContext.peek() 710 if !ok { 711 return errEmptyJSONContextStack 712 } 713 v = strconv.FormatFloat(value, 'g', -1, 64) 714 switch cxt { 715 case _CONTEXT_IN_OBJECT_FIRST, _CONTEXT_IN_OBJECT_NEXT_KEY: 716 v = string(JSON_QUOTE) + v + string(JSON_QUOTE) 717 } 718 } 719 if e := p.OutputStringData(v); e != nil { 720 return e 721 } 722 return p.OutputPostValue() 723} 724 725func (p *TSimpleJSONProtocol) OutputI64(value int64) error { 726 if e := p.OutputPreValue(); e != nil { 727 return e 728 } 729 cxt, ok := p.dumpContext.peek() 730 if !ok { 731 return errEmptyJSONContextStack 732 } 733 v := strconv.FormatInt(value, 10) 734 switch cxt { 735 case _CONTEXT_IN_OBJECT_FIRST, _CONTEXT_IN_OBJECT_NEXT_KEY: 736 v = jsonQuote(v) 737 } 738 if e := p.OutputStringData(v); e != nil { 739 return e 740 } 741 return p.OutputPostValue() 742} 743 744func (p *TSimpleJSONProtocol) OutputString(s string) error { 745 if e := p.OutputPreValue(); e != nil { 746 return e 747 } 748 if e := p.OutputStringData(jsonQuote(s)); e != nil { 749 return e 750 } 751 return p.OutputPostValue() 752} 753 754func (p *TSimpleJSONProtocol) OutputStringData(s string) error { 755 _, e := p.write([]byte(s)) 756 return NewTProtocolException(e) 757} 758 759func (p *TSimpleJSONProtocol) OutputObjectBegin() error { 760 if e := p.OutputPreValue(); e != nil { 761 return e 762 } 763 if _, e := p.write(JSON_LBRACE); e != nil { 764 return NewTProtocolException(e) 765 } 766 p.dumpContext.push(_CONTEXT_IN_OBJECT_FIRST) 767 return nil 768} 769 770func (p *TSimpleJSONProtocol) OutputObjectEnd() error { 771 if _, e := p.write(JSON_RBRACE); e != nil { 772 return NewTProtocolException(e) 773 } 774 _, ok := p.dumpContext.pop() 775 if !ok { 776 return errEmptyJSONContextStack 777 } 778 if e := p.OutputPostValue(); e != nil { 779 return e 780 } 781 return nil 782} 783 784func (p *TSimpleJSONProtocol) OutputListBegin() error { 785 if e := p.OutputPreValue(); e != nil { 786 return e 787 } 788 if _, e := p.write(JSON_LBRACKET); e != nil { 789 return NewTProtocolException(e) 790 } 791 p.dumpContext.push(_CONTEXT_IN_LIST_FIRST) 792 return nil 793} 794 795func (p *TSimpleJSONProtocol) OutputListEnd() error { 796 if _, e := p.write(JSON_RBRACKET); e != nil { 797 return NewTProtocolException(e) 798 } 799 _, ok := p.dumpContext.pop() 800 if !ok { 801 return errEmptyJSONContextStack 802 } 803 if e := p.OutputPostValue(); e != nil { 804 return e 805 } 806 return nil 807} 808 809func (p *TSimpleJSONProtocol) OutputElemListBegin(elemType TType, size int) error { 810 if e := p.OutputListBegin(); e != nil { 811 return e 812 } 813 if e := p.OutputI64(int64(elemType)); e != nil { 814 return e 815 } 816 if e := p.OutputI64(int64(size)); e != nil { 817 return e 818 } 819 return nil 820} 821 822func (p *TSimpleJSONProtocol) ParsePreValue() error { 823 if e := p.readNonSignificantWhitespace(); e != nil { 824 return NewTProtocolException(e) 825 } 826 cxt, ok := p.parseContextStack.peek() 827 if !ok { 828 return errEmptyJSONContextStack 829 } 830 b, _ := p.reader.Peek(1) 831 switch cxt { 832 case _CONTEXT_IN_LIST: 833 if len(b) > 0 { 834 switch b[0] { 835 case JSON_RBRACKET[0]: 836 return nil 837 case JSON_COMMA[0]: 838 p.reader.ReadByte() 839 if e := p.readNonSignificantWhitespace(); e != nil { 840 return NewTProtocolException(e) 841 } 842 return nil 843 default: 844 e := fmt.Errorf("Expected \"]\" or \",\" in list context, but found \"%s\"", string(b)) 845 return NewTProtocolExceptionWithType(INVALID_DATA, e) 846 } 847 } 848 case _CONTEXT_IN_OBJECT_NEXT_KEY: 849 if len(b) > 0 { 850 switch b[0] { 851 case JSON_RBRACE[0]: 852 return nil 853 case JSON_COMMA[0]: 854 p.reader.ReadByte() 855 if e := p.readNonSignificantWhitespace(); e != nil { 856 return NewTProtocolException(e) 857 } 858 return nil 859 default: 860 e := fmt.Errorf("Expected \"}\" or \",\" in object context, but found \"%s\"", string(b)) 861 return NewTProtocolExceptionWithType(INVALID_DATA, e) 862 } 863 } 864 case _CONTEXT_IN_OBJECT_NEXT_VALUE: 865 if len(b) > 0 { 866 switch b[0] { 867 case JSON_COLON[0]: 868 p.reader.ReadByte() 869 if e := p.readNonSignificantWhitespace(); e != nil { 870 return NewTProtocolException(e) 871 } 872 return nil 873 default: 874 e := fmt.Errorf("Expected \":\" in object context, but found \"%s\"", string(b)) 875 return NewTProtocolExceptionWithType(INVALID_DATA, e) 876 } 877 } 878 } 879 return nil 880} 881 882func (p *TSimpleJSONProtocol) ParsePostValue() error { 883 if e := p.readNonSignificantWhitespace(); e != nil { 884 return NewTProtocolException(e) 885 } 886 cxt, ok := p.parseContextStack.peek() 887 if !ok { 888 return errEmptyJSONContextStack 889 } 890 switch cxt { 891 case _CONTEXT_IN_LIST_FIRST: 892 p.parseContextStack.pop() 893 p.parseContextStack.push(_CONTEXT_IN_LIST) 894 case _CONTEXT_IN_OBJECT_FIRST, _CONTEXT_IN_OBJECT_NEXT_KEY: 895 p.parseContextStack.pop() 896 p.parseContextStack.push(_CONTEXT_IN_OBJECT_NEXT_VALUE) 897 case _CONTEXT_IN_OBJECT_NEXT_VALUE: 898 p.parseContextStack.pop() 899 p.parseContextStack.push(_CONTEXT_IN_OBJECT_NEXT_KEY) 900 } 901 return nil 902} 903 904func (p *TSimpleJSONProtocol) readNonSignificantWhitespace() error { 905 for { 906 b, _ := p.reader.Peek(1) 907 if len(b) < 1 { 908 return nil 909 } 910 switch b[0] { 911 case ' ', '\r', '\n', '\t': 912 p.reader.ReadByte() 913 continue 914 } 915 break 916 } 917 return nil 918} 919 920func (p *TSimpleJSONProtocol) ParseStringBody() (string, error) { 921 line, err := p.reader.ReadString(JSON_QUOTE) 922 if err != nil { 923 return "", NewTProtocolException(err) 924 } 925 l := len(line) 926 // count number of escapes to see if we need to keep going 927 i := 1 928 for ; i < l; i++ { 929 if line[l-i-1] != '\\' { 930 break 931 } 932 } 933 if i&0x01 == 1 { 934 v, ok := jsonUnquote(string(JSON_QUOTE) + line) 935 if !ok { 936 return "", NewTProtocolException(err) 937 } 938 return v, nil 939 } 940 s, err := p.ParseQuotedStringBody() 941 if err != nil { 942 return "", NewTProtocolException(err) 943 } 944 str := string(JSON_QUOTE) + line + s 945 v, ok := jsonUnquote(str) 946 if !ok { 947 e := fmt.Errorf("Unable to parse as JSON string %s", str) 948 return "", NewTProtocolExceptionWithType(INVALID_DATA, e) 949 } 950 return v, nil 951} 952 953func (p *TSimpleJSONProtocol) ParseQuotedStringBody() (string, error) { 954 line, err := p.reader.ReadString(JSON_QUOTE) 955 if err != nil { 956 return "", NewTProtocolException(err) 957 } 958 l := len(line) 959 // count number of escapes to see if we need to keep going 960 i := 1 961 for ; i < l; i++ { 962 if line[l-i-1] != '\\' { 963 break 964 } 965 } 966 if i&0x01 == 1 { 967 return line, nil 968 } 969 s, err := p.ParseQuotedStringBody() 970 if err != nil { 971 return "", NewTProtocolException(err) 972 } 973 v := line + s 974 return v, nil 975} 976 977func (p *TSimpleJSONProtocol) ParseBase64EncodedBody() ([]byte, error) { 978 line, err := p.reader.ReadBytes(JSON_QUOTE) 979 if err != nil { 980 return line, NewTProtocolException(err) 981 } 982 line2 := line[0 : len(line)-1] 983 l := len(line2) 984 if (l % 4) != 0 { 985 pad := 4 - (l % 4) 986 fill := [...]byte{'=', '=', '='} 987 line2 = append(line2, fill[:pad]...) 988 l = len(line2) 989 } 990 output := make([]byte, base64.StdEncoding.DecodedLen(l)) 991 n, err := base64.StdEncoding.Decode(output, line2) 992 return output[0:n], NewTProtocolException(err) 993} 994 995func (p *TSimpleJSONProtocol) ParseI64() (int64, bool, error) { 996 if err := p.ParsePreValue(); err != nil { 997 return 0, false, err 998 } 999 var value int64 1000 var isnull bool 1001 if p.safePeekContains(JSON_NULL) { 1002 p.reader.Read(make([]byte, len(JSON_NULL))) 1003 isnull = true 1004 } else { 1005 num, err := p.readNumeric() 1006 isnull = (num == nil) 1007 if !isnull { 1008 value = num.Int64() 1009 } 1010 if err != nil { 1011 return value, isnull, err 1012 } 1013 } 1014 return value, isnull, p.ParsePostValue() 1015} 1016 1017func (p *TSimpleJSONProtocol) ParseF64() (float64, bool, error) { 1018 if err := p.ParsePreValue(); err != nil { 1019 return 0, false, err 1020 } 1021 var value float64 1022 var isnull bool 1023 if p.safePeekContains(JSON_NULL) { 1024 p.reader.Read(make([]byte, len(JSON_NULL))) 1025 isnull = true 1026 } else { 1027 num, err := p.readNumeric() 1028 isnull = (num == nil) 1029 if !isnull { 1030 value = num.Float64() 1031 } 1032 if err != nil { 1033 return value, isnull, err 1034 } 1035 } 1036 return value, isnull, p.ParsePostValue() 1037} 1038 1039func (p *TSimpleJSONProtocol) ParseObjectStart() (bool, error) { 1040 if err := p.ParsePreValue(); err != nil { 1041 return false, err 1042 } 1043 var b []byte 1044 b, err := p.reader.Peek(1) 1045 if err != nil { 1046 return false, err 1047 } 1048 if len(b) > 0 && b[0] == JSON_LBRACE[0] { 1049 p.reader.ReadByte() 1050 p.parseContextStack.push(_CONTEXT_IN_OBJECT_FIRST) 1051 return false, nil 1052 } else if p.safePeekContains(JSON_NULL) { 1053 return true, nil 1054 } 1055 e := fmt.Errorf("Expected '{' or null, but found '%s'", string(b)) 1056 return false, NewTProtocolExceptionWithType(INVALID_DATA, e) 1057} 1058 1059func (p *TSimpleJSONProtocol) ParseObjectEnd() error { 1060 if isNull, err := p.readIfNull(); isNull || err != nil { 1061 return err 1062 } 1063 cxt, _ := p.parseContextStack.peek() 1064 if (cxt != _CONTEXT_IN_OBJECT_FIRST) && (cxt != _CONTEXT_IN_OBJECT_NEXT_KEY) { 1065 e := fmt.Errorf("Expected to be in the Object Context, but not in Object Context (%d)", cxt) 1066 return NewTProtocolExceptionWithType(INVALID_DATA, e) 1067 } 1068 line, err := p.reader.ReadString(JSON_RBRACE[0]) 1069 if err != nil { 1070 return NewTProtocolException(err) 1071 } 1072 for _, char := range line { 1073 switch char { 1074 default: 1075 e := fmt.Errorf("Expecting end of object \"}\", but found: \"%s\"", line) 1076 return NewTProtocolExceptionWithType(INVALID_DATA, e) 1077 case ' ', '\n', '\r', '\t', '}': 1078 // do nothing 1079 } 1080 } 1081 p.parseContextStack.pop() 1082 return p.ParsePostValue() 1083} 1084 1085func (p *TSimpleJSONProtocol) ParseListBegin() (isNull bool, err error) { 1086 if e := p.ParsePreValue(); e != nil { 1087 return false, e 1088 } 1089 var b []byte 1090 b, err = p.reader.Peek(1) 1091 if err != nil { 1092 return false, err 1093 } 1094 if len(b) >= 1 && b[0] == JSON_LBRACKET[0] { 1095 p.parseContextStack.push(_CONTEXT_IN_LIST_FIRST) 1096 p.reader.ReadByte() 1097 isNull = false 1098 } else if p.safePeekContains(JSON_NULL) { 1099 isNull = true 1100 } else { 1101 err = fmt.Errorf("Expected \"null\" or \"[\", received %q", b) 1102 } 1103 return isNull, NewTProtocolExceptionWithType(INVALID_DATA, err) 1104} 1105 1106func (p *TSimpleJSONProtocol) ParseElemListBegin() (elemType TType, size int, e error) { 1107 if isNull, e := p.ParseListBegin(); isNull || e != nil { 1108 return VOID, 0, e 1109 } 1110 bElemType, _, err := p.ParseI64() 1111 elemType = TType(bElemType) 1112 if err != nil { 1113 return elemType, size, err 1114 } 1115 nSize, _, err := p.ParseI64() 1116 if err != nil { 1117 return elemType, 0, err 1118 } 1119 err = checkSizeForProtocol(int32(nSize), p.cfg) 1120 if err != nil { 1121 return elemType, 0, err 1122 } 1123 size = int(nSize) 1124 return elemType, size, nil 1125} 1126 1127func (p *TSimpleJSONProtocol) ParseListEnd() error { 1128 if isNull, err := p.readIfNull(); isNull || err != nil { 1129 return err 1130 } 1131 cxt, _ := p.parseContextStack.peek() 1132 if cxt != _CONTEXT_IN_LIST { 1133 e := fmt.Errorf("Expected to be in the List Context, but not in List Context (%d)", cxt) 1134 return NewTProtocolExceptionWithType(INVALID_DATA, e) 1135 } 1136 line, err := p.reader.ReadString(JSON_RBRACKET[0]) 1137 if err != nil { 1138 return NewTProtocolException(err) 1139 } 1140 for _, char := range line { 1141 switch char { 1142 default: 1143 e := fmt.Errorf("Expecting end of list \"]\", but found: \"%v\"", line) 1144 return NewTProtocolExceptionWithType(INVALID_DATA, e) 1145 case ' ', '\n', '\r', '\t', rune(JSON_RBRACKET[0]): 1146 // do nothing 1147 } 1148 } 1149 p.parseContextStack.pop() 1150 if cxt, ok := p.parseContextStack.peek(); !ok { 1151 return errEmptyJSONContextStack 1152 } else if cxt == _CONTEXT_IN_TOPLEVEL { 1153 return nil 1154 } 1155 return p.ParsePostValue() 1156} 1157 1158func (p *TSimpleJSONProtocol) readIfNull() (bool, error) { 1159 cont := true 1160 for cont { 1161 b, _ := p.reader.Peek(1) 1162 if len(b) < 1 { 1163 return false, nil 1164 } 1165 switch b[0] { 1166 default: 1167 return false, nil 1168 case JSON_NULL[0]: 1169 cont = false 1170 case ' ', '\n', '\r', '\t': 1171 p.reader.ReadByte() 1172 } 1173 } 1174 if p.safePeekContains(JSON_NULL) { 1175 p.reader.Read(make([]byte, len(JSON_NULL))) 1176 return true, nil 1177 } 1178 return false, nil 1179} 1180 1181func (p *TSimpleJSONProtocol) readQuoteIfNext() { 1182 b, _ := p.reader.Peek(1) 1183 if len(b) > 0 && b[0] == JSON_QUOTE { 1184 p.reader.ReadByte() 1185 } 1186} 1187 1188func (p *TSimpleJSONProtocol) readNumeric() (Numeric, error) { 1189 isNull, err := p.readIfNull() 1190 if isNull || err != nil { 1191 return NUMERIC_NULL, err 1192 } 1193 hasDecimalPoint := false 1194 nextCanBeSign := true 1195 hasE := false 1196 MAX_LEN := 40 1197 buf := bytes.NewBuffer(make([]byte, 0, MAX_LEN)) 1198 continueFor := true 1199 inQuotes := false 1200 for continueFor { 1201 c, err := p.reader.ReadByte() 1202 if err != nil { 1203 if err == io.EOF { 1204 break 1205 } 1206 return NUMERIC_NULL, NewTProtocolException(err) 1207 } 1208 switch c { 1209 case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': 1210 buf.WriteByte(c) 1211 nextCanBeSign = false 1212 case '.': 1213 if hasDecimalPoint { 1214 e := fmt.Errorf("Unable to parse number with multiple decimal points '%s.'", buf.String()) 1215 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1216 } 1217 if hasE { 1218 e := fmt.Errorf("Unable to parse number with decimal points in the exponent '%s.'", buf.String()) 1219 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1220 } 1221 buf.WriteByte(c) 1222 hasDecimalPoint, nextCanBeSign = true, false 1223 case 'e', 'E': 1224 if hasE { 1225 e := fmt.Errorf("Unable to parse number with multiple exponents '%s%c'", buf.String(), c) 1226 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1227 } 1228 buf.WriteByte(c) 1229 hasE, nextCanBeSign = true, true 1230 case '-', '+': 1231 if !nextCanBeSign { 1232 e := fmt.Errorf("Negative sign within number") 1233 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1234 } 1235 buf.WriteByte(c) 1236 nextCanBeSign = false 1237 case ' ', 0, '\t', '\n', '\r', JSON_RBRACE[0], JSON_RBRACKET[0], JSON_COMMA[0], JSON_COLON[0]: 1238 p.reader.UnreadByte() 1239 continueFor = false 1240 case JSON_NAN[0]: 1241 if buf.Len() == 0 { 1242 buffer := make([]byte, len(JSON_NAN)) 1243 buffer[0] = c 1244 _, e := p.reader.Read(buffer[1:]) 1245 if e != nil { 1246 return NUMERIC_NULL, NewTProtocolException(e) 1247 } 1248 if JSON_NAN != string(buffer) { 1249 e := mismatch(JSON_NAN, string(buffer)) 1250 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1251 } 1252 if inQuotes { 1253 p.readQuoteIfNext() 1254 } 1255 return NAN, nil 1256 } else { 1257 e := fmt.Errorf("Unable to parse number starting with character '%c'", c) 1258 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1259 } 1260 case JSON_INFINITY[0]: 1261 if buf.Len() == 0 || (buf.Len() == 1 && buf.Bytes()[0] == '+') { 1262 buffer := make([]byte, len(JSON_INFINITY)) 1263 buffer[0] = c 1264 _, e := p.reader.Read(buffer[1:]) 1265 if e != nil { 1266 return NUMERIC_NULL, NewTProtocolException(e) 1267 } 1268 if JSON_INFINITY != string(buffer) { 1269 e := mismatch(JSON_INFINITY, string(buffer)) 1270 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1271 } 1272 if inQuotes { 1273 p.readQuoteIfNext() 1274 } 1275 return INFINITY, nil 1276 } else if buf.Len() == 1 && buf.Bytes()[0] == JSON_NEGATIVE_INFINITY[0] { 1277 buffer := make([]byte, len(JSON_NEGATIVE_INFINITY)) 1278 buffer[0] = JSON_NEGATIVE_INFINITY[0] 1279 buffer[1] = c 1280 _, e := p.reader.Read(buffer[2:]) 1281 if e != nil { 1282 return NUMERIC_NULL, NewTProtocolException(e) 1283 } 1284 if JSON_NEGATIVE_INFINITY != string(buffer) { 1285 e := mismatch(JSON_NEGATIVE_INFINITY, string(buffer)) 1286 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1287 } 1288 if inQuotes { 1289 p.readQuoteIfNext() 1290 } 1291 return NEGATIVE_INFINITY, nil 1292 } else { 1293 e := fmt.Errorf("Unable to parse number starting with character '%c' due to existing buffer %s", c, buf.String()) 1294 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1295 } 1296 case JSON_QUOTE: 1297 if !inQuotes { 1298 inQuotes = true 1299 } 1300 default: 1301 e := fmt.Errorf("Unable to parse number starting with character '%c'", c) 1302 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1303 } 1304 } 1305 if buf.Len() == 0 { 1306 e := fmt.Errorf("Unable to parse number from empty string ''") 1307 return NUMERIC_NULL, NewTProtocolExceptionWithType(INVALID_DATA, e) 1308 } 1309 return NewNumericFromJSONString(buf.String(), false), nil 1310} 1311 1312// Safely peeks into the buffer, reading only what is necessary 1313func (p *TSimpleJSONProtocol) safePeekContains(b []byte) bool { 1314 for i := 0; i < len(b); i++ { 1315 a, _ := p.reader.Peek(i + 1) 1316 if len(a) < (i+1) || a[i] != b[i] { 1317 return false 1318 } 1319 } 1320 return true 1321} 1322 1323// Reset the context stack to its initial state. 1324func (p *TSimpleJSONProtocol) resetContextStack() { 1325 p.parseContextStack = jsonContextStack{_CONTEXT_IN_TOPLEVEL} 1326 p.dumpContext = jsonContextStack{_CONTEXT_IN_TOPLEVEL} 1327} 1328 1329func (p *TSimpleJSONProtocol) write(b []byte) (int, error) { 1330 n, err := p.writer.Write(b) 1331 if err != nil { 1332 p.writer.Reset(p.trans) // THRIFT-3735 1333 } 1334 return n, err 1335} 1336 1337// SetTConfiguration implements TConfigurationSetter for propagation. 1338func (p *TSimpleJSONProtocol) SetTConfiguration(conf *TConfiguration) { 1339 PropagateTConfiguration(p.trans, conf) 1340 p.cfg = conf 1341} 1342 1343// Reset resets this protocol's internal state. 1344// 1345// It's useful when a single protocol instance is reused after errors, to make 1346// sure the next use will not be in a bad state to begin with. An example is 1347// when it's used in serializer/deserializer pools. 1348func (p *TSimpleJSONProtocol) Reset() { 1349 p.resetContextStack() 1350 p.writer.Reset(p.trans) 1351 p.reader.Reset(p.trans) 1352} 1353 1354var ( 1355 _ TConfigurationSetter = (*TSimpleJSONProtocol)(nil) 1356 _ TConfigurationSetter = (*TSimpleJSONProtocolFactory)(nil) 1357) 1358