Skip to content

Commit

Permalink
Merge pull request #171 from philippgille/rename-proto-package-to-pro…
Browse files Browse the repository at this point in the history
…tobuf

Rename proto package to protobuf
  • Loading branch information
philippgille authored Jan 21, 2024
2 parents 918b014 + d68f94b commit 6bcd482
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ This repository contains the subpackage `encoding`, which is an abstraction and

- [X] JSON
- [X] [gob](https://blog.golang.org/gobs-of-data)
- [X] [proto](https://pkg.go.dev/google.golang.org/protobuf/proto)
- [X] [protobuf](https://pkg.go.dev/google.golang.org/protobuf)

More formats will be supported in the future (e.g. XML).

Expand All @@ -132,7 +132,7 @@ Differences between the formats:
- Depending on the use case, the custom (un-)marshal methods of one of the formats might be easier to implement
- JSON: [`MarshalJSON() ([]byte, error)`](https://pkg.go.dev/encoding/json#Marshaler) and [`UnmarshalJSON([]byte) error`](https://pkg.go.dev/encoding/json#Unmarshaler)
- gob: [`GobEncode() ([]byte, error)`](https://pkg.go.dev/encoding/gob#GobEncoder) and [`GobDecode([]byte) error`](https://pkg.go.dev/encoding/gob#GobDecoder)
- proto: [`Marshal(proto.Message) ([]byte, error)`](https://pkg.go.dev/google.golang.org/protobuf/proto#Marshal) and [`Unmarshal([]byte, proto.Message) error`](https://pkg.go.dev/google.golang.org/protobuf/proto#Unmarshal)
- protobuf: [`Marshal(proto.Message) ([]byte, error)`](https://pkg.go.dev/google.golang.org/protobuf/proto#Marshal) and [`Unmarshal([]byte, proto.Message) error`](https://pkg.go.dev/google.golang.org/protobuf/proto#Unmarshal)

### Roadmap

Expand Down
2 changes: 1 addition & 1 deletion build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ done
# Examples
echo "building examples"
(cd "$SCRIPT_DIR"/../examples/redis && go build -v) || (cd "$WORKING_DIR" && echo " failed" && exit 1)
(cd "$SCRIPT_DIR"/../examples/proto_encoding && go build -v) || (cd "$WORKING_DIR" && echo " failed" && exit 1)
(cd "$SCRIPT_DIR"/../examples/protobuf_encoding && go build -v) || (cd "$WORKING_DIR" && echo " failed" && exit 1)

cd "$WORKING_DIR"
2 changes: 1 addition & 1 deletion build/update-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ done

# Examples
(cd "$SCRIPT_DIR"/../examples/redis && go get $(go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all) && go mod tidy) || (cd "$WORKING_DIR" && echo "update failed" && exit 1)
(cd "$SCRIPT_DIR"/../examples/proto_encoding && go get $(go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all) && go mod tidy) || (cd "$WORKING_DIR" && echo "update failed" && exit 1)
(cd "$SCRIPT_DIR"/../examples/protobuf_encoding && go get $(go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all) && go mod tidy) || (cd "$WORKING_DIR" && echo "update failed" && exit 1)

cd "$WORKING_DIR"
5 changes: 0 additions & 5 deletions encoding/proto/go.mod

This file was deleted.

5 changes: 5 additions & 0 deletions encoding/protobuf/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/philippgille/gokv/encoding/protobuf

go 1.20

require google.golang.org/protobuf v1.31.0
File renamed without changes.
2 changes: 1 addition & 1 deletion encoding/proto/proto.go → encoding/protobuf/protobuf.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package proto
package protobuf

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Proto encoding example
======================
Protobuf encoding example
=========================

For this example we already generated the Go file from the `.proto` file, so you can run it with `go run .`.

Expand Down Expand Up @@ -30,13 +30,13 @@ m := reflectedField.Interface().(map[string][]byte)
rawVal := m["foo123"]
fmt.Printf("Raw value: %s\n", rawVal)
// Prints:
// Raw value:
// John Doe����johndoe@example.com"
// Raw value:
// John Doe����johndoe@example.com"
//
// 0123-456789"
// 0123-456789"
//
// 0987-654321*
// 󟛪����
// 0987-654321*
// 󟛪����
```

The reflection usage is only required because the example uses the `gomap` in-memory store. If it was using Redis or another remote store, you could just create a plain (non-`gokv`) client and retrieve the value with that. It would lead to the same result.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package tutorial;

import "google/protobuf/timestamp.proto";

option go_package = "github.com/philippgille/gokv/examples/proto_encoding/tutorialpb";
option go_package = "github.com/philippgille/gokv/examples/protobuf_encoding/tutorialpb";

message Person {
string name = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/philippgille/gokv/examples/proto_encoding
module github.com/philippgille/gokv/examples/protobuf_encoding

go 1.20

require (
github.com/philippgille/gokv v0.6.0
github.com/philippgille/gokv/encoding/proto v0.0.0
github.com/philippgille/gokv/encoding/protobuf v0.0.0
github.com/philippgille/gokv/gomap v0.6.0
google.golang.org/protobuf v1.32.0
)

replace github.com/philippgille/gokv/encoding/proto => ../../encoding/proto
replace github.com/philippgille/gokv/encoding/protobuf => ../../encoding/protobuf

require (
github.com/philippgille/gokv/encoding v0.6.0 // indirect
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"math/rand"

"github.com/philippgille/gokv"
"github.com/philippgille/gokv/encoding/proto"
"github.com/philippgille/gokv/examples/proto_encoding/tutorialpb"
"github.com/philippgille/gokv/encoding/protobuf"
"github.com/philippgille/gokv/examples/protobuf_encoding/tutorialpb"
"github.com/philippgille/gokv/gomap"
"google.golang.org/protobuf/types/known/timestamppb"
)

func main() {
// Create store with customized options (using the proto codec)
// Create store with customized options (using the protobuf codec)
options := gomap.Options{
Codec: proto.Codec,
Codec: protobuf.Codec,
}
store := gomap.NewStore(options)
defer store.Close()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6bcd482

Please sign in to comment.