Example usage for org.apache.thrift.protocol TTupleProtocol writeMapEnd

List of usage examples for org.apache.thrift.protocol TTupleProtocol writeMapEnd

Introduction

In this page you can find the example usage for org.apache.thrift.protocol TTupleProtocol writeMapEnd.

Prototype

public void writeMapEnd() throws TException 

Source Link

Usage

From source file:net.morimekta.providence.thrift.TTupleProtocolSerializer.java

License:Apache License

private void writeTypedValue(Object item, PDescriptor type, TTupleProtocol protocol)
        throws TException, SerializerException {
    switch (type.getType()) {
    case BOOL:/* ww w  . j  a  va2s.c  om*/
        protocol.writeBool((Boolean) item);
        break;
    case BYTE:
        protocol.writeByte((Byte) item);
        break;
    case I16:
        protocol.writeI16((Short) item);
        break;
    case I32:
        protocol.writeI32((Integer) item);
        break;
    case I64:
        protocol.writeI64((Long) item);
        break;
    case DOUBLE:
        protocol.writeDouble((Double) item);
        break;
    case STRING:
        protocol.writeString((String) item);
        break;
    case BINARY:
        protocol.writeBinary(((Binary) item).getByteBuffer());
        break;
    case ENUM:
        PEnumValue<?> value = (PEnumValue<?>) item;
        protocol.writeI32(value.getValue());
        break;
    case MESSAGE:
        writeMessage((PMessage<?, ?>) item, protocol);
        break;
    case LIST:
        PList<?> lType = (PList<?>) type;
        List<?> list = (List<?>) item;
        protocol.writeI32(list.size());
        for (Object i : list) {
            writeTypedValue(i, lType.itemDescriptor(), protocol);
        }
        break;
    case SET:
        PSet<?> sType = (PSet<?>) type;
        Set<?> set = (Set<?>) item;
        protocol.writeI32(set.size());
        for (Object i : set) {
            writeTypedValue(i, sType.itemDescriptor(), protocol);
        }
        break;
    case MAP:
        PMap<?, ?> mType = (PMap<?, ?>) type;
        Map<?, ?> map = (Map<?, ?>) item;
        protocol.writeI32(map.size());

        for (Map.Entry<?, ?> entry : map.entrySet()) {
            writeTypedValue(entry.getKey(), mType.keyDescriptor(), protocol);
            writeTypedValue(entry.getValue(), mType.itemDescriptor(), protocol);
        }

        protocol.writeMapEnd();
        break;
    default:
        break;
    }
}