public TProtocol getProtocol(TTransport trans) { return new TJSONProtocol(trans); }
@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(); }
@Override public TMessage readMessageBegin() throws TException { readJSONArrayStart(); if (readJSONInteger() != VERSION) { throw new TProtocolException(TProtocolException.BAD_VERSION, "Message contained bad version."); } String name; try { name = readJSONString(false).toString("UTF-8"); } catch (UnsupportedEncodingException ex) { throw new TException("JVM DOES NOT SUPPORT UTF-8"); } byte type = (byte) readJSONInteger(); int seqid = (int) readJSONInteger(); return new TMessage(name, type, seqid); }
private void readJSONArrayStart() throws TException { context_.read(); readJSONSyntaxChar(LBRACKET); pushContext(new JSONListContext()); }
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 writeJSONObjectStart() throws TException { context_.write(); trans_.write(LBRACE); pushContext(new JSONPairContext()); }
private void writeJSONArrayEnd() throws TException { popContext(); trans_.write(RBRACKET); }
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(); }
@Override public TMessage readMessageBegin() throws TException { readJSONArrayStart(); if (readJSONInteger() != VERSION) { throw new TProtocolException(TProtocolException.BAD_VERSION, "Message contained bad version."); } String name; try { name = readJSONString(false).toString("UTF-8"); } catch (UnsupportedEncodingException ex) { throw new TException("JVM DOES NOT SUPPORT UTF-8"); } byte type = (byte) readJSONInteger(); int seqid = (int) readJSONInteger(); return new TMessage(name, type, seqid); }
private void readJSONObjectStart() throws TException { context_.read(); readJSONSyntaxChar(LBRACE); pushContext(new JSONPairContext()); }
private void readJSONObjectEnd() throws TException { readJSONSyntaxChar(RBRACE); 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 writeJSONArrayStart() throws TException { context_.write(); trans_.write(LBRACKET); pushContext(new JSONListContext()); }