Skip to content

Commit

Permalink
Refactor protobuf marshaling with utils
Browse files Browse the repository at this point in the history
This commit replaces the usage of the `protojson` method for marshaling and unmarshaling protobuf objects in `crown_jewel.go` with the `FastMarshal` and `FastUnmarshal` methods from `utils`.
protojson is failing to unmarshal resources.
  • Loading branch information
jakule committed May 7, 2024
1 parent f62dd48 commit 0cc7e5e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/services/crown_jewel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ package services

import (
"context"
"google.golang.org/protobuf/encoding/protojson"

"github.com/gravitational/trace"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

crownjewelv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/crownjewel/v1"
"github.com/gravitational/teleport/lib/utils"
)

// CrownJewels is the interface for managing crown jewel resources.
Expand Down Expand Up @@ -57,7 +57,7 @@ func MarshalCrownJewel(object *crownjewelv1.CrownJewel, opts ...MarshalOption) (
object = proto.Clone(object).(*crownjewelv1.CrownJewel)
object.Metadata.Revision = ""
}
data, err := protojson.Marshal(object)
data, err := utils.FastMarshal(object)
if err != nil {
return nil, trace.Wrap(err)
}
Expand All @@ -74,7 +74,7 @@ func UnmarshalCrownJewel(data []byte, opts ...MarshalOption) (*crownjewelv1.Crow
return nil, trace.Wrap(err)
}
var obj crownjewelv1.CrownJewel
if err := protojson.Unmarshal(data, &obj); err != nil {
if err := utils.FastUnmarshal(data, &obj); err != nil {
return nil, trace.BadParameter(err.Error())
}
if cfg.Revision != "" {
Expand Down

0 comments on commit 0cc7e5e

Please sign in to comment.