From 3b13a44f3a5a1509bb829a0f84433385595f4ab4 Mon Sep 17 00:00:00 2001 From: nisdas Date: Sun, 22 Apr 2018 23:09:22 +0800 Subject: [PATCH] sharding/client: Adding Parse Blob(#92) Former-commit-id: 2ae72f191f84b88ab28a0752130b591c01b7a2fd [formerly c9a496eb646c098a1b46b9880d8059a094b93574] Former-commit-id: a1ef1e7d5f2d880c6678ca725ecd4837349a21f6 --- sharding/client/utils.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/sharding/client/utils.go b/sharding/client/utils.go index cecff0b95..29f12c187 100644 --- a/sharding/client/utils.go +++ b/sharding/client/utils.go @@ -10,27 +10,32 @@ var ( collationsizelimit = int64(2 ^ 20) chunkSize = int64(32) indicatorSize = int64(1) + numberOfChunks = collationsizelimit / chunkSize chunkDataSize = chunkSize - indicatorSize + totalDatasize = numberOfChunks * chunkDataSize ) +func (cb collationbody) length() int64 { + + return int64(len(cb)) +} + /* Validate that the collation body is within its bounds and if the size of the body is below the limit it is simply appended till it reaches the required limit */ func (cb collationbody) validateBody() error { - length := int64(len(cb)) - - if length == 0 { + if cb.length() == 0 { return fmt.Errorf("Collation Body has to be a non-zero value") } - if length > collationsizelimit { + if cb.length() > totalDatasize { return fmt.Errorf("Collation Body is over the size limit") } - if length < collationsizelimit { - x := make([]byte, (collationsizelimit - length)) + if cb.length() < totalDatasize { + x := make([]byte, (totalDatasize - cb.length())) cb = append(cb, x...) fmt.Printf("%b", x) @@ -39,12 +44,17 @@ func (cb collationbody) validateBody() error { return nil } -func main() { +/* + add +*/ - x := []byte{'h', 'e', 'g', 'g'} - t := x.validateBody() - fmt.Printf("%b %s", x, t) +func (cb collationbody) ParseBlob() { + terminalLength := cb.length() % chunkDataSize + chunksNumber := cb.length() / chunkDataSize + if terminalLength != 0 { + + } } /*