Skip to content

Commit

Permalink
crunch: format & make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
superwhiskers committed Apr 30, 2020
1 parent 301ddbf commit 659ca9d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 123 deletions.
2 changes: 1 addition & 1 deletion examples/signed-integers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
// | the size of a 32-bit signed integer (in bytes)
// |
// | | two integers
// | |
// | |
// v v
buf.Grow(4 * 2)

Expand Down
16 changes: 8 additions & 8 deletions generation/complex.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func GenerateComplex(oldFiles map[string][]byte) (files map[string][]byte, e err

body.BlockFunc(func(loop *jen.Group) {
loop.Id("read_loop:")

if arguments[2] == "F" {
// this is necessary for precedence
v := loop.Id("u").Op("=")
Expand Down Expand Up @@ -315,22 +315,22 @@ func GenerateComplex(oldFiles map[string][]byte) (files map[string][]byte, e err
loop.Id("b").Dot("buf").Index(jen.Id("off").Op("+").Id("int64").
Call(jen.Id("i").Op("*").Lit(intBytes))).Op("=").Id("byte").
Call(jen.Op("*").Parens(jen.Op("*").Id(strings.Join([]string{"uint", arguments[3]}, ""))).Parens(jen.Id("unsafe").Dot("Pointer").
Call(jen.Op("&").Id("data").Index(jen.Id("i")))).Op(">>").Lit((intBytes - 1) * 8))
Call(jen.Op("&").Id("data").Index(jen.Id("i")))).Op(">>").Lit((intBytes - 1) * 8))
for i := intBytes - 1; i > 1; i-- {
loop.Id("b").Dot("buf").Index(jen.Id("off").Op("+").Id("int64").
Call(jen.Lit(intBytes - i).Op("+").Parens(jen.Id("i").Op("*").Lit(intBytes)))).Op("=").Id("byte").
Call(jen.Op("*").Parens(jen.Op("*").Id(strings.Join([]string{"uint", arguments[3]}, ""))).Parens(jen.Id("unsafe").Dot("Pointer").
Call(jen.Op("&").Id("data").Index(jen.Id("i")))).Op(">>").Lit((i - 1) * 8))
Call(jen.Op("&").Id("data").Index(jen.Id("i")))).Op(">>").Lit((i - 1) * 8))
}
loop.Id("b").Dot("buf").Index(jen.Id("off").Op("+").Id("int64").
Call(jen.Lit(intBytes - 1).Op("+").Parens(jen.Id("i").Op("*").Lit(intBytes)))).Op("=").Id("byte").
Call(jen.Op("*").Parens(jen.Op("*").Id(strings.Join([]string{"uint", arguments[3]}, ""))).Parens(jen.Id("unsafe").Dot("Pointer").
Call(jen.Op("&").Id("data").Index(jen.Id("i")))))
/*
Call(jen.Op("&").Id("data").Index(jen.Id("i")))))
/*
looking into reworking it to be like this:
*(*uintBITS)(unsafe.Pointer(b.obuf + (i * 8))) = (or chain)
*/
*/
}
} else {
if arguments[2] == "U" || arguments[2] == "I" {
Expand All @@ -346,12 +346,12 @@ func GenerateComplex(oldFiles map[string][]byte) (files map[string][]byte, e err
loop.Id("b").Dot("buf").Index(jen.Id("off").Op("+").Id("int64").
Call(jen.Id("i").Op("*").Lit(intBytes))).Op("=").Id("byte").
Call(jen.Op("*").Parens(jen.Op("*").Id(strings.Join([]string{"uint", arguments[3]}, ""))).Parens(jen.Id("unsafe").Dot("Pointer").
Call(jen.Op("&").Id("data").Index(jen.Id("i")))))
Call(jen.Op("&").Id("data").Index(jen.Id("i")))))
for i := 1; i < intBytes; i++ {
loop.Id("b").Dot("buf").Index(jen.Id("off").Op("+").Id("int64").
Call(jen.Lit(i).Op("+").Parens(jen.Id("i").Op("*").Lit(intBytes)))).Op("=").Id("byte").
Call(jen.Op("*").Parens(jen.Op("*").Id(strings.Join([]string{"uint", arguments[3]}, ""))).Parens(jen.Id("unsafe").Dot("Pointer").
Call(jen.Op("&").Id("data").Index(jen.Id("i")))).Op(">>").Lit(i * 8))
Call(jen.Op("&").Id("data").Index(jen.Id("i")))).Op(">>").Lit(i * 8))
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions v3/_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ func (b *Buffer) WriteByteNext(data byte) {

//generator:complex Buffer Write U 64 BE


//generator:complex Buffer Write I 16 LE

//generator:complex Buffer Write I 16 BE
Expand All @@ -458,7 +457,6 @@ func (b *Buffer) WriteByteNext(data byte) {

//generator:complex Buffer Write I 64 BE


//generator:complex Buffer Write F 32 LE

//generator:complex Buffer Write F 32 BE
Expand Down Expand Up @@ -527,7 +525,6 @@ func (b *Buffer) ReadByteNext() (out byte) {

//generator:complex Buffer Read U 64 BE


//generator:complex Buffer Read I 16 LE

//generator:complex Buffer Read I 16 BE
Expand All @@ -540,7 +537,6 @@ func (b *Buffer) ReadByteNext() (out byte) {

//generator:complex Buffer Read I 64 BE


//generator:complex Buffer Read F 32 LE

//generator:complex Buffer Read F 32 BE
Expand Down
4 changes: 0 additions & 4 deletions v3/_minibuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ func (b *MiniBuffer) WriteBytesNext(data []byte) {

//generator:complex MiniBuffer Write U 64 BE


//generator:complex MiniBuffer Write I 16 LE

//generator:complex MiniBuffer Write I 16 BE
Expand All @@ -380,7 +379,6 @@ func (b *MiniBuffer) WriteBytesNext(data []byte) {

//generator:complex MiniBuffer Write I 64 BE


//generator:complex MiniBuffer Write F 32 LE

//generator:complex MiniBuffer Write F 32 BE
Expand Down Expand Up @@ -418,7 +416,6 @@ func (b *MiniBuffer) ReadBytesNext(out *[]byte, n int64) {

//generator:complex MiniBuffer Read U 64 BE


//generator:complex MiniBuffer Read I 16 LE

//generator:complex MiniBuffer Read I 16 BE
Expand All @@ -431,7 +428,6 @@ func (b *MiniBuffer) ReadBytesNext(out *[]byte, n int64) {

//generator:complex MiniBuffer Read I 64 BE


//generator:complex MiniBuffer Read F 32 LE

//generator:complex MiniBuffer Read F 32 BE
Expand Down
2 changes: 0 additions & 2 deletions v3/buffer.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ func (b *Buffer) WriteU64BENext(data []uint64) {
b.SeekByte(int64(len(data))*8, true)
}


// WriteI16LE writes a slice of int16s to the buffer at the
// specified offset in little-endian without modifying the internal
// offset value
Expand Down Expand Up @@ -1220,7 +1219,6 @@ func (b *Buffer) ReadU64BENext(n int64) (out []uint64) {
return
}


// ReadI16LE reads a slice of int16s from the buffer at the
// specified offset in little-endian without modifying the internal
// offset value
Expand Down
102 changes: 51 additions & 51 deletions v3/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,19 +479,19 @@ func TestBufferReadBytesNext(t *testing.T) {
func TestBufferReadSNEN(t *testing.T) {

var (
expected_readu16le = []uint16{0x01, 0x00}
expected_readu16be = []uint16{0x100, 0x00}
expected_readu32le = []uint32{0x01, 0x00}
expected_readu32be = []uint32{0x1000000, 0x00}
expected_readu64le = []uint64{0x01, 0x01}
expected_readu64be = []uint64{0x100000000000000, 0x100000000000000}

expected_readi16le = []int16{0x01, 0x00}
expected_readi16be = []int16{0x100, 0x00}
expected_readi32le = []int32{0x01, 0x00}
expected_readi32be = []int32{0x1000000, 0x00}
expected_readi64le = []int64{0x01, 0x01}
expected_readi64be = []int64{0x100000000000000, 0x100000000000000}
expectedReadu16le = []uint16{0x01, 0x00}
expectedReadu16be = []uint16{0x100, 0x00}
expectedReadu32le = []uint32{0x01, 0x00}
expectedReadu32be = []uint32{0x1000000, 0x00}
expectedReadu64le = []uint64{0x01, 0x01}
expectedReadu64be = []uint64{0x100000000000000, 0x100000000000000}

expectedReadi16le = []int16{0x01, 0x00}
expectedReadi16be = []int16{0x100, 0x00}
expectedReadi32le = []int32{0x01, 0x00}
expectedReadi32be = []int32{0x1000000, 0x00}
expectedReadi64le = []int64{0x01, 0x01}
expectedReadi64be = []int64{0x100000000000000, 0x100000000000000}
)

buf := NewBuffer([]byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
Expand All @@ -501,9 +501,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out1 := buf.ReadU16LENext(2)
if !cmp.Equal(out1, expected_readu16le) {
if !cmp.Equal(out1, expectedReadu16le) {

t.Fatalf("expected uint16 array does not match the one gotten (got %#v, expected %#v)", out1, expected_readu16le)
t.Fatalf("expected uint16 array does not match the one gotten (got %#v, expected %#v)", out1, expectedReadu16le)

}

Expand All @@ -520,9 +520,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out1 = buf.ReadU16BENext(2)
if !cmp.Equal(out1, expected_readu16be) {
if !cmp.Equal(out1, expectedReadu16be) {

t.Fatalf("expected uint16 array does not match the one gotten (got %#v, expected %#v)", out1, expected_readu16be)
t.Fatalf("expected uint16 array does not match the one gotten (got %#v, expected %#v)", out1, expectedReadu16be)

}

Expand All @@ -539,9 +539,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out2 := buf.ReadU32LENext(2)
if !cmp.Equal(out2, expected_readu32le) {
if !cmp.Equal(out2, expectedReadu32le) {

t.Fatalf("expected uint32 array does not match the one gotten (got %#v, expected %#v)", out2, expected_readu32le)
t.Fatalf("expected uint32 array does not match the one gotten (got %#v, expected %#v)", out2, expectedReadu32le)

}

Expand All @@ -558,9 +558,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out2 = buf.ReadU32BENext(2)
if !cmp.Equal(out2, expected_readu32be) {
if !cmp.Equal(out2, expectedReadu32be) {

t.Fatalf("expected uint32 array does not match the one gotten (got %#v, expected %#v)", out2, expected_readu32be)
t.Fatalf("expected uint32 array does not match the one gotten (got %#v, expected %#v)", out2, expectedReadu32be)

}

Expand All @@ -577,9 +577,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out3 := buf.ReadU64LENext(2)
if !cmp.Equal(out3, expected_readu64le) {
if !cmp.Equal(out3, expectedReadu64le) {

t.Fatalf("expected uint64 array does not match the one gotten (got %#v, expected %#v)", out3, expected_readu64le)
t.Fatalf("expected uint64 array does not match the one gotten (got %#v, expected %#v)", out3, expectedReadu64le)

}

Expand All @@ -596,9 +596,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out3 = buf.ReadU64BENext(2)
if !cmp.Equal(out3, expected_readu64be) {
if !cmp.Equal(out3, expectedReadu64be) {

t.Fatalf("expected uint64 array does not match the one gotten (got %#v, expected %#v)", out3, expected_readu64be)
t.Fatalf("expected uint64 array does not match the one gotten (got %#v, expected %#v)", out3, expectedReadu64be)

}

Expand All @@ -615,9 +615,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out4 := buf.ReadI16LENext(2)
if !cmp.Equal(out4, expected_readi16le) {
if !cmp.Equal(out4, expectedReadi16le) {

t.Fatalf("expected int16 array does not match the one gotten (got %#v, expected %#v)", out4, expected_readi16le)
t.Fatalf("expected int16 array does not match the one gotten (got %#v, expected %#v)", out4, expectedReadi16le)

}
off = buf.ByteOffset()
Expand All @@ -633,9 +633,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out4 = buf.ReadI16BENext(2)
if !cmp.Equal(out4, expected_readi16be) {
if !cmp.Equal(out4, expectedReadi16be) {

t.Fatalf("expected int16 array does not match the one gotten (got %#v, expected %#v)", out4, expected_readi16be)
t.Fatalf("expected int16 array does not match the one gotten (got %#v, expected %#v)", out4, expectedReadi16be)

}
off = buf.ByteOffset()
Expand All @@ -651,9 +651,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out5 := buf.ReadI32LENext(2)
if !cmp.Equal(out5, expected_readi32le) {
if !cmp.Equal(out5, expectedReadi32le) {

t.Fatalf("expected int32 array does not match the one gotten (got %#v, expected %#v)", out5, expected_readi32le)
t.Fatalf("expected int32 array does not match the one gotten (got %#v, expected %#v)", out5, expectedReadi32le)

}
off = buf.ByteOffset()
Expand All @@ -669,9 +669,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out5 = buf.ReadI32BENext(2)
if !cmp.Equal(out5, expected_readi32be) {
if !cmp.Equal(out5, expectedReadi32be) {

t.Fatalf("expected int32 array does not match the one gotten (got %#v, expected %#v)", out5, expected_readi32be)
t.Fatalf("expected int32 array does not match the one gotten (got %#v, expected %#v)", out5, expectedReadi32be)

}
off = buf.ByteOffset()
Expand All @@ -687,9 +687,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out6 := buf.ReadI64LENext(2)
if !cmp.Equal(out6, expected_readi64le) {
if !cmp.Equal(out6, expectedReadi64le) {

t.Fatalf("expected int64 array does not match the one gotten (got %#v, expected %#v)", out6, expected_readi64le)
t.Fatalf("expected int64 array does not match the one gotten (got %#v, expected %#v)", out6, expectedReadi64le)

}
off = buf.ByteOffset()
Expand All @@ -705,9 +705,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out6 = buf.ReadI64BENext(2)
if !cmp.Equal(out6, expected_readi64be) {
if !cmp.Equal(out6, expectedReadi64be) {

t.Fatalf("expected int64 array does not match the one gotten (got %#v, expected %#v)", out6, expected_readi64be)
t.Fatalf("expected int64 array does not match the one gotten (got %#v, expected %#v)", out6, expectedReadi64be)

}
off = buf.ByteOffset()
Expand All @@ -723,10 +723,10 @@ func TestBufferReadSNEN(t *testing.T) {
//

var (
expected_readf32le = []float32{-45.318115, -8.536945e+32}
expected_readf32be = []float32{-3.081406, -1.0854726e-29}
expected_readf64le = []float64{-1.498274907009045e+261, 5.278146837874356e-99}
expected_readf64be = []float64{-42.42, 3.621}
expectedReadf32le = []float32{-45.318115, -8.536945e+32}
expectedReadf32be = []float32{-3.081406, -1.0854726e-29}
expectedReadf64le = []float64{-1.498274907009045e+261, 5.278146837874356e-99}
expectedReadf64be = []float64{-42.42, 3.621}
)

buf = NewBuffer([]byte{0xc0, 0x45, 0x35, 0xc2, 0x8f, 0x5c, 0x28, 0xf6, 0x40, 0xc, 0xf7, 0xce, 0xd9, 0x16, 0x87, 0x2b})
Expand All @@ -736,9 +736,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out7 := buf.ReadF32LENext(2)
if !cmp.Equal(out7, expected_readf32le) {
if !cmp.Equal(out7, expectedReadf32le) {

t.Fatalf("expected float32 array does not match the one gotten (got %#v, expected %#v)", out7, expected_readf32le)
t.Fatalf("expected float32 array does not match the one gotten (got %#v, expected %#v)", out7, expectedReadf32le)

}
off = buf.ByteOffset()
Expand All @@ -754,14 +754,14 @@ func TestBufferReadSNEN(t *testing.T) {
//

out7 = buf.ReadF32BENext(2)
if !cmp.Equal(out7, expected_readf32be) {
if !cmp.Equal(out7, expectedReadf32be) {

t.Fatalf("expected float32 array does not match the one gotten (got %#v, expected %#v)", out7, expected_readf32be)
t.Fatalf("expected float32 array does not match the one gotten (got %#v, expected %#v)", out7, expectedReadf32be)

}
off = buf.ByteOffset()
if off != 8 {

t.Fatalf("incorrect offset: %d", off)

}
Expand All @@ -772,9 +772,9 @@ func TestBufferReadSNEN(t *testing.T) {
//

out8 := buf.ReadF64LENext(2)
if !cmp.Equal(out8, expected_readf64le) {
if !cmp.Equal(out8, expectedReadf64le) {

t.Fatalf("expected float64 array does not match the one gotten (got %#v, expected %#v)", out8, expected_readf64le)
t.Fatalf("expected float64 array does not match the one gotten (got %#v, expected %#v)", out8, expectedReadf64le)

}
off = buf.ByteOffset()
Expand All @@ -784,15 +784,15 @@ func TestBufferReadSNEN(t *testing.T) {

}
buf.SeekByte(0x00, false)

//
// f64be
//

out8 = buf.ReadF64BENext(2)
if !cmp.Equal(out8, expected_readf64be) {
if !cmp.Equal(out8, expectedReadf64be) {

t.Fatalf("expected float64 array does not match the one gotten (got %#v, expected %#v)", out8, expected_readf64be)
t.Fatalf("expected float64 array does not match the one gotten (got %#v, expected %#v)", out8, expectedReadf64be)

}
off = buf.ByteOffset()
Expand Down
Loading

0 comments on commit 659ca9d

Please sign in to comment.