func (this *DataSegment) Bytes(b []byte) []byte { b = serial.Uint16ToBytes(this.Conv, b) b = append(b, byte(CommandData), byte(this.Option)) b = serial.Uint32ToBytes(this.Timestamp, b) b = serial.Uint32ToBytes(this.Number, b) b = serial.Uint32ToBytes(this.SendingNext, b) b = serial.Uint16ToBytes(uint16(this.Data.Len()), b) b = append(b, this.Data.Value...) return b }
func (v *DataSegment) Bytes() buf.Supplier { return func(b []byte) (int, error) { b = serial.Uint16ToBytes(v.Conv, b[:0]) b = append(b, byte(CommandData), byte(v.Option)) b = serial.Uint32ToBytes(v.Timestamp, b) b = serial.Uint32ToBytes(v.Number, b) b = serial.Uint32ToBytes(v.SendingNext, b) b = serial.Uint16ToBytes(uint16(v.Data.Len()), b) b = append(b, v.Data.Bytes()...) return v.ByteSize(), nil } }
func (this *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.Writer) error { cmd, ok := command.(*protocol.CommandSwitchAccount) if !ok { return ErrCommandTypeMismatch } hostStr := "" if cmd.Host != nil { hostStr = cmd.Host.String() } writer.Write([]byte{byte(len(hostStr))}) if len(hostStr) > 0 { writer.Write([]byte(hostStr)) } writer.Write(cmd.Port.Bytes(nil)) idBytes := cmd.ID.Bytes() writer.Write(idBytes) writer.Write(serial.Uint16ToBytes(cmd.AlterIds, nil)) writer.Write([]byte{byte(cmd.Level)}) writer.Write([]byte{cmd.ValidMin}) return nil }
func (v *ChunkWriter) Write(payload *buf.Buffer) error { totalLength := payload.Len() serial.Uint16ToBytes(uint16(totalLength), v.buffer[:0]) v.auth.Authenticate(payload.Bytes())(v.buffer[2:]) copy(v.buffer[2+AuthSize:], payload.Bytes()) _, err := v.writer.Write(v.buffer[:2+AuthSize+payload.Len()]) return err }
func (this *CmdOnlySegment) Bytes(b []byte) []byte { b = serial.Uint16ToBytes(this.Conv, b) b = append(b, byte(this.Command), byte(this.Option)) b = serial.Uint32ToBytes(this.SendingNext, b) b = serial.Uint32ToBytes(this.ReceivinNext, b) b = serial.Uint32ToBytes(this.PeerRTO, b) return b }
func (v *AuthenticationWriter) Write(b []byte) (int, error) { cipherChunk, err := v.auth.Seal(v.buffer[2:2], b) if err != nil { return 0, err } serial.Uint16ToBytes(uint16(len(cipherChunk)), v.buffer[:0]) _, err = v.writer.Write(v.buffer[:2+len(cipherChunk)]) return len(b), err }
func (v *CmdOnlySegment) Bytes() buf.Supplier { return func(b []byte) (int, error) { b = serial.Uint16ToBytes(v.Conv, b[:0]) b = append(b, byte(v.Cmd), byte(v.Option)) b = serial.Uint32ToBytes(v.SendingNext, b) b = serial.Uint32ToBytes(v.ReceivinNext, b) b = serial.Uint32ToBytes(v.PeerRTO, b) return v.ByteSize(), nil } }
func (this *AckSegment) Bytes(b []byte) []byte { b = serial.Uint16ToBytes(this.Conv, b) b = append(b, byte(CommandACK), byte(this.Option)) b = serial.Uint32ToBytes(this.ReceivingWindow, b) b = serial.Uint32ToBytes(this.ReceivingNext, b) b = serial.Uint32ToBytes(this.Timestamp, b) b = append(b, this.Count) for i := byte(0); i < this.Count; i++ { b = serial.Uint32ToBytes(this.NumberList[i], b) } return b }
func (v *AckSegment) Bytes() buf.Supplier { return func(b []byte) (int, error) { b = serial.Uint16ToBytes(v.Conv, b[:0]) b = append(b, byte(CommandACK), byte(v.Option)) b = serial.Uint32ToBytes(v.ReceivingWindow, b) b = serial.Uint32ToBytes(v.ReceivingNext, b) b = serial.Uint32ToBytes(v.Timestamp, b) b = append(b, v.Count) for i := byte(0); i < v.Count; i++ { b = serial.Uint32ToBytes(v.NumberList[i], b) } return v.ByteSize(), nil } }
func (v *AckSegment) Bytes() buf.Supplier { return func(b []byte) (int, error) { b = serial.Uint16ToBytes(v.Conv, b[:0]) b = append(b, byte(CommandACK), byte(v.Option)) b = serial.Uint32ToBytes(v.ReceivingWindow, b) b = serial.Uint32ToBytes(v.ReceivingNext, b) b = serial.Uint32ToBytes(v.Timestamp, b) count := byte(len(v.NumberList)) b = append(b, count) for _, number := range v.NumberList { b = serial.Uint32ToBytes(number, b) } return v.ByteSize(), nil } }
// Seal implements cipher.AEAD.Seal(). func (v *SimpleAuthenticator) Seal(dst, nonce, plain, extra []byte) []byte { dst = append(dst, 0, 0, 0, 0) dst = serial.Uint16ToBytes(uint16(len(plain)), dst) dst = append(dst, plain...) fnvHash := fnv.New32a() fnvHash.Write(dst[4:]) fnvHash.Sum(dst[:0]) len := len(dst) xtra := 4 - len%4 if xtra != 4 { dst = append(dst, make([]byte, xtra)...) } xorfwd(dst) if xtra != 4 { dst = dst[:len] } return dst }
func (v *UTP) Write(b []byte) (int, error) { serial.Uint16ToBytes(v.connectionId, b[:0]) b[2] = v.header b[3] = v.extension return 4, nil }
// Bytes returns the correspoding bytes of v Port, in big endian order. func (v Port) Bytes(b []byte) []byte { return serial.Uint16ToBytes(v.Value(), b) }
func (v *ChunkNonceGenerator) Next() []byte { serial.Uint16ToBytes(v.count, v.Nonce[:0]) v.count++ return v.Nonce[:v.Size] }
// Bytes returns the correspoding bytes of this Port, in big endian order. func (this Port) Bytes(b []byte) []byte { return serial.Uint16ToBytes(this.Value(), b) }
func (b *Buffer) AppendUint16(v uint16) *Buffer { b.Value = serial.Uint16ToBytes(v, b.Value) return b }
func (b *Buffer) PrependUint16(v uint16) *Buffer { b.SliceBack(2) serial.Uint16ToBytes(v, b.Value[:0]) return b }
func (v *SRTP) Write(b []byte) (int, error) { v.number++ serial.Uint16ToBytes(v.number, b[:0]) serial.Uint16ToBytes(v.number, b[:2]) return 4, nil }