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

net.dongliu.prettypb.runtime.code.primitive.FloatProtoFieldInfo Maven / Gradle / Ivy

There is a newer version: 0.3.5
Show newest version
package net.dongliu.prettypb.runtime.code.primitive;

import net.dongliu.prettypb.runtime.code.ProtoBufReader;
import net.dongliu.prettypb.runtime.include.ProtoField;
import net.dongliu.prettypb.runtime.include.ProtoType;
import net.dongliu.prettypb.runtime.code.ProtoBufWriter;
import net.dongliu.prettypb.runtime.code.PrimitiveProtoFieldInfo;

import java.io.IOException;
import java.lang.reflect.Field;

/**
 * @author Dong Liu
 */
public class FloatProtoFieldInfo extends PrimitiveProtoFieldInfo {

    public FloatProtoFieldInfo(Field field, Field helperField, ProtoField protoField) {
        super(field, helperField, protoField);
    }

    @Override
    protected  void serializeFieldInternal(T bean, ProtoBufWriter protoBufWriter)
            throws IllegalAccessException, IOException {
        float value = field.getFloat(bean);
        protoBufWriter.encodeTag(ProtoType.Float, idx());
        protoBufWriter.writeFloat(value);
    }

    @Override
    protected  void deSerializeFieldInternal(T bean, ProtoBufReader protoBufReader)
            throws IOException, IllegalAccessException {
        float f = protoBufReader.readFloat();
        field.setFloat(bean, f);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy