This commit is contained in:
@@ -36,7 +36,7 @@ public final class DLongSimpledCoder<R extends Reader, W extends Writer> extends
|
|||||||
public DLong convertFrom(R in) {
|
public DLong convertFrom(R in) {
|
||||||
byte[] bs = bsSimpledCoder.convertFrom(in);
|
byte[] bs = bsSimpledCoder.convertFrom(in);
|
||||||
if (bs == null) return null;
|
if (bs == null) return null;
|
||||||
return new DLong(bs);
|
return DLong.create(bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ public class DLongJsonSimpledCoder extends JsonSimpledCoder<DLong> {
|
|||||||
public DLong convertFrom(JsonReader in) {
|
public DLong convertFrom(JsonReader in) {
|
||||||
final String str = in.readString();
|
final String str = in.readString();
|
||||||
if (str == null) return null;
|
if (str == null) return null;
|
||||||
return new DLong(Utility.hexToBin(str));
|
return DLong.create(Utility.hexToBin(str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,17 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public final class DLong extends Number implements Comparable<DLong> {
|
public final class DLong extends Number implements Comparable<DLong> {
|
||||||
|
|
||||||
private final byte[] bytes;
|
public static final DLong ZERO = new DLong(new byte[16]);
|
||||||
|
|
||||||
public DLong(long v1, long v2) {
|
protected final byte[] bytes;
|
||||||
|
|
||||||
|
protected DLong(long v1, long v2) { //暂时不用
|
||||||
this.bytes = new byte[]{(byte) (v1 >> 56), (byte) (v1 >> 48), (byte) (v1 >> 40), (byte) (v1 >> 32),
|
this.bytes = new byte[]{(byte) (v1 >> 56), (byte) (v1 >> 48), (byte) (v1 >> 40), (byte) (v1 >> 32),
|
||||||
(byte) (v1 >> 24), (byte) (v1 >> 16), (byte) (v1 >> 8), (byte) v1, (byte) (v2 >> 56), (byte) (v2 >> 48), (byte) (v2 >> 40), (byte) (v2 >> 32),
|
(byte) (v1 >> 24), (byte) (v1 >> 16), (byte) (v1 >> 8), (byte) v1, (byte) (v2 >> 56), (byte) (v2 >> 48), (byte) (v2 >> 40), (byte) (v2 >> 32),
|
||||||
(byte) (v2 >> 24), (byte) (v2 >> 16), (byte) (v2 >> 8), (byte) v2};
|
(byte) (v2 >> 24), (byte) (v2 >> 16), (byte) (v2 >> 8), (byte) v2};
|
||||||
}
|
}
|
||||||
|
|
||||||
public DLong(byte[] bytes) {
|
protected DLong(byte[] bytes) {
|
||||||
if (bytes == null || bytes.length != 16) throw new NumberFormatException("Not 16 length bytes");
|
if (bytes == null || bytes.length != 16) throw new NumberFormatException("Not 16 length bytes");
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
}
|
}
|
||||||
@@ -38,8 +40,20 @@ public final class DLong extends Number implements Comparable<DLong> {
|
|||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer putTo(ByteBuffer buffer) {
|
public static DLong create(byte[] bytes) {
|
||||||
buffer.put(bytes);
|
if (ZERO.equals(bytes)) return ZERO;
|
||||||
|
return new DLong(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DLong read(ByteBuffer buffer) {
|
||||||
|
byte[] bs = new byte[16];
|
||||||
|
buffer.get(bs);
|
||||||
|
if (ZERO.equals(bs)) return ZERO;
|
||||||
|
return new DLong(bs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ByteBuffer write(ByteBuffer buffer, DLong value) {
|
||||||
|
buffer.put(value.bytes);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +76,7 @@ public final class DLong extends Number implements Comparable<DLong> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
if (this == ZERO) return "0";
|
||||||
return new String(Utility.binToHex(bytes));
|
return new String(Utility.binToHex(bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user