• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

singnet / snet-daemon / #659

18 Aug 2025 01:56PM UTC coverage: 36.314% (-1.7%) from 38.001%
#659

push

web-flow
chore: fix some minor issues in comments (#641)

Signed-off-by: longhutianjie <keplrnewton@icloud.com>
Co-authored-by: Semyon Novikov <semyon.novikov@singularitynet.io>

5702 of 15702 relevant lines covered (36.31%)

3.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.8
/codec/codec.go
1
package codec
2

3
import (
4
        "fmt"
5

6
        "google.golang.org/grpc/encoding"
7
        _ "google.golang.org/grpc/encoding/gzip"
8
        _ "google.golang.org/grpc/encoding/proto" // ensure the default "proto" codec is registered first
9
        "google.golang.org/protobuf/proto"
10
        "google.golang.org/protobuf/protoadapt"
11
)
12

13
func init() {
6✔
14
        encoding.RegisterCodec(BytesCodec("proto", &protoCodec{}))
6✔
15
        encoding.RegisterCodec(BytesCodec("json", nil))
6✔
16
}
6✔
17

18
func BytesCodec(name string, fallback encoding.Codec) encoding.Codec {
16✔
19
        return bytesCodec{name: name, fallback: fallback}
16✔
20
}
16✔
21

22
type bytesCodec struct {
23
        name     string
24
        fallback encoding.Codec
25
}
26

27
type GrpcFrame struct {
28
        Data []byte
29
}
30

31
func (s bytesCodec) Marshal(v any) ([]byte, error) {
8✔
32
        if m, ok := v.(*GrpcFrame); ok {
11✔
33
                return m.Data, nil
3✔
34
        }
3✔
35

36
        if s.fallback == nil {
6✔
37
                return nil, fmt.Errorf("object %+v not of type codec.GrpcFrame", v)
1✔
38
        }
1✔
39

40
        return s.fallback.Marshal(v)
4✔
41
}
42

43
func (s bytesCodec) Unmarshal(data []byte, v any) error {
8✔
44
        if m, ok := v.(*GrpcFrame); ok {
11✔
45
                m.Data = data
3✔
46
                return nil
3✔
47
        }
3✔
48

49
        if s.fallback == nil {
6✔
50
                return fmt.Errorf("object %+v not of type codec.GrpcFrame", v)
1✔
51
        }
1✔
52

53
        return s.fallback.Unmarshal(data, v)
4✔
54
}
55

56
func (s bytesCodec) Name() string {
31✔
57
        return s.name
31✔
58
}
31✔
59

60
// protoCodec is a Codec implementation with protobuf. It is the default rawCodec for gRPC.
61
type protoCodec struct{}
62

63
func (protoCodec) Name() string {
×
64
        return "proto"
×
65
}
×
66

67
func (protoCodec) Marshal(v any) ([]byte, error) {
6✔
68
        vv := messageV2Of(v)
6✔
69
        if vv == nil {
7✔
70
                return nil, fmt.Errorf("failed to marshal, message is %T, want proto.Message", v)
1✔
71
        }
1✔
72

73
        return proto.Marshal(vv)
5✔
74
}
75

76
func (protoCodec) Unmarshal(data []byte, v any) error {
6✔
77
        vv := messageV2Of(v)
6✔
78
        if vv == nil {
7✔
79
                return fmt.Errorf("failed to unmarshal, message is %T, want proto.Message", v)
1✔
80
        }
1✔
81

82
        return proto.Unmarshal(data, vv)
5✔
83
}
84

85
func messageV2Of(v any) proto.Message {
12✔
86
        switch v := v.(type) {
12✔
87
        case protoadapt.MessageV1:
10✔
88
                return protoadapt.MessageV2Of(v)
10✔
89
        case protoadapt.MessageV2:
×
90
                return v
×
91
        }
92

93
        return nil
2✔
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc