hprose.io.access.LongFieldAccessor Maven / Gradle / Ivy
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/
/**********************************************************\
* *
* LongFieldAccessor.java *
* *
* LongFieldAccessor class for Java. *
* *
* LastModified: Aug 3, 2016 *
* Author: Ma Bingyao *
* *
\**********************************************************/
package hprose.io.access;
import hprose.common.HproseException;
import hprose.io.serialize.ValueWriter;
import hprose.io.serialize.Writer;
import hprose.io.unserialize.LongUnserializer;
import hprose.io.unserialize.Reader;
import java.io.IOException;
import java.lang.reflect.Field;
public final class LongFieldAccessor implements MemberAccessor {
private final long offset;
public LongFieldAccessor(Field accessor) {
accessor.setAccessible(true);
offset = Accessors.unsafe.objectFieldOffset(accessor);
}
@Override
public void serialize(Writer writer, Object obj) throws IOException {
long value;
try {
value = Accessors.unsafe.getLong(obj, offset);
}
catch (Exception e) {
throw new HproseException(e.getMessage());
}
ValueWriter.write(writer.stream, value);
}
@Override
public void unserialize(Reader reader, Object obj) throws IOException {
long value = LongUnserializer.instance.read(reader);
try {
Accessors.unsafe.putLong(obj, offset, value);
}
catch (Exception e) {
throw new HproseException(e.getMessage());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy