-
Notifications
You must be signed in to change notification settings - Fork 6
/
tag.go
183 lines (159 loc) · 5.81 KB
/
tag.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* Go IPP - IPP core protocol implementation in pure Go
*
* Copyright (C) 2020 and up by Alexander Pevzner ([email protected])
* See LICENSE for license terms and conditions
*
* IPP Tags
*/
package goipp
import (
"fmt"
)
// Tag represents a tag used in a binary representation
// of the IPP message
type Tag int
// Tag values
const (
// Delimiter tags
TagZero Tag = 0x00 // Zero tag - used for separators
TagOperationGroup Tag = 0x01 // Operation group
TagJobGroup Tag = 0x02 // Job group
TagEnd Tag = 0x03 // End-of-attributes
TagPrinterGroup Tag = 0x04 // Printer group
TagUnsupportedGroup Tag = 0x05 // Unsupported attributes group
TagSubscriptionGroup Tag = 0x06 // Subscription group
TagEventNotificationGroup Tag = 0x07 // Event group
TagResourceGroup Tag = 0x08 // Resource group
TagDocumentGroup Tag = 0x09 // Document group
TagSystemGroup Tag = 0x0a // System group
TagFuture11Group Tag = 0x0b // Future group 11
TagFuture12Group Tag = 0x0c // Future group 12
TagFuture13Group Tag = 0x0d // Future group 13
TagFuture14Group Tag = 0x0e // Future group 14
TagFuture15Group Tag = 0x0f // Future group 15
// Value tags
TagUnsupportedValue Tag = 0x10 // Unsupported value
TagDefault Tag = 0x11 // Default value
TagUnknown Tag = 0x12 // Unknown value
TagNoValue Tag = 0x13 // No-value value
TagNotSettable Tag = 0x15 // Not-settable value
TagDeleteAttr Tag = 0x16 // Delete-attribute value
TagAdminDefine Tag = 0x17 // Admin-defined value
TagInteger Tag = 0x21 // Integer value
TagBoolean Tag = 0x22 // Boolean value
TagEnum Tag = 0x23 // Enumeration value
TagString Tag = 0x30 // Octet string value
TagDateTime Tag = 0x31 // Date/time value
TagResolution Tag = 0x32 // Resolution value
TagRange Tag = 0x33 // Range value
TagBeginCollection Tag = 0x34 // Beginning of collection value
TagTextLang Tag = 0x35 // Text-with-language value
TagNameLang Tag = 0x36 // Name-with-language value
TagEndCollection Tag = 0x37 // End of collection value
TagText Tag = 0x41 // Text value
TagName Tag = 0x42 // Name value
TagReservedString Tag = 0x43 // Reserved for future string value
TagKeyword Tag = 0x44 // Keyword value
TagURI Tag = 0x45 // URI value
TagURIScheme Tag = 0x46 // URI scheme value
TagCharset Tag = 0x47 // Character set value
TagLanguage Tag = 0x48 // Language value
TagMimeType Tag = 0x49 // MIME media type value
TagMemberName Tag = 0x4a // Collection member name value
TagExtension Tag = 0x7f // Extension point for 32-bit tags
)
// IsDelimiter returns true for delimiter tags
func (tag Tag) IsDelimiter() bool {
return uint(tag) < 0x10
}
// IsGroup returns true for group tags
func (tag Tag) IsGroup() bool {
return tag.IsDelimiter() && tag != TagZero && tag != TagEnd
}
// Type returns Type of Value that corresponds to the tag
func (tag Tag) Type() Type {
if tag.IsDelimiter() {
return TypeInvalid
}
switch tag {
case TagInteger, TagEnum:
return TypeInteger
case TagBoolean:
return TypeBoolean
case TagUnsupportedValue, TagDefault, TagUnknown, TagNotSettable,
TagNoValue, TagDeleteAttr, TagAdminDefine:
// These tags not expected to have value
return TypeVoid
case TagText, TagName, TagReservedString, TagKeyword, TagURI, TagURIScheme,
TagCharset, TagLanguage, TagMimeType, TagMemberName:
return TypeString
case TagDateTime:
return TypeDateTime
case TagResolution:
return TypeResolution
case TagRange:
return TypeRange
case TagTextLang, TagNameLang:
return TypeTextWithLang
case TagBeginCollection:
return TypeCollection
case TagEndCollection:
return TypeVoid
default:
return TypeBinary
}
}
// String() returns a tag name, as defined by RFC 8010
func (tag Tag) String() string {
if 0 <= tag && int(tag) < len(tagNames) {
if s := tagNames[tag]; s != "" {
return s
}
}
if tag < 0x100 {
return fmt.Sprintf("0x%2.2x", uint(tag))
}
return fmt.Sprintf("0x%8.8x", uint(tag))
}
var tagNames = [...]string{
// Delimiter tags
TagZero: "zero",
TagOperationGroup: "operation-attributes-tag",
TagJobGroup: "job-attributes-tag",
TagEnd: "end-of-attributes-tag",
TagPrinterGroup: "printer-attributes-tag",
TagUnsupportedGroup: "unsupported-attributes-tag",
TagSubscriptionGroup: "subscription-attributes-tag",
TagEventNotificationGroup: "event-notification-attributes-tag",
TagResourceGroup: "resource-attributes-tag",
TagDocumentGroup: "document-attributes-tag",
TagSystemGroup: "system-attributes-tag",
// Value tags
TagUnsupportedValue: "unsupported",
TagDefault: "default",
TagUnknown: "unknown",
TagNoValue: "no-value",
TagNotSettable: "not-settable",
TagDeleteAttr: "delete-attribute",
TagAdminDefine: "admin-define",
TagInteger: "integer",
TagBoolean: "boolean",
TagEnum: "enum",
TagString: "octetString",
TagDateTime: "dateTime",
TagResolution: "resolution",
TagRange: "rangeOfInteger",
TagBeginCollection: "collection",
TagTextLang: "textWithLanguage",
TagNameLang: "nameWithLanguage",
TagEndCollection: "endCollection",
TagText: "textWithoutLanguage",
TagName: "nameWithoutLanguage",
TagKeyword: "keyword",
TagURI: "uri",
TagURIScheme: "uriScheme",
TagCharset: "charset",
TagLanguage: "naturalLanguage",
TagMimeType: "mimeMediaType",
TagMemberName: "memberAttrName",
}