From de168d053ba9dfdcc008d18078251a4d255dc124 Mon Sep 17 00:00:00 2001 From: huanghaiquan Date: Tue, 11 Jun 2019 16:07:48 +0800 Subject: [PATCH] Added new types; --- .../jd/blockchain/binaryproto/BaseType.java | 43 ++++++++++++++++ .../jd/blockchain/binaryproto/DataType.java | 24 --------- .../blockchain/binaryproto/PrimitiveType.java | 50 +++++++++++++------ .../ByteArrayObjectJsonSerializer.java | 10 ++-- 4 files changed, 83 insertions(+), 44 deletions(-) create mode 100644 source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/BaseType.java delete mode 100644 source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/DataType.java diff --git a/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/BaseType.java b/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/BaseType.java new file mode 100644 index 00000000..c294174d --- /dev/null +++ b/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/BaseType.java @@ -0,0 +1,43 @@ +package com.jd.blockchain.binaryproto; + +/** + * 基础类型; + * + * @author huanghaiquan + * + */ +public interface BaseType { + + /** + * 空值; + */ + public static final byte NIL = (byte) 0x00; + + /** + * 布尔; + */ + public static final byte BOOLEAN = (byte) 0x01; + + /** + * 数值; + */ + public static final byte NUMERIC = (byte) 0x10; + + /** + * 文本 + */ + public static final byte TEXT = (byte) 0x20; + + /** + * 字节序列; + */ + public static final byte BYTES = (byte) 0x40; + + /** + * 扩展类型;
+ * + * 最高位为1,用作保留字段; + */ + public static final byte EXT = (byte) 0x80; + +} diff --git a/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/DataType.java b/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/DataType.java deleted file mode 100644 index 9df9f7bd..00000000 --- a/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/DataType.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.jd.blockchain.binaryproto; - -public interface DataType { - - /** - * 空值; - */ - public static final byte NIL = (byte) 0x00; - - /** - * 布尔; - */ - public static final byte BOOLEAN = (byte) 0x01; - - /** - * 数值; - */ - public static final byte NUMERIC = (byte) 0x10; - - public static final byte TEXT = (byte) 0x20; - - public static final byte BINARY = (byte) 0x40; - -} diff --git a/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/PrimitiveType.java b/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/PrimitiveType.java index c183d8df..a70ff94b 100644 --- a/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/PrimitiveType.java +++ b/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/PrimitiveType.java @@ -11,68 +11,88 @@ public enum PrimitiveType { /** * 空; */ - NIL(DataType.NIL), + NIL(BaseType.NIL), /** * 布尔型; */ - BOOLEAN(DataType.BOOLEAN), + BOOLEAN(BaseType.BOOLEAN), /** * 数值型: */ - INT8((byte) (DataType.NUMERIC | 0x01)), + INT8((byte) (BaseType.NUMERIC | 0x01)), - INT16((byte) (DataType.NUMERIC | 0x02)), + INT16((byte) (BaseType.NUMERIC | 0x02)), - INT32((byte) (DataType.NUMERIC | 0x03)), + INT32((byte) (BaseType.NUMERIC | 0x03)), - INT64((byte) (DataType.NUMERIC | 0x04)), + INT64((byte) (BaseType.NUMERIC | 0x04)), /** * 时间戳; */ - TIMESTAMP((byte) (DataType.NUMERIC | 0x08)), + TIMESTAMP((byte) (BaseType.NUMERIC | 0x08)), /** * 文本数据; */ - TEXT(DataType.TEXT), + TEXT(BaseType.TEXT), /** * 文本数据; */ - JSON((byte) (DataType.TEXT | 0x01)), + JSON((byte) (BaseType.TEXT | 0x01)), /** * 文本数据; */ - XML((byte) (DataType.TEXT | 0x02)), + XML((byte) (BaseType.TEXT | 0x02)), /** * 二进制数据; */ - BYTES(DataType.BINARY), + BYTES(BaseType.BYTES), /** * 大整数; */ - BIG_INT((byte) (DataType.BINARY | 0x01)), + BIG_INT((byte) (BaseType.BYTES | 0x01)), /** * 图片; */ - IMG((byte) (DataType.BINARY | 0x02)), + IMG((byte) (BaseType.BYTES | 0x02)), /** * 视频; */ - VIDEO((byte) (DataType.BINARY | 0x03)), + VIDEO((byte) (BaseType.BYTES | 0x03)), /** * 位置坐标; */ - LOCATION((byte) (DataType.BINARY | 0x04)); + LOCATION((byte) (BaseType.BYTES | 0x04)), + + /** + * 公钥; + */ + PUB_KEY((byte) (BaseType.BYTES | 0x05)), + + /** + * 签名摘要; + */ + SIGNATURE_DIGEST((byte) (BaseType.BYTES | 0x06)), + + /** + * 哈希摘要; + */ + HASH_DIGEST((byte) (BaseType.BYTES | 0x07)), + + /** + * 加密数据; + */ + ENCRYPTED_DATA((byte) (BaseType.BYTES | 0x08)); public final byte CODE; diff --git a/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectJsonSerializer.java b/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectJsonSerializer.java index 896e1f4a..e4a82b13 100644 --- a/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectJsonSerializer.java +++ b/source/ledger/ledger-rpc/src/main/java/com/jd/blockchain/web/serializes/ByteArrayObjectJsonSerializer.java @@ -2,7 +2,7 @@ package com.jd.blockchain.web.serializes; import com.alibaba.fastjson.serializer.JSONSerializer; import com.alibaba.fastjson.serializer.ObjectSerializer; -import com.jd.blockchain.binaryproto.DataType; +import com.jd.blockchain.binaryproto.BaseType; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.SignatureDigest; @@ -92,20 +92,20 @@ public class ByteArrayObjectJsonSerializer implements ObjectSerializer { public static class BytesValueJson { - public BytesValueJson(DataType type, Object value) { + public BytesValueJson(BaseType type, Object value) { this.type = type; this.value = value; } - DataType type; + BaseType type; Object value; - public DataType getType() { + public BaseType getType() { return type; } - public void setType(DataType type) { + public void setType(BaseType type) { this.type = type; }