嗯,你是对的,我没仔细看。
那就换成 write 吧!
$ go doc encoding/binary.Write
package binary // import "encoding/binary"
func Write(w io.Writer, order ByteOrder, data interface{}) error
Write writes the binary representation of data into w. Data must be a
fixed-size value or a slice of fixed-size values, or a pointer to such data.
Boolean values encode as one byte: 1 for true, and 0 for false. Bytes
written to w are encoded using the specified byte order and read from
successive fields of the data. When writing structs, zero values are written
for fields with blank (_) field names.
别忘了明确字节序:
$ go doc encoding/binary.BigEndian
package binary // import "encoding/binary"
var BigEndian bigEndian
BigEndian is the big-endian implementation of ByteOrder.
$ go doc encoding/binary.LittleEndian
package binary // import "encoding/binary"
var LittleEndian littleEndian
LittleEndian is the little-endian implementation of ByteOrder.
网络字节序是 BigEndian,条件允许的话,一般建议用这个。
【 在 adu (阿杜) 的大作中提到: 】
: 我感觉楼主是要用go,收json,然后转成私有udp发出去。
: 发自「今日水木 on 鸿蒙」
--
FROM 27.38.197.*