public TProtocol getProtocol(TTransport trans) { return new TJSONProtocol(trans, fieldNamesAsString_); }
@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(); }
@Override public void writeFieldBegin(TField field) throws TException { if (fieldNamesAsString_) { writeString(field.name); } else { writeJSONInteger(field.id); } writeJSONObjectStart(); writeJSONString(getTypeNameForTypeID(field.type)); }
@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(); }
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 readMessageEnd() throws TException { readJSONArrayEnd(); }
private void writeJSONArrayStart() throws TException { context_.write(); trans_.write(LBRACKET); pushContext(new JSONListContext()); }
private void writeJSONObjectEnd() throws TException { popContext(); trans_.write(RBRACE); }
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 void writeFieldBegin(TField field) throws TException { if (fieldNamesAsString_) { writeString(field.name); } else { writeJSONInteger(field.id); } writeJSONObjectStart(); writeJSONString(getTypeNameForTypeID(field.type)); }
@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()); }
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]));