From e88c1343d402f4928b155e8f297f9a9d2283c788 Mon Sep 17 00:00:00 2001 From: nisdas Date: Wed, 2 May 2018 13:00:37 +0800 Subject: [PATCH] sharding/client: Adding deserialize blobs(#92) Former-commit-id: f11427ff5b305c1f9ebb30b2436e75b5ff9a9dc9 [formerly 3def7d93a525e3bb8348de8fb24ad9d828580860] Former-commit-id: 6dc530e57dc5a35ee50564ecc082d035f6ceead1 --- sharding/client/utils.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/sharding/client/utils.go b/sharding/client/utils.go index 0950dbdb4..30c284570 100644 --- a/sharding/client/utils.go +++ b/sharding/client/utils.go @@ -3,6 +3,7 @@ package client import ( "fmt" "math" + "reflect" ) var ( @@ -18,8 +19,8 @@ type collationbody []byte type body interface { length() int64 - validateblob() error - ParseBlob() + validateBody() error + serializeBlob() []byte } func (cb collationbody) length() int64 { @@ -44,6 +45,24 @@ func (cb collationbody) validateBody() error { return nil } +func deserializeBlob(blob body) []byte { + deserializedblob := blob.(collationbody) + length := deserializedblob.length() + chunksNumber := chunkSize / length + indicatorByte := make([]byte, 1) + indicatorByte[0] = 0 + tempbody := []byte{0} + + for i := int64(1); i <= chunksNumber; i++ { + + if reflect.TypeOf(deserializedblob[:(i-1)*chunksNumber]) == reflect.TypeOf(indicatorByte) { + + } + + } + +} + // Parse Collation body and modify it accordingly func (cb collationbody) serializeBlob() []byte { @@ -52,7 +71,7 @@ func (cb collationbody) serializeBlob() []byte { chunksNumber := cb.length() / chunkDataSize indicatorByte := make([]byte, 1) indicatorByte[0] = 0 - var tempbody []byte + tempbody := []byte{} // if blob is less than 31 bytes, it adds the indicator chunk and pads the remaining empty bytes to the right