Skip to content

Instantly share code, notes, and snippets.

@napsy
Created April 3, 2011 08:25
Show Gist options
  • Save napsy/900287 to your computer and use it in GitHub Desktop.
Save napsy/900287 to your computer and use it in GitHub Desktop.
package main
import (
"io/ioutil"
"unsafe"
)
type Data struct {
Head [4]byte
Flags byte
Meta [2]byte
}
func main() {
var data Data = Data{[4]byte{1, 2, 3, 4}, 5, [2]byte{6, 7}}
obj := (*[7]byte)(unsafe.Pointer(&data))
s := make([]byte, 10)
s[0] = 1
s[1] = 2
s[2] = 3
copy(s[3:], obj[:])
ioutil.WriteFile("out.bin", s, 0666)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment