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

tarantool / go-tarantool / 12350021459

16 Dec 2024 09:06AM UTC coverage: 73.845%. First build
12350021459

push

github

oleg-jukovec
Release v2.2.0

6042 of 8182 relevant lines covered (73.85%)

4998.76 hits per line

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

55.0
/uuid/uuid.go
1
// Package with support of Tarantool's UUID data type.
2
//
3
// UUID data type supported in Tarantool since 2.4.1.
4
//
5
// Since: 1.6.0.
6
//
7
// # See also
8
//
9
//   - Tarantool commit with UUID support:
10
//     https://github.com/tarantool/tarantool/commit/d68fc29246714eee505bc9bbcd84a02de17972c5
11
//
12
//   - Tarantool data model:
13
//     https://www.tarantool.io/en/doc/latest/book/box/data_model/
14
//
15
//   - Module UUID:
16
//     https://www.tarantool.io/en/doc/latest/reference/reference_lua/uuid/
17
package uuid
18

19
import (
20
        "fmt"
21
        "reflect"
22

23
        "github.com/google/uuid"
24
        "github.com/vmihailenco/msgpack/v5"
25
)
26

27
// UUID external type.
28
const uuid_extID = 2
29

30
func encodeUUID(e *msgpack.Encoder, v reflect.Value) error {
×
31
        id := v.Interface().(uuid.UUID)
×
32

×
33
        bytes, err := id.MarshalBinary()
×
34
        if err != nil {
×
35
                return fmt.Errorf("msgpack: can't marshal binary uuid: %w", err)
×
36
        }
×
37

38
        _, err = e.Writer().Write(bytes)
×
39
        if err != nil {
×
40
                return fmt.Errorf("msgpack: can't write bytes to msgpack.Encoder writer: %w", err)
×
41
        }
×
42

43
        return nil
×
44
}
45

46
func decodeUUID(d *msgpack.Decoder, v reflect.Value) error {
4✔
47
        var bytesCount = 16
4✔
48
        bytes := make([]byte, bytesCount)
4✔
49

4✔
50
        n, err := d.Buffered().Read(bytes)
4✔
51
        if err != nil {
4✔
52
                return fmt.Errorf("msgpack: can't read bytes on uuid decode: %w", err)
×
53
        }
×
54
        if n < bytesCount {
4✔
55
                return fmt.Errorf("msgpack: unexpected end of stream after %d uuid bytes", n)
×
56
        }
×
57

58
        id, err := uuid.FromBytes(bytes)
4✔
59
        if err != nil {
4✔
60
                return fmt.Errorf("msgpack: can't create uuid from bytes: %w", err)
×
61
        }
×
62

63
        v.Set(reflect.ValueOf(id))
4✔
64
        return nil
4✔
65
}
66

67
func init() {
1✔
68
        msgpack.Register(reflect.TypeOf((*uuid.UUID)(nil)).Elem(), encodeUUID, decodeUUID)
1✔
69
        msgpack.RegisterExtEncoder(uuid_extID, uuid.UUID{},
1✔
70
                func(e *msgpack.Encoder, v reflect.Value) ([]byte, error) {
5✔
71
                        uuid := v.Interface().(uuid.UUID)
4✔
72
                        return uuid.MarshalBinary()
4✔
73
                })
4✔
74
        msgpack.RegisterExtDecoder(uuid_extID, uuid.UUID{},
1✔
75
                func(d *msgpack.Decoder, v reflect.Value, extLen int) error {
5✔
76
                        return decodeUUID(d, v)
4✔
77
                })
4✔
78
}
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