go-restruct / restruct

Rich binary (de)serialization library for Golang
https://restruct.io/
ISC License
360 stars 17 forks source link

Simplify example on restruct.io #22

Closed mewmew closed 6 years ago

mewmew commented 6 years ago

A simplified example of the one presented at https://restruct.io/, to help focus on the aspects of the restruct package and not the Go standard library.

 package main

 import (
    "encoding/binary"
    "io/ioutil"
-   "os"

    "gopkg.in/restruct.v1"
 )

 type Record struct {
    Message string `struct:"[128]byte"`
 }

 type Container struct {
    Version   int `struct:"int32"`
    NumRecord int `struct:"int32,sizeof=Records"`
    Records   []Record
 }

 func main() {
    var c Container

-   file, _ := os.Open("records")
-   defer file.Close()
-   data, _ := ioutil.ReadAll(file)
+   data, _ := ioutil.ReadFile("records")

    restruct.Unpack(data, binary.LittleEndian, &c)
 }
jchv commented 6 years ago

Cool, thanks, that looks a bit better. I'll change this when I get a moment.

mewmew commented 6 years ago

Cool, thanks, that looks a bit better. I'll change this when I get a moment.

Happy to.

Out of curiosity, does the site contain any code that you wish to keep private, otherwise of the restruct.io repo was on GitHub, then we may send pull requests in the future :)

jchv commented 6 years ago

Oh, actually, the source code IS available. It's a standard GitHub Pages setup, so you can find it in the gh pages branch. A bit counterintuitive, but to the best of my knowledge there's not a much better way to do so whilst utilizing GitHub Pages.

jchv commented 6 years ago

Thanks for the feedback. I've updated the homepage.

mewmew commented 6 years ago

Oh, actually, the source code IS available. It's a standard GitHub Pages setup, so you can find it in the gh pages branch. A bit counterintuitive, but to the best of my knowledge there's not a much better way to do so whilst utilizing GitHub Pages.

I think you can do this with a CNAME file. See https://github.com/decomp/decomp.org for example.

https://github.com/decomp/decomp.org/blob/gh-pages/CNAME

mewmew commented 6 years ago

That way you can create a restruct.io repository in go-restruct, i.e.

https://github.com/go-restruct/restruct.io