field_type.cpp 1.47 KB
Newer Older
gejun's avatar
gejun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
// mcpack2pb - Make protobuf be front-end of mcpack/compack
// Copyright (c) 2015 Baidu.com, Inc. All Rights Reserved

// Author: The baidu-rpc authors (pbrpc@baidu.com)
// Date: Mon Oct 19 17:17:36 CST 2015

#include "mcpack2pb/field_type.h"

namespace mcpack2pb {

const char* type2str(FieldType type) {
    bool is_short = false;
    if (type & FIELD_SHORT_MASK) {
        is_short = true;
        type = (FieldType)(type & ~FIELD_SHORT_MASK);
    }
    switch (type) {
    case FIELD_OBJECT:         return "object";
    case FIELD_ARRAY:          return "array";
    case FIELD_ISOARRAY:       return "isoarray";
    case FIELD_OBJECTISOARRAY: return "object_isoarray";
    case FIELD_STRING:         return (is_short ? "string(short)" : "string");
    case FIELD_BINARY:         return (is_short ? "binary(short)" : "binary");
    case FIELD_INT8:          return "int8";
    case FIELD_INT16:         return "int16";
    case FIELD_INT32:         return "int32";
    case FIELD_INT64:         return "int64";
    case FIELD_UINT8:         return "uint8";
    case FIELD_UINT16:        return "uint16";
    case FIELD_UINT32:        return "uint32";
    case FIELD_UINT64:        return "uint64";
    case FIELD_BOOL:           return "bool";
    case FIELD_FLOAT:          return "float";
    case FIELD_DOUBLE:         return "double";
    case FIELD_DATE:           return "date";
    case FIELD_NULL:           return "null";
    }
    return "unknown_field_type";
}

} // namespace mcpack2pb