forked from yutopp/go-rtmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amf_convertible.go
58 lines (48 loc) · 1.1 KB
/
amf_convertible.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Copyright (c) 2018- yutopp (yutopp@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
//
package message
import (
"io"
"github.com/yutopp/go-amf0"
)
type EncodingType uint8
const (
EncodingTypeAMF0 EncodingType = 0
EncodingTypeAMF3 EncodingType = 3
)
type AMFConvertible interface {
FromArgs(args ...interface{}) error
ToArgs(ty EncodingType) ([]interface{}, error)
}
type AMFDecoder interface {
Decode(interface{}) error
Reset(r io.Reader)
}
func NewAMFDecoder(r io.Reader, encTy EncodingType) AMFDecoder {
switch encTy {
case EncodingTypeAMF3:
panic("Unsupported encoding: AMF3")
case EncodingTypeAMF0:
return amf0.NewDecoder(r)
default:
panic("Unreachable")
}
}
type AMFEncoder interface {
Encode(interface{}) error
Reset(w io.Writer)
}
func NewAMFEncoder(w io.Writer, encTy EncodingType) AMFEncoder {
switch encTy {
case EncodingTypeAMF3:
panic("Unsupported encoding: AMF3")
case EncodingTypeAMF0:
return amf0.NewEncoder(w)
default:
panic("Unreachable")
}
}