headBytes renamed buf.

This commit is contained in:
scruzin 2019-01-19 16:41:22 +10:30
parent 8b8afd08b0
commit 45f5817307
1 changed files with 15 additions and 15 deletions

View File

@ -316,7 +316,7 @@ func (pkt *packet) writeTo(c *Conn, queue bool) error {
// The complete packet starts from headerSize _before_ the start the body.
// origIdx is the original offset, which will be 0 for a full (12-byte) header or 11 for a minimum (1-byte) header.
headBytes := pkt.buf
buf := pkt.buf
hSize := headerSizes[pkt.headerType]
origIdx := fullHeaderSize - hSize
@ -356,16 +356,16 @@ func (pkt *packet) writeTo(c *Conn, queue bool) error {
case 2:
ch |= 1
}
headBytes[headerIdx] = ch
buf[headerIdx] = ch
headerIdx++
if cSize != 0 {
tmp := pkt.channel - 64
headBytes[headerIdx] = byte(tmp & 0xff)
buf[headerIdx] = byte(tmp & 0xff)
headerIdx++
if cSize == 2 {
headBytes[headerIdx] = byte(tmp >> 8)
buf[headerIdx] = byte(tmp >> 8)
headerIdx++
}
}
@ -375,24 +375,24 @@ func (pkt *packet) writeTo(c *Conn, queue bool) error {
if ts > 0xffffff {
tmp = 0xffffff
}
amf.EncodeInt24(headBytes[headerIdx:], tmp)
amf.EncodeInt24(buf[headerIdx:], tmp)
headerIdx += 3 // 24bits
}
if headerSizes[pkt.headerType] > 4 {
amf.EncodeInt24(headBytes[headerIdx:], pkt.bodySize)
amf.EncodeInt24(buf[headerIdx:], pkt.bodySize)
headerIdx += 3 // 24bits
headBytes[headerIdx] = pkt.packetType
buf[headerIdx] = pkt.packetType
headerIdx++
}
if headerSizes[pkt.headerType] > 8 {
binary.LittleEndian.PutUint32(headBytes[headerIdx:headerIdx+4], uint32(pkt.info))
binary.LittleEndian.PutUint32(buf[headerIdx:headerIdx+4], uint32(pkt.info))
headerIdx += 4 // 32bits
}
if ts >= 0xffffff {
amf.EncodeInt32(headBytes[headerIdx:], ts)
amf.EncodeInt32(buf[headerIdx:], ts)
headerIdx += 4 // 32bits
}
@ -402,7 +402,7 @@ func (pkt *packet) writeTo(c *Conn, queue bool) error {
if c.deferred == nil {
// Defer sending small audio packets (at most once).
if pkt.packetType == packetTypeAudio && size < chunkSize {
c.deferred = headBytes[origIdx:][:size+hSize]
c.deferred = buf[origIdx:][:size+hSize]
c.log(DebugLevel, pkg+"deferred sending packet", "size", size, "la", c.link.conn.LocalAddr(), "ra", c.link.conn.RemoteAddr())
return nil
}
@ -424,7 +424,7 @@ func (pkt *packet) writeTo(c *Conn, queue bool) error {
if chunkSize > size {
chunkSize = size
}
bytes := headBytes[origIdx:][:chunkSize+hSize]
bytes := buf[origIdx:][:chunkSize+hSize]
if c.deferred != nil {
// Prepend the previously deferred packet and write it with the current one.
c.log(DebugLevel, pkg+"combining deferred packet", "size", len(c.deferred))
@ -450,18 +450,18 @@ func (pkt *packet) writeTo(c *Conn, queue bool) error {
hSize += 4
}
headBytes[origIdx] = 0xc0 | ch
buf[origIdx] = 0xc0 | ch
if cSize != 0 {
tmp := int(pkt.channel) - 64
headBytes[origIdx+1] = byte(tmp)
buf[origIdx+1] = byte(tmp)
if cSize == 2 {
headBytes[origIdx+2] = byte(tmp >> 8)
buf[origIdx+2] = byte(tmp >> 8)
}
}
if ts >= 0xffffff {
extendedTimestamp := headBytes[origIdx+1+cSize:]
extendedTimestamp := buf[origIdx+1+cSize:]
amf.EncodeInt32(extendedTimestamp[:4], ts)
}
}