Skip to content
This repository was archived by the owner on Jun 7, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/impl/codec_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ func makeProtoStringerFieldCoder(ft reflect.Type) pointerCoderFuncs {
if reflect.ValueOf(ps).IsNil() {
return 0
}
v, err := ps.ProtoString()
s, err := ps.ProtoStringSize()
if err != nil {
panic(err)
}
return f.tagsize + protowire.SizeBytes(len(v))
return f.tagsize + protowire.SizeBytes(s)
},
marshal: func(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
ps := p.AsValueOf(ft).Elem().Interface().(pref.ProtoStringer)
Expand Down Expand Up @@ -712,11 +712,11 @@ func makeProtoStringerSliceFieldCoder(ft reflect.Type) pointerCoderFuncs {
size: func(p pointer, f *coderFieldInfo, opts marshalOptions) int {
n := 0
for _, v := range p.PointerSlice() {
v, err := v.AsValueOf(ft.Elem()).Interface().(pref.ProtoStringer).ProtoString()
s, err := v.AsValueOf(ft.Elem()).Interface().(pref.ProtoStringer).ProtoStringSize()
if err != nil {
panic(err)
}
n += f.tagsize + protowire.SizeBytes(len(v))
n += f.tagsize + protowire.SizeBytes(s)
}
return n
},
Expand Down
3 changes: 3 additions & 0 deletions reflect/protoreflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,7 @@ type ProtoStringer interface {

// ParseProtoString sets value of struct from string
ParseProtoString(string) error

// ProtoStringSize returns size of the value if converted to string format
ProtoStringSize() (int, error)
}