本文整理匯總了Golang中github.com/funny/binary.Reader類的典型用法代碼示例。如果您正苦於以下問題:Golang Reader類的具體用法?Golang Reader怎麽用?Golang Reader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Reader類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Unmarshal
func (msg *gatewayMsg) Unmarshal(r *binary.Reader) error {
msg.Command = r.ReadUint8()
// DEBUG("收到:" + strconv.Itoa(int(msg.Command)))
switch msg.Command {
case CMD_NEW_1:
msg.ClientId = r.ReadUint64BE()
msg.Data = r.ReadPacket(binary.SplitByUint8)
case CMD_NEW_2:
msg.ClientId = r.ReadUint64BE()
msg.ClientIds = []uint64{r.ReadUint64BE()}
case CMD_NEW_3:
msg.ClientId = r.ReadUint64BE()
case CMD_DEL:
msg.ClientId = r.ReadUint64BE()
case CMD_MSG:
msg.ClientId = r.ReadUint64BE()
msg.Data = r.ReadPacket(binary.SplitByUvarint)
case CMD_BRD:
num := int(r.ReadUvarint())
msg.ClientIds = make([]uint64, num)
for i := 0; i < num; i++ {
msg.ClientIds[i] = r.ReadUvarint()
}
msg.Data = r.ReadPacket(binary.SplitByUvarint)
}
return nil
}
示例2: Unmarshal
func (msg *TestMessage) Unmarshal(r *binary.Reader) error {
*msg = r.ReadPacket(binary.SplitByUvarint)
return nil
}
示例3: BinaryDecode
func (msg *gatewayMsg) BinaryDecode(r *binary.Reader) error {
msg.Command = r.ReadUint8()
switch msg.Command {
case CMD_NEW_1:
msg.ClientId = r.ReadUint64BE()
msg.Data = r.ReadPacket(binary.SplitByUint8)
case CMD_NEW_2:
msg.ClientId = r.ReadUint64BE()
msg.ClientIds = []uint64{r.ReadUint64BE()}
case CMD_DEL:
msg.ClientId = r.ReadUint64BE()
case CMD_MSG:
msg.ClientId = r.ReadUint64BE()
msg.Data = r.ReadPacket(binary.SplitByUvarint)
case CMD_BRD:
num := int(r.ReadUvarint())
msg.ClientIds = make([]uint64, num)
for i := 0; i < num; i++ {
msg.ClientIds[i] = r.ReadUvarint()
}
msg.Data = r.ReadPacket(binary.SplitByUvarint)
}
return nil
}
示例4: BinaryDecode
func (obj *TestObject) BinaryDecode(r *binary.Reader) error {
obj.X = int(r.ReadVarint())
obj.Y = int(r.ReadVarint())
obj.Z = int(r.ReadVarint())
return nil
}