Skip to content

Commit

Permalink
Fix:(#108) Slice Decoding (#109)
Browse files Browse the repository at this point in the history
* Fixing the decoder bug in #108

* updating changelog

* updating trunk linter and changelog
  • Loading branch information
ShivanshVij authored Apr 28, 2022
1 parent 102665c commit 5785f03
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 0.1
cli:
version: 0.10.1-beta
version: 0.11.0-beta
lint:
enabled:
- [email protected]
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## Fixes

- Fixing issue where generated `decode` functions for slices would not allocate the proper memory before decoding the slice values (Issue #108)

## Changes

- Updating Trunk Linter to `v0.11.0-beta`

## [v0.4.5] - 2022-04-22 (Beta)

## Fixes
Expand Down
5 changes: 5 additions & 0 deletions protoc-gen-frisbee/examples/simple/simple.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ message Request {

message Response{
string Message = 1;
}

message SliceResponse {
repeated Response ResponseSlice = 1;
map<string, Response> ResponseMap = 2;
}
3 changes: 3 additions & 0 deletions protoc-gen-frisbee/templates/decode.templ
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (x *{{CamelCase .FullName}}) decode(d *packet.Decoder) error {
for i := uint32(0); i < sliceSize; i++ {
{{ $decoder := GetLUTDecoder $field.Kind -}}
{{ if eq $field.Kind 11 -}} {{/* protoreflect.MessageKind */ -}}
if x.{{ CamelCaseName $field.Name }}[i] == nil {
x.{{ CamelCaseName $field.Name }}[i] = New{{ CamelCase $field.Message.FullName }}()
}
err = x.{{ CamelCaseName $field.Name }}[i].decode(d)
{{ else -}}
x.{{ CamelCaseName $field.Name }}[i], err = d{{ $decoder }}()
Expand Down

0 comments on commit 5785f03

Please sign in to comment.