transport_generic.go (907B)
1 package dbus 2 3 import ( 4 "encoding/binary" 5 "errors" 6 "io" 7 "unsafe" 8 ) 9 10 var nativeEndian binary.ByteOrder 11 12 func detectEndianness() binary.ByteOrder { 13 var x uint32 = 0x01020304 14 if *(*byte)(unsafe.Pointer(&x)) == 0x01 { 15 return binary.BigEndian 16 } 17 return binary.LittleEndian 18 } 19 20 func init() { 21 nativeEndian = detectEndianness() 22 } 23 24 type genericTransport struct { 25 io.ReadWriteCloser 26 } 27 28 func (t genericTransport) SendNullByte() error { 29 _, err := t.Write([]byte{0}) 30 return err 31 } 32 33 func (t genericTransport) SupportsUnixFDs() bool { 34 return false 35 } 36 37 func (t genericTransport) EnableUnixFDs() {} 38 39 func (t genericTransport) ReadMessage() (*Message, error) { 40 return DecodeMessage(t) 41 } 42 43 func (t genericTransport) SendMessage(msg *Message) error { 44 for _, v := range msg.Body { 45 if _, ok := v.(UnixFD); ok { 46 return errors.New("dbus: unix fd passing not enabled") 47 } 48 } 49 return msg.EncodeTo(t, nativeEndian) 50 }