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

kshard / wreck / 10407194664

15 Aug 2024 04:38PM UTC coverage: 49.091%. First build
10407194664

push

github

web-flow
wreck codec (#1)

81 of 165 new or added lines in 4 files covered. (49.09%)

81 of 165 relevant lines covered (49.09%)

0.55 hits per line

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

77.05
/codec.go
1
//
2
// Copyright (C) 2024 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license. See the LICENSE file for details.
6
// https://github.com/kshard/wreck
7
//
8

9
package wreck
10

11
import (
12
        "encoding/binary"
13
        "errors"
14
        "io"
15
)
16

17
type Chunk struct {
18
        UniqueKey []uint8
19
        SortKey   []uint8
20
        Vector    []uint8
21
}
22

23
func Encode(w io.Writer, wreck *Chunk) error {
1✔
24
        var head [8]uint8
1✔
25

1✔
26
        szData := len(wreck.Vector)
1✔
27
        szUniqueKey := len(wreck.UniqueKey)
1✔
28
        szSortKey := len(wreck.SortKey)
1✔
29
        szWreck := szData + szUniqueKey + szSortKey
1✔
30

1✔
31
        binary.LittleEndian.PutUint32(head[0:4], uint32(szWreck))
1✔
32
        binary.LittleEndian.PutUint16(head[4:6], uint16(szData))
1✔
33
        binary.LittleEndian.PutUint16(head[6:8], uint16(szSortKey))
1✔
34

1✔
35
        if _, err := w.Write(head[:]); err != nil {
1✔
NEW
36
                return err
×
NEW
37
        }
×
38

39
        if szData > 0 {
2✔
40
                if _, err := w.Write(wreck.Vector); err != nil {
1✔
NEW
41
                        return err
×
NEW
42
                }
×
43
        }
44

45
        if szSortKey > 0 {
2✔
46
                if _, err := w.Write(wreck.SortKey); err != nil {
1✔
NEW
47
                        return err
×
NEW
48
                }
×
49
        }
50

51
        if szUniqueKey > 0 {
2✔
52
                if _, err := w.Write(wreck.UniqueKey); err != nil {
1✔
NEW
53
                        return err
×
NEW
54
                }
×
55
        }
56

57
        return nil
1✔
58
}
59

60
func Decode(r io.Reader, wreck *Chunk) error {
1✔
61
        var head [8]uint8
1✔
62

1✔
63
        if _, err := io.ReadFull(r, head[:]); err != nil {
1✔
NEW
64
                return err
×
NEW
65
        }
×
66

67
        szWreck := int(binary.LittleEndian.Uint32(head[0:4]))
1✔
68
        szData := int(binary.LittleEndian.Uint16(head[4:6]))
1✔
69
        szSortKey := int(binary.LittleEndian.Uint16(head[6:8]))
1✔
70
        szUniqueKey := szWreck - szData - szSortKey
1✔
71

1✔
72
        b := make([]uint8, szWreck)
1✔
73
        if _, err := io.ReadFull(r, b); err != nil {
1✔
NEW
74
                if !errors.Is(err, io.EOF) {
×
NEW
75
                        return err
×
NEW
76
                }
×
NEW
77
                return io.ErrUnexpectedEOF
×
78
        }
79

80
        if szData == 0 {
2✔
81
                wreck.Vector = nil
1✔
82
        } else {
2✔
83
                wreck.Vector = b[0:szData]
1✔
84
        }
1✔
85

86
        if szSortKey == 0 {
2✔
87
                wreck.SortKey = nil
1✔
88
        } else {
2✔
89
                wreck.SortKey = b[szData : szData+szSortKey]
1✔
90
        }
1✔
91

92
        if szUniqueKey == 0 {
2✔
93
                wreck.UniqueKey = nil
1✔
94
        } else {
2✔
95
                wreck.UniqueKey = b[szData+szSortKey : szData+szSortKey+szUniqueKey]
1✔
96
        }
1✔
97

98
        return nil
1✔
99
}
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

© 2026 Coveralls, Inc