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

org.redkale.convert.ext.DLongSimpledCoder Maven / Gradle / Ivy

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.redkale.convert.ext;

import org.redkale.convert.Reader;
import org.redkale.convert.Writer;
import org.redkale.convert.SimpledCoder;
import org.redkale.util.*;

/**
 * Dlong 的SimpledCoder实现
 *
 * 

* 详情见: https://redkale.org * * @author zhangjx * @param Reader输入的子类型 * @param Writer输出的子类型 */ public final class DLongSimpledCoder extends SimpledCoder { private static final ByteArraySimpledCoder bsSimpledCoder = ByteArraySimpledCoder.instance; public static final DLongSimpledCoder instance = new DLongSimpledCoder(); @Override @SuppressWarnings("unchecked") public void convertTo(final W out, final DLong value) { if (value == null) { out.writeNull(); } else { bsSimpledCoder.convertTo(out, value.directBytes()); } } @Override @SuppressWarnings("unchecked") public DLong convertFrom(R in) { byte[] bs = bsSimpledCoder.convertFrom(in); if (bs == null) return null; return DLong.create(bs); } /** * DLong 的JsonSimpledCoder实现 * * @param Reader输入的子类型 * @param Writer输出的子类型 */ public static class DLongJsonSimpledCoder extends SimpledCoder { public static final DLongJsonSimpledCoder instance = new DLongJsonSimpledCoder(); @Override public void convertTo(final Writer out, final DLong value) { if (value == null) { out.writeNull(); } else { out.writeSmallString(value.toString()); } } @Override public DLong convertFrom(Reader in) { final String str = in.readSmallString(); if (str == null) return null; return DLong.create(Utility.hexToBin(str)); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy