rtmp: remove unsafe and C imports from amf.go

unsafe importing functions moved to rtmp.go.
This commit is contained in:
Dan Kortschak 2018-09-16 09:44:04 +09:30
parent 61798fd4a6
commit ea5c54c85d
2 changed files with 37 additions and 43 deletions

View File

@ -33,16 +33,10 @@ LICENSE
*/
package rtmp
/*
#include <stdlib.h>
*/
import "C"
import (
"encoding/binary"
"log"
"math"
"unsafe"
)
var (
@ -55,43 +49,6 @@ const (
AMF3_INTEGER_MIN = -268435456
)
func pp2b(b, e *byte) []byte {
if b == nil {
return nil
}
base := unsafe.Pointer(b)
len := uintptr(unsafe.Pointer(e)) - uintptr(base)
return (*[_Gi]byte)(base)[:len]
}
func pl2b(b *byte, l int) []byte {
if b == nil {
return nil
}
base := unsafe.Pointer(b)
return (*[_Gi]byte)(base)[:l]
}
func b2pp(buf []byte) (b, e *byte) {
if buf == nil {
return nil, nil
}
if len(buf) == 0 {
b = *(**byte)(unsafe.Pointer(&buf))
return b, b
}
b = &buf[0]
e = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(b)) + uintptr(len(buf))))
return b, e
}
func bAddr(buf []byte) *byte {
if len(buf) == 0 {
return nil
}
return &buf[0]
}
// unsigned short AMF_DecodeInt16(const char* data);
// amf.c +41
func C_AMF_DecodeInt16(data []byte) uint16 {

View File

@ -62,6 +62,43 @@ import (
const _Gi = 1 << 30
func pp2b(b, e *byte) []byte {
if b == nil {
return nil
}
base := unsafe.Pointer(b)
len := uintptr(unsafe.Pointer(e)) - uintptr(base)
return (*[_Gi]byte)(base)[:len]
}
func pl2b(b *byte, l int) []byte {
if b == nil {
return nil
}
base := unsafe.Pointer(b)
return (*[_Gi]byte)(base)[:l]
}
func b2pp(buf []byte) (b, e *byte) {
if buf == nil {
return nil, nil
}
if len(buf) == 0 {
b = *(**byte)(unsafe.Pointer(&buf))
return b, b
}
b = &buf[0]
e = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(b)) + uintptr(len(buf))))
return b, e
}
func bAddr(buf []byte) *byte {
if len(buf) == 0 {
return nil
}
return &buf[0]
}
const (
minDataSize = 11
debugMode = false