• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package http2interop
2
3import (
4	"fmt"
5	"io"
6)
7
8type UnknownFrame struct {
9	Header FrameHeader
10	Data   []byte
11}
12
13func (f *UnknownFrame) GetHeader() *FrameHeader {
14	return &f.Header
15}
16
17func (f *UnknownFrame) ParsePayload(r io.Reader) error {
18	raw := make([]byte, f.Header.Length)
19	if _, err := io.ReadFull(r, raw); err != nil {
20		return err
21	}
22	return f.UnmarshalPayload(raw)
23}
24
25func (f *UnknownFrame) UnmarshalPayload(raw []byte) error {
26	if f.Header.Length != len(raw) {
27		return fmt.Errorf("Invalid Payload length %d != %d", f.Header.Length, len(raw))
28	}
29
30	f.Data = []byte(string(raw))
31
32	return nil
33}
34
35func (f *UnknownFrame) MarshalPayload() ([]byte, error) {
36	return []byte(string(f.Data)), nil
37}
38
39func (f *UnknownFrame) MarshalBinary() ([]byte, error) {
40	f.Header.Length = len(f.Data)
41	buf, err := f.Header.MarshalBinary()
42	if err != nil {
43		return nil, err
44	}
45
46	payload, err := f.MarshalPayload()
47	if err != nil {
48		return nil, err
49	}
50
51	buf = append(buf, payload...)
52
53	return buf, nil
54}
55