本文整理匯總了Golang中github.com/funny/binary.Writer類的典型用法代碼示例。如果您正苦於以下問題:Golang Writer類的具體用法?Golang Writer怎麽用?Golang Writer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Writer類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Marshal
func (msg *gatewayMsg) Marshal(w *binary.Writer) error {
w.WriteUint8(msg.Command)
// DEBUG("發送:" + strconv.Itoa(int(msg.Command)))
switch msg.Command {
case CMD_NEW_1:
w.WriteUint64BE(msg.ClientId)
w.WritePacket(msg.Data, binary.SplitByUint8)
case CMD_NEW_2:
w.WriteUint64BE(msg.ClientId)
w.WriteUint64BE(msg.ClientIds[0])
case CMD_NEW_3:
w.WriteUint64BE(msg.ClientId)
case CMD_DEL:
w.WriteUint64BE(msg.ClientId)
case CMD_MSG:
w.WriteUint64BE(msg.ClientId)
goto ENCODE
case CMD_BRD:
w.WriteUvarint(uint64(len(msg.ClientIds)))
for i := 0; i < len(msg.ClientIds); i++ {
w.WriteUvarint(msg.ClientIds[i])
}
goto ENCODE
}
return w.Flush()
ENCODE:
if fast, ok := msg.Message.(packet.FastOutMessage); ok {
binary.SplitByUvarint.WriteHead(w, fast.MarshalSize())
if err := fast.Marshal(w); err != nil {
return err
}
} else {
data, err := msg.Message.(packet.OutMessage).Marshal()
if err != nil {
return err
}
w.WritePacket(data, binary.SplitByUvarint)
}
return w.Flush()
}
示例2: BinaryEncode
func (msg *gatewayMsg) BinaryEncode(w *binary.Writer) error {
w.WriteUint8(msg.Command)
switch msg.Command {
case CMD_NEW_1:
w.WriteUint64BE(msg.ClientId)
w.WritePacket(msg.Data, binary.SplitByUint8)
case CMD_NEW_2:
w.WriteUint64BE(msg.ClientId)
w.WriteUint64BE(msg.ClientIds[0])
case CMD_DEL:
w.WriteUint64BE(msg.ClientId)
case CMD_MSG:
w.WriteUint64BE(msg.ClientId)
w.WritePacket(msg.Data, binary.SplitByUvarint)
case CMD_BRD:
w.WriteUvarint(uint64(len(msg.ClientIds)))
for i := 0; i < len(msg.ClientIds); i++ {
w.WriteUvarint(msg.ClientIds[i])
}
w.WritePacket(msg.Data, binary.SplitByUvarint)
}
return nil
}
示例3: BinaryEncode
func (obj *TestObject) BinaryEncode(w *binary.Writer) error {
w.WriteVarint(int64(obj.X))
w.WriteVarint(int64(obj.Y))
w.WriteVarint(int64(obj.Z))
return nil
}
示例4: Marshal
func (msg TestMessage) Marshal(w *binary.Writer) error {
w.WritePacket(msg, binary.SplitByUvarint)
return nil
}
示例5: Marshal
func (msg RAW) Marshal(w *binary.Writer) error {
_, err := w.Write(msg)
return err
}