Skip to content

Commit

Permalink
v0.5.1 (#14)
Browse files Browse the repository at this point in the history
* Refactor: Extensions (#13)

* Renaming functions to make them publicly available

* Fixing linter

* Updating test

* Updating test

* Updating formatting

* Updating formatting

* Updating formatting

* Update README.md
  • Loading branch information
ShivanshVij authored Nov 17, 2022
1 parent 525bb89 commit 481f846
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 113 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Cache Linters/Formatters
uses: actions/cache@v2
with:
path: ~/.cache/trunk
key: trunk-${{ runner.os }}
uses: actions/checkout@v3

- name: Trunk Check
uses: trunk-io/trunk-action@v1
50 changes: 10 additions & 40 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,30 @@ jobs:
tests:
runs-on: ubuntu-latest
steps:
- id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Go Build Cache
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

- name: Go Mod Cache
uses: actions/cache@v2
uses: actions/setup-go@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
go-version: "1.19"
check-latest: true
cache: true

- name: Test
run: go test -v ./...
tests-race:
runs-on: ubuntu-latest
steps:
- id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Go Build Cache
uses: actions/cache@v2
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

- name: Go Mod Cache
uses: actions/cache@v2
uses: actions/setup-go@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
go-version: "1.19"
check-latest: true
cache: true

- name: Test with Race Conditions
run: go test -race -v ./...
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Tag Replacer
uses: AlexRogalskiy/github-action-tag-replacer@v2.0.1
uses: AlexRogalskiy/github-action-tag-replacer@v2
with:
sourceFile: "./internal/version/version.go"
prefix: 'const (\n Version = "'
Expand Down
4 changes: 3 additions & 1 deletion .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*out
*logs
actions
notifications
external
logs
18 changes: 12 additions & 6 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
version: 0.1
cli:
version: 0.14.1-beta
version: 1.1.0
lint:
enabled:
- gitleaks@8.7.1
- gofmt@1.18.1
- golangci-lint@1.45.2
- markdownlint@0.31.1
- prettier@2.6.2
- actionlint@1.6.22
- git-diff-check
- gitleaks@8.15.0
- gofmt@1.19.3
- golangci-lint@1.50.1
- markdownlint@0.32.2
- prettier@2.7.1
runtimes:
enabled:
- go@1.18.3
- node@16.14.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0)

Go library used for encoding and decoding data types from a portable byte buffer, used in [FRPC](https://github.com/loopholelabs/frisbee)
Go library used for encoding and decoding data types from a portable byte buffer, used in [fRPC](https://github.com/loopholelabs/frpc-go)

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func decodeUint8(b []byte) ([]byte, uint8, error) {
}

// Variable integer encoding with the same format as binary.varint
//(https://developers.google.com/protocol-buffers/docs/encoding#varints)
// (https://developers.google.com/protocol-buffers/docs/encoding#varints)
func decodeUint16(b []byte) ([]byte, uint16, error) {
if len(b) > 1 && b[0] == Uint16Kind[0] {
var x uint16
Expand Down
2 changes: 1 addition & 1 deletion encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func encodeUint8(b *Buffer, value uint8) {
}

// Variable integer encoding with the same format as binary.varint
//(https://developers.google.com/protocol-buffers/docs/encoding#varints)
// (https://developers.google.com/protocol-buffers/docs/encoding#varints)
func encodeUint16(b *Buffer, value uint16) {
b.Write(Uint16Kind)
for value >= continuation {
Expand Down
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
package version

const (
Version = "0.5.0"
Version = "0.5.1"
)
10 changes: 5 additions & 5 deletions pkg/generator/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package generator

const (
extension = ".polyglot.go"
pointer = "*"
mapSuffix = "Map"
slice = "[]"
polyglotAnyKind = "polyglot.AnyKind"
Extension = ".polyglot.go"
Pointer = "*"
MapSuffix = "Map"
Slice = "[]"
PolyglotAnyKind = "polyglot.AnyKind"
)
21 changes: 0 additions & 21 deletions pkg/generator/file.go

This file was deleted.

16 changes: 8 additions & 8 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func New() *Generator {
"Counter": utils.Counter,
"FirstLowerCase": utils.FirstLowerCase,
"FirstLowerCaseName": utils.FirstLowerCaseName,
"FindValue": findValue,
"GetKind": getKind,
"GetLUTEncoder": getLUTEncoder,
"GetLUTDecoder": getLUTDecoder,
"GetEncodingFields": getEncodingFields,
"GetDecodingFields": getDecodingFields,
"GetKindLUT": getKindLUT,
"FindValue": FindValue,
"GetKind": GetKind,
"GetLUTEncoder": GetLUTEncoder,
"GetLUTDecoder": GetLUTDecoder,
"GetEncodingFields": GetEncodingFields,
"GetDecodingFields": GetDecodingFields,
"GetKindLUT": GetKindLUT,
"CustomFields": func() string {
return g.CustomFields()
},
Expand Down Expand Up @@ -119,7 +119,7 @@ func (g *Generator) ExecuteTemplate(
"pluginVersion": version.Version,
"sourcePath": protoFile.Desc.Path(),
"package": packageName,
"requiredImports": requiredImports,
"requiredImports": RequiredImports,
"enums": protoFile.Desc.Enums(),
"messages": protoFile.Desc.Messages(),
"header": header,
Expand Down
2 changes: 1 addition & 1 deletion pkg/generator/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ import (
)

func FileName(name string) string {
return utils.AppendString(name, extension)
return utils.AppendString(name, Extension)
}
2 changes: 1 addition & 1 deletion pkg/generator/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package generator

var (
requiredImports = []string{
RequiredImports = []string{
"github.com/loopholelabs/polyglot-go",
"errors",
}
Expand Down
34 changes: 17 additions & 17 deletions pkg/generator/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,27 @@ var (
}
)

func findValue(field protoreflect.FieldDescriptor) string {
func FindValue(field protoreflect.FieldDescriptor) string {
if kind, ok := typeLUT[field.Kind()]; !ok {
switch field.Kind() {
case protoreflect.EnumKind:
switch field.Cardinality() {
case protoreflect.Optional, protoreflect.Required:
return utils.CamelCase(string(field.Enum().FullName()))
case protoreflect.Repeated:
return utils.CamelCase(utils.AppendString(slice, string(field.Enum().FullName())))
return utils.CamelCase(utils.AppendString(Slice, string(field.Enum().FullName())))
default:
panic(errUnknownCardinality)
}
case protoreflect.MessageKind:
if field.IsMap() {
return utils.CamelCase(utils.AppendString(string(field.FullName()), mapSuffix))
return utils.CamelCase(utils.AppendString(string(field.FullName()), MapSuffix))
} else {
switch field.Cardinality() {
case protoreflect.Optional, protoreflect.Required:
return utils.AppendString(pointer, utils.CamelCase(string(field.Message().FullName())))
return utils.AppendString(Pointer, utils.CamelCase(string(field.Message().FullName())))
case protoreflect.Repeated:
return utils.AppendString(slice, pointer, utils.CamelCase(string(field.Message().FullName())))
return utils.AppendString(Slice, Pointer, utils.CamelCase(string(field.Message().FullName())))
default:
panic(errUnknownCardinality)
}
Expand All @@ -135,19 +135,19 @@ func findValue(field protoreflect.FieldDescriptor) string {
}
} else {
if field.Cardinality() == protoreflect.Repeated {
kind = slice + kind
kind = Slice + kind
}
return kind
}
}

type encodingFields struct {
type EncodingFields struct {
MessageFields []protoreflect.FieldDescriptor
SliceFields []protoreflect.FieldDescriptor
Values []string
}

func getEncodingFields(fields protoreflect.FieldDescriptors) encodingFields {
func GetEncodingFields(fields protoreflect.FieldDescriptors) EncodingFields {
var messageFields []protoreflect.FieldDescriptor
var sliceFields []protoreflect.FieldDescriptor
var values []string
Expand All @@ -173,20 +173,20 @@ func getEncodingFields(fields protoreflect.FieldDescriptors) encodingFields {
}
}
}
return encodingFields{
return EncodingFields{
MessageFields: messageFields,
SliceFields: sliceFields,
Values: values,
}
}

type decodingFields struct {
type DecodingFields struct {
MessageFields []protoreflect.FieldDescriptor
SliceFields []protoreflect.FieldDescriptor
Other []protoreflect.FieldDescriptor
}

func getDecodingFields(fields protoreflect.FieldDescriptors) decodingFields {
func GetDecodingFields(fields protoreflect.FieldDescriptors) DecodingFields {
var messageFields []protoreflect.FieldDescriptor
var sliceFields []protoreflect.FieldDescriptor
var other []protoreflect.FieldDescriptor
Expand All @@ -209,35 +209,35 @@ func getDecodingFields(fields protoreflect.FieldDescriptors) decodingFields {
}
}

return decodingFields{
return DecodingFields{
MessageFields: messageFields,
SliceFields: sliceFields,
Other: other,
}
}

func getKind(kind protoreflect.Kind) string {
func GetKind(kind protoreflect.Kind) string {
var outKind string
var ok bool
if outKind, ok = kindLUT[kind]; !ok {
switch kind {
case protoreflect.MessageKind:
outKind = polyglotAnyKind
outKind = PolyglotAnyKind
default:
panic(errUnknownKind)
}
}
return outKind
}

func getLUTEncoder(kind protoreflect.Kind) string {
func GetLUTEncoder(kind protoreflect.Kind) string {
return encodeLUT[kind]
}

func getLUTDecoder(kind protoreflect.Kind) string {
func GetLUTDecoder(kind protoreflect.Kind) string {
return decodeLUT[kind]
}

func getKindLUT(kind protoreflect.Kind) string {
func GetKindLUT(kind protoreflect.Kind) string {
return kindLUT[kind]
}

0 comments on commit 481f846

Please sign in to comment.