Skip to content

Commit

Permalink
sharding/client: Adding Parse Blob(ethereum#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas committed May 16, 2018
1 parent a83b6fd commit 3e357a9
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions sharding/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -39,12 +44,17 @@ func (cb collationbody) validateBody() error {
return nil
}

func main() {
/*
add
*/

func (cb collationbody) ParseBlob() {
terminalLength := cb.length() % chunkDataSize
chunksNumber := cb.length() / chunkDataSize

x := []byte{'h', 'e', 'g', 'g'}
t := x.validateBody()
fmt.Printf("%b %s", x, t)
if terminalLength != 0 {

}
}

/*
Expand Down

0 comments on commit 3e357a9

Please sign in to comment.