All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hprose.io.unserialize.EnumUnserializer Maven / Gradle / Ivy

/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/
/**********************************************************\
 *                                                        *
 * EnumUnserializer.java                                  *
 *                                                        *
 * Enum unserializer class for Java.                      *
 *                                                        *
 * LastModified: Aug 3, 2016                              *
 * Author: Ma Bingyao                   *
 *                                                        *
\**********************************************************/

package hprose.io.unserialize;

import hprose.util.ClassUtil;
import java.io.IOException;
import java.lang.reflect.Type;

public final class EnumUnserializer implements Unserializer {

    public final static EnumUnserializer instance = new EnumUnserializer();

    public Object read(Reader reader, int tag, Type type) throws IOException {
        int index = IntUnserializer.instance.read(reader, tag, int.class);
        return ClassUtil.toClass(type).getEnumConstants()[index];
    }

    public Object read(Reader reader, Type type) throws IOException {
        return read(reader, reader.stream.read(), type);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy