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
}
Esempio n. 2
0
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
}
Esempio n. 3
0
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
}