@@ -192,14 +192,16 @@ const (
192192 // i.e., the body must be 0-length.
193193 // This header field is controlled by the message sender.
194194 fieldSignature
195- // fieldUnixFDs is the number of Unix file descriptors that accompany the message.
196- // If omitted, it is assumed that no Unix file descriptors accompany the message.
197- // The actual file descriptors need to be transferred via platform specific mechanism out-of-band.
198- // They must be sent at the same time as part of the message itself.
199- // They may not be sent before the first byte of the message itself is transferred
200- // or after the last byte of the message itself.
201- // This header field is controlled by the message sender.
202- fieldUnixFDs
195+ )
196+
197+ // D-Bus types,
198+ // see https://dbus.freedesktop.org/doc/dbus-specification.html#id-1.3.8.
199+ const (
200+ typeByte = 'y'
201+ typeUint32 = 'u'
202+ typeString = 's'
203+ typeObjectPath = 'o'
204+ typeSignature = 'g'
203205)
204206
205207// headerField represents a header field.
@@ -220,34 +222,6 @@ type headerField struct {
220222 Code byte
221223}
222224
223- func (f * headerField ) String () string {
224- var name string
225- switch f .Code {
226- case fieldPath :
227- name = "PATH"
228- case fieldInterface :
229- name = "INTERFACE"
230- case fieldMember :
231- name = "MEMBER"
232- case fieldErrorName :
233- name = "ERROR_NAME"
234- case fieldReplySerial :
235- name = "REPLY_SERIAL"
236- case fieldDestination :
237- name = "DESTINATION"
238- case fieldSender :
239- name = "SENDER"
240- case fieldSignature :
241- name = "SIGNATURE"
242- case fieldUnixFDs :
243- name = "UNIX_FDS"
244- default :
245- name = "INVALID"
246- }
247-
248- return name
249- }
250-
251225// decodeHeaderField decodes a header field.
252226func decodeHeaderField (d * decoder , conv * stringConverter ) (f headerField , err error ) {
253227 // Since "(yv)" struct is being decoded, an alignment must be discarded.
@@ -280,20 +254,17 @@ func decodeHeaderField(d *decoder, conv *stringConverter) (f headerField, err er
280254 s []byte
281255 )
282256 switch sign [0 ] {
283- // UINT32 type.
284- case 'u' :
257+ case typeUint32 :
285258 if u , err = d .Uint32 (); err != nil {
286259 return
287260 }
288261 f .U = uint64 (u )
289- // STRING, OBJECT_PATH types.
290- case 's' , 'o' :
262+ case typeString , typeObjectPath :
291263 if s , err = d .String (); err != nil {
292264 return
293265 }
294266 f .S = conv .String (s )
295- // SIGNATURE type.
296- case 'g' :
267+ case typeSignature :
297268 if s , err = d .Signature (); err != nil {
298269 return
299270 }
@@ -367,14 +338,11 @@ func encodeHeaderField(e *encoder, f headerField) error {
367338 e .Signature (f .Signature )
368339
369340 switch f .Signature [0 ] {
370- // UINT32 type.
371- case 'u' :
341+ case typeUint32 :
372342 e .Uint32 (uint32 (f .U ))
373- // STRING, OBJECT_PATH types.
374- case 's' , 'o' :
343+ case typeString , typeObjectPath :
375344 e .String (f .S )
376- // SIGNATURE type.
377- case 'g' :
345+ case typeSignature :
378346 e .Signature (f .S )
379347 default :
380348 return fmt .Errorf ("unknown type: %s" , f .Signature )
0 commit comments