예제 #1
0
// Read	reads the appropriate number of bytes and deserializes the BasicHeader
// from the given io.Reader. If an error is encoutnered along the way, it is
// returned immediately, and the basic header is assumed NOT to be read
// correctly.
func (h *BasicHeader) Read(r io.Reader) error {
	b, err := spec.ReadByte(r)
	if err != nil {
		return err
	}

	h.FormatId = b >> 6

	if b&0x3f == 0x3f {
		tail, err := spec.ReadBytes(r, int(2))
		if err != nil {
			return err
		}

		h.StreamId = spec.Uint32(tail) + 64
	} else if b&0x3f == 0 {
		tail, err := spec.ReadBytes(r, int(1))
		if err != nil {
			return err
		}

		h.StreamId = spec.Uint32(tail) + 64
	} else {
		h.StreamId = spec.Uint32([]byte{b & 0x3f})
	}

	return nil
}
예제 #2
0
// Read slurps four bytes off of the given reader and parses the Delta field out
// as an unsigned, 32-bit integer.
func (t *ExtendedTimestamp) Read(r io.Reader) error {
	buf, err := spec.ReadBytes(r, 4)
	if err != nil {
		return err
	}

	t.Delta = spec.Uint32(buf)
	return nil
}
func (c *WindowAckSize) Read(r io.Reader) error {
	buf, err := spec.ReadBytes(r, 4)
	if err != nil {
		return err
	}

	c.WindowAckSize = spec.Uint32(buf)

	return nil
}
func TestExtendedTimestampWrite(t *testing.T) {
	time := rand.Uint32()
	e := &chunk.ExtendedTimestamp{time}

	buf := new(bytes.Buffer)
	err := e.Write(buf)

	assert.Nil(t, err)
	assert.Equal(t, time, spec.Uint32(buf.Bytes()))
}
예제 #5
0
func (c *AbortMessage) Read(r io.Reader) error {
	buf, err := spec.ReadBytes(r, 4)
	if err != nil {
		return err
	}

	c.ChunkStreamId = spec.Uint32(buf)

	return nil
}
func (c *Acknowledgement) Read(r io.Reader) error {
	buf, err := spec.ReadBytes(r, 4)
	if err != nil {
		return err
	}

	c.SequenceNumber = spec.Uint32(buf)

	return nil
}
예제 #7
0
func (c *SetChunkSize) Read(r io.Reader) error {
	buf, err := spec.ReadBytes(r, 4)
	if err != nil {
		return err
	}

	c.chunkSize = spec.Uint32(buf)

	return nil
}
func (c *SetPeerBandwidth) Read(r io.Reader) error {
	buf, err := spec.ReadBytes(r, 5)
	if err != nil {
		return err
	}

	c.AckWindowSize = spec.Uint32(buf[:4])
	c.LimitType = LimitType(buf[4])

	return nil
}
예제 #9
0
// Read reads a type 0, 1, 2, or 3-format MessageHeader from the given
// io.Reader, using a process as defined in the RTMP specification.
func (m *MessageHeader) Read(r io.Reader) error {
	switch m.FormatId {
	case 0:
		buf, err := spec.ReadBytes(r, 11)
		if err != nil {
			return err
		}

		m.Timestamp = spec.Uint32(buf[:3])
		m.TimestampDelta = false
		m.Length = spec.Uint32(buf[3:6])
		m.TypeId = buf[6]
		m.StreamId = spec.LittleEndianUint32(buf[7:])
	case 1:
		buf, err := spec.ReadBytes(r, 7)
		if err != nil {
			return err
		}

		m.Timestamp = spec.Uint32(buf[:3])
		m.TimestampDelta = true
		m.Length = spec.Uint32(buf[3:6])
		m.TypeId = buf[6]
	case 2:
		buf, err := spec.ReadBytes(r, 3)
		if err != nil {
			return err
		}

		m.Timestamp = spec.Uint32(buf)
		m.TimestampDelta = true
	case 3:
		return nil
	default:
		return ErrUnknownFormatId
	}

	return nil
}