-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix decoder bugs, add example proto, optimise docs
- Loading branch information
Showing
10 changed files
with
569 additions
and
62 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,7 @@ | ||
module exampleperson | ||
|
||
replace exampleperson => ./ | ||
|
||
go 1.21.3 | ||
|
||
require google.golang.org/protobuf v1.32.0 |
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,6 @@ | ||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= | ||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= | ||
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= |
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,56 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os" | ||
|
||
person_pb "exampleperson/person.pb" | ||
|
||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func main() { | ||
// Create a new Person message | ||
person := &person_pb.Person{} | ||
jsonStr := `{ | ||
"name": "John Doe", | ||
"age": 30, | ||
"gender": 1, | ||
"addresses": [ | ||
{ | ||
"street": "123 Main St", | ||
"city": "Anytown", | ||
"state": "CA", | ||
"zip": "12345" | ||
}, | ||
{ | ||
"street": "456 Oak St", | ||
"city": "Othertown", | ||
"state": "NY", | ||
"zip": "67890" | ||
} | ||
] | ||
}` | ||
if err := json.Unmarshal([]byte(jsonStr), person); err != nil { | ||
log.Fatal("unmarshaling error: ", err) | ||
} | ||
|
||
// serialize the Person message | ||
data, err := proto.Marshal(person) | ||
if err != nil { | ||
log.Fatal("marshaling error: ", err) | ||
} | ||
|
||
// write the serialized data to a file | ||
file, err := os.Create("person.bin") | ||
if err != nil { | ||
log.Fatal("file creation error: ", err) | ||
} | ||
defer file.Close() | ||
if n, err := file.Write(data); err != nil { | ||
log.Fatal("file write error: ", err) | ||
} else if n != len(data) { | ||
log.Printf("wrote %d bytes\n", n) | ||
} | ||
} |
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,5 @@ | ||
|
||
John Doe"! | ||
123 Main StAnytownCA"12345"" | ||
|
||
456 Oak St OthertownNY"67890 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.