protected TProtocol createThriftProtocol(TTransport transport) { switch(this.protocol) { case BINARY: return new TBinaryProtocol(transport); case JSON: return new TJSONProtocol(transport); case SIMPLE_JSON: return new TSimpleJSONProtocol(transport); default: throw new IllegalArgumentException("Unknown Thrift Protocol."); } } }
@Override public TMap readMapBegin() throws TException { readJSONArrayStart(); byte keyType = getTypeIDForTypeName(readJSONString(false).get()); byte valueType = getTypeIDForTypeName(readJSONString(false).get()); int size = (int)readJSONInteger(); readJSONObjectStart(); return new TMap(keyType, valueType, size); }
@Override public void writeMapBegin(TMap map) throws TException { writeJSONArrayStart(); writeJSONString(getTypeNameForTypeID(map.keyType)); writeJSONString(getTypeNameForTypeID(map.valueType)); writeJSONInteger(map.size); writeJSONObjectStart(); }
@Override public void readMapEnd() throws TException { readJSONObjectEnd(); readJSONArrayEnd(); }
private void readJSONObjectEnd() throws TException { readJSONSyntaxChar(RBRACE); popContext(); }
private void readJSONArrayStart() throws TException { context_.read(); readJSONSyntaxChar(LBRACKET); pushContext(new JSONListContext()); }
context_.read(); readJSONSyntaxChar(QUOTE); while (true) { byte ch = reader_.read(); trans_.readAll(tmpbuf_, 0, 4); short cu = (short)( ((short)hexVal(tmpbuf_[0]) << 12) + ((short)hexVal(tmpbuf_[1]) << 8) + ((short)hexVal(tmpbuf_[2]) << 4) + (short)hexVal(tmpbuf_[3])); try { if (Character.isHighSurrogate((char)cu)) {
@Override public void readListEnd() throws TException { readJSONArrayEnd(); }
private void resetContext() { while (!contextStack_.isEmpty()) { popContext(); } }
private void writeJSONObjectStart() throws TException { context_.write(); trans_.write(LBRACE); pushContext(new JSONPairContext()); }
private String readJSONNumericChars() throws TException { StringBuilder strbld = new StringBuilder(); while (true) { byte ch = reader_.peek(); if (!isJSONNumeric(ch)) { break; } strbld.append((char)reader_.read()); } return strbld.toString(); }
private void readJSONObjectStart() throws TException { context_.read(); readJSONSyntaxChar(LBRACE); pushContext(new JSONPairContext()); }
private void readJSONArrayEnd() throws TException { readJSONSyntaxChar(RBRACKET); popContext(); }
@Override public void readMapEnd() throws TException { readJSONObjectEnd(); readJSONArrayEnd(); }
context_.read(); readJSONSyntaxChar(QUOTE); while (true) { byte ch = reader_.read(); ch = reader_.read(); if (ch == ESCSEQ[1]) { readJSONSyntaxChar(ZERO); readJSONSyntaxChar(ZERO); trans_.readAll(tmpbuf_, 0, 2); ch = (byte)((hexVal((byte)tmpbuf_[0]) << 4) + hexVal(tmpbuf_[1]));
@Override public void readSetEnd() throws TException { readJSONArrayEnd(); }
private void writeJSONArrayEnd() throws TException { popContext(); trans_.write(RBRACKET); }
private void writeJSONArrayStart() throws TException { context_.write(); trans_.write(LBRACKET); pushContext(new JSONListContext()); }
private String readJSONNumericChars() throws TException { StringBuilder strbld = new StringBuilder(); while (true) { byte ch = reader_.peek(); if (!isJSONNumeric(ch)) { break; } strbld.append((char)reader_.read()); } return strbld.toString(); }