forked from veraison/corim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbytes.go
50 lines (38 loc) · 761 Bytes
/
bytes.go
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
// Copyright 2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package comid
import (
"fmt"
)
const BytesType = "bytes"
type TaggedBytes []byte
func NewBytes(val any) (*TaggedBytes, error) {
var ret TaggedBytes
if val == nil {
return &ret, nil
}
switch t := val.(type) {
case string:
b := []byte(t)
ret = TaggedBytes(b)
case []byte:
ret = TaggedBytes(t)
case *[]byte:
ret = TaggedBytes(*t)
default:
return nil, fmt.Errorf("unexpected type for bytes: %T", t)
}
return &ret, nil
}
func (o TaggedBytes) String() string {
return string(o)
}
func (o TaggedBytes) Valid() error {
return nil
}
func (o TaggedBytes) Type() string {
return "bytes"
}
func (o TaggedBytes) Bytes() []byte {
return o
}