Test Failed
Push — main ( 973aa1...436074 )
by Christian
02:37
created

proto.MarshalOptions.sizeSingular   F

Complexity

Conditions 20

Size

Total Lines 40
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 20
eloc 40
nop 3
dl 0
loc 40
rs 0
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like proto.MarshalOptions.sizeSingular often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
// Copyright 2018 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
5
// Code generated by generate-types. DO NOT EDIT.
6
7
package proto
8
9
import (
10
	"google.golang.org/protobuf/encoding/protowire"
11
	"google.golang.org/protobuf/reflect/protoreflect"
12
)
13
14
func (o MarshalOptions) sizeSingular(num protowire.Number, kind protoreflect.Kind, v protoreflect.Value) int {
15
	switch kind {
16
	case protoreflect.BoolKind:
17
		return protowire.SizeVarint(protowire.EncodeBool(v.Bool()))
18
	case protoreflect.EnumKind:
19
		return protowire.SizeVarint(uint64(v.Enum()))
20
	case protoreflect.Int32Kind:
21
		return protowire.SizeVarint(uint64(int32(v.Int())))
22
	case protoreflect.Sint32Kind:
23
		return protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int()))))
24
	case protoreflect.Uint32Kind:
25
		return protowire.SizeVarint(uint64(uint32(v.Uint())))
26
	case protoreflect.Int64Kind:
27
		return protowire.SizeVarint(uint64(v.Int()))
28
	case protoreflect.Sint64Kind:
29
		return protowire.SizeVarint(protowire.EncodeZigZag(v.Int()))
30
	case protoreflect.Uint64Kind:
31
		return protowire.SizeVarint(v.Uint())
32
	case protoreflect.Sfixed32Kind:
33
		return protowire.SizeFixed32()
34
	case protoreflect.Fixed32Kind:
35
		return protowire.SizeFixed32()
36
	case protoreflect.FloatKind:
37
		return protowire.SizeFixed32()
38
	case protoreflect.Sfixed64Kind:
39
		return protowire.SizeFixed64()
40
	case protoreflect.Fixed64Kind:
41
		return protowire.SizeFixed64()
42
	case protoreflect.DoubleKind:
43
		return protowire.SizeFixed64()
44
	case protoreflect.StringKind:
45
		return protowire.SizeBytes(len(v.String()))
46
	case protoreflect.BytesKind:
47
		return protowire.SizeBytes(len(v.Bytes()))
48
	case protoreflect.MessageKind:
49
		return protowire.SizeBytes(o.size(v.Message()))
50
	case protoreflect.GroupKind:
51
		return protowire.SizeGroup(num, o.size(v.Message()))
52
	default:
53
		return 0
54
	}
55
}
56