File: convert.go

package info (click to toggle)
golang-github-tinylib-msgp 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 836 kB
  • sloc: makefile: 47
file content (83 lines) | stat: -rw-r--r-- 1,686 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package _generated

import "errors"

//go:generate msgp

//msgp:shim ConvertStringVal as:string using:fromConvertStringVal/toConvertStringVal mode:convert
//msgp:ignore ConvertStringVal

func fromConvertStringVal(v ConvertStringVal) (string, error) {
	return string(v), nil
}

func toConvertStringVal(s string) (ConvertStringVal, error) {
	return ConvertStringVal(s), nil
}

type ConvertStringVal string

type ConvertString struct {
	String ConvertStringVal
}

type ConvertStringSlice struct {
	Strings []ConvertStringVal
}

type ConvertStringMapValue struct {
	Strings map[string]ConvertStringVal
}

//msgp:shim ConvertIntfVal as:interface{} using:fromConvertIntfVal/toConvertIntfVal mode:convert
//msgp:ignore ConvertIntfVal

func fromConvertIntfVal(v ConvertIntfVal) (interface{}, error) {
	return v.Test, nil
}

func toConvertIntfVal(s interface{}) (ConvertIntfVal, error) {
	return ConvertIntfVal{Test: s.(string)}, nil
}

type ConvertIntfVal struct {
	Test string
}

type ConvertIntf struct {
	Intf ConvertIntfVal
}

//msgp:shim ConvertErrVal as:string using:fromConvertErrVal/toConvertErrVal mode:convert
//msgp:ignore ConvertErrVal

var (
	errConvertFrom = errors.New("error: convert from")
	errConvertTo   = errors.New("error: convert to")
)

const (
	fromFailStr = "fromfail"
	toFailStr   = "tofail"
)

func fromConvertErrVal(v ConvertErrVal) (string, error) {
	s := string(v)
	if s == fromFailStr {
		return "", errConvertFrom
	}
	return s, nil
}

func toConvertErrVal(s string) (ConvertErrVal, error) {
	if s == toFailStr {
		return ConvertErrVal(""), errConvertTo
	}
	return ConvertErrVal(s), nil
}

type ConvertErrVal string

type ConvertErr struct {
	Err ConvertErrVal
}