-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split things up to build with gopherjs
- Loading branch information
Showing
5 changed files
with
138 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/protofudger | ||
/protofudger.js | ||
/protofudger.js.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
all: protofudger | ||
|
||
protofudger: decode.go main_native.go | ||
go build | ||
|
||
protofudger.js: decode.go main_js.go | ||
gopherjs build -m -o protofudger.js | ||
|
||
clean: | ||
rm -f protofudger | ||
rm -f protofudger.js protofudger.js.map | ||
|
||
.PHONY: all clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// +build js | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/gopherjs/gopherjs/js" | ||
) | ||
|
||
func main() { | ||
js.Global.Set("protofudger", map[string]interface{}{ | ||
"parse": func(d []byte, showAll, showOffsets bool) []string { | ||
l, err := parseBuffer(d, showAll, showOffsets) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return l | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// +build !js | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
var ( | ||
showAll = flag.Bool("show_all", false, "Show all possible types instead of just most likely.") | ||
showOffsets = flag.Bool("show_offsets", false, "Show byte offsets of each value.") | ||
) | ||
|
||
func parseStream(rd io.Reader, showAll, showOffsets bool) ([]string, error) { | ||
d, err := ioutil.ReadAll(rd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return parseBuffer(d, showAll, showOffsets) | ||
} | ||
|
||
func parseAndPrint(rd io.Reader, showAll, showOffsets bool) error { | ||
lines, err := parseStream(rd, showAll, showOffsets) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, l := range lines { | ||
if _, err := fmt.Println(l); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
if len(flag.Args()) == 0 { | ||
if err := parseAndPrint(os.Stdin, *showAll, *showOffsets); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
for _, f := range flag.Args() { | ||
fmt.Printf("parsing %s\n", f) | ||
|
||
func() { | ||
fd, err := os.Open(f) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer fd.Close() | ||
|
||
if err := parseAndPrint(fd, *showAll, *showOffsets); err != nil { | ||
panic(err) | ||
} | ||
}() | ||
} | ||
} |