Skip to content

Commit ef02f1b

Browse files
committed
cleanup serialisation
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
1 parent 27e265b commit ef02f1b

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

fieldpath/serialize-pe.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"strconv"
24+
"strings"
2425

2526
"github.com/go-json-experiment/json"
2627
"sigs.k8s.io/structured-merge-diff/v6/value"
@@ -68,14 +69,15 @@ func DeserializePathElement(s string) (PathElement, error) {
6869
FieldName: &str,
6970
}, nil
7071
case peValueSepBytes[0]:
71-
v, err := value.FromJSON([]byte(rest))
72-
if err != nil {
72+
var v any
73+
if err := json.UnmarshalRead(strings.NewReader(rest), &v); err != nil {
7374
return PathElement{}, err
7475
}
75-
return PathElement{Value: &v}, nil
76+
interfaceValue := value.NewValueInterface(v)
77+
return PathElement{Value: &interfaceValue}, nil
7678
case peKeySepBytes[0]:
7779
var fields value.FieldList
78-
if err := json.Unmarshal([]byte(rest), &fields); err != nil {
80+
if err := json.UnmarshalRead(strings.NewReader(rest), &fields); err != nil {
7981
return PathElement{}, err
8082
}
8183
return PathElement{Key: &fields}, nil
@@ -103,7 +105,7 @@ func SerializePathElement(pe PathElement) (string, error) {
103105

104106
type pathElementSerializer struct {
105107
builder bytes.Buffer
106-
fastValue value.MarshalValue
108+
fastValue value.FastMarshalValue
107109
}
108110

109111
func (pes *pathElementSerializer) reset() {

value/fields.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ type Field struct {
3232
Value Value
3333
}
3434

35-
type MarshalValue struct {
35+
// Not meant to be used by an external library.
36+
type FastMarshalValue struct {
3637
Value *Value
3738
}
3839

39-
func (mv MarshalValue) MarshalJSONTo(enc *jsontext.Encoder) error {
40+
func (mv FastMarshalValue) MarshalJSONTo(enc *jsontext.Encoder) error {
4041
return valueMarshalJSONTo(enc, *mv.Value)
4142
}
4243

0 commit comments

Comments
 (0)