package proto
import (
)
func ( Message) int {
return MarshalOptions{}.Size()
}
func ( MarshalOptions) ( Message) int {
if == nil {
return 0
}
return .size(.ProtoReflect())
}
func ( MarshalOptions) ( protoreflect.Message) ( int) {
:= protoMethods()
if != nil && .Size != nil {
:= .Size(protoiface.SizeInput{
Message: ,
})
return .Size
}
if != nil && .Marshal != nil {
, := .Marshal(protoiface.MarshalInput{
Message: ,
})
return len(.Buf)
}
return .sizeMessageSlow()
}
func ( MarshalOptions) ( protoreflect.Message) ( int) {
if messageset.IsMessageSet(.Descriptor()) {
return .sizeMessageSet()
}
.Range(func( protoreflect.FieldDescriptor, protoreflect.Value) bool {
+= .sizeField(, )
return true
})
+= len(.GetUnknown())
return
}
func ( MarshalOptions) ( protoreflect.FieldDescriptor, protoreflect.Value) ( int) {
:= .Number()
switch {
case .IsList():
return .sizeList(, , .List())
case .IsMap():
return .sizeMap(, , .Map())
default:
return protowire.SizeTag() + .sizeSingular(, .Kind(), )
}
}
func ( MarshalOptions) ( protowire.Number, protoreflect.FieldDescriptor, protoreflect.List) ( int) {
if .IsPacked() && .Len() > 0 {
:= 0
for , := 0, .Len(); < ; ++ {
+= .sizeSingular(, .Kind(), .Get())
}
return protowire.SizeTag() + protowire.SizeBytes()
}
for , := 0, .Len(); < ; ++ {
+= protowire.SizeTag() + .sizeSingular(, .Kind(), .Get())
}
return
}
func ( MarshalOptions) ( protowire.Number, protoreflect.FieldDescriptor, protoreflect.Map) ( int) {
.Range(func( protoreflect.MapKey, protoreflect.Value) bool {
+= protowire.SizeTag()
+= protowire.SizeBytes(.sizeField(.MapKey(), .Value()) + .sizeField(.MapValue(), ))
return true
})
return
}