https://github.com/googleapis/go-type-adapters
Type adapters for common Go protobuf messages
https://github.com/googleapis/go-type-adapters
go protobuf
Last synced: about 1 year ago
JSON representation
Type adapters for common Go protobuf messages
- Host: GitHub
- URL: https://github.com/googleapis/go-type-adapters
- Owner: googleapis
- License: apache-2.0
- Archived: true
- Created: 2021-03-31T22:16:24.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T23:07:35.000Z (over 1 year ago)
- Last Synced: 2025-03-02T23:42:19.080Z (over 1 year ago)
- Topics: go, protobuf
- Language: Go
- Homepage:
- Size: 386 KB
- Stars: 15
- Watchers: 42
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Go google.type Adapters



This library provides helper functions for converting between the Go
proto messages in `google.type` (as found in [genproto][]) and Go native
types.
Full docs are at https://pkg.go.dev/github.com/googleapis/go-type-adapters.
### Example
As a simple example, this library can convert between a `google.type.Decimal`
([proto definition][], [Go docs][]) and a Go [big.Float][]:
```go
import (
"github.com/googleapis/go-type-adapters/adapters"
dpb "google.golang.org/genproto/type/decimal"
)
func main() {
decimal := &dpb.Decimal{Value: "12345.678"}
flt, err := adapters.DecimalToFloat(decimal)
if err != nil {
panic(err)
}
// flt is a Go *big.Float and can be used as such...
}
```
[genproto]: https://pkg.go.dev/google.golang.org/genproto
[proto definition]: https://github.com/googleapis/googleapis/blob/master/google/type/decimal.proto
[go docs]: https://pkg.go.dev/google.golang.org/genproto/googleapis/type/decimal
[big.float]: https://golang.org/pkg/math/big/#Float
## License
This software is made available under the [Apache 2.0][] license.
[apache 2.0]: https://www.apache.org/licenses/LICENSE-2.0