From ea5c54c85d976ae1f470aa1241082f5f69bfdd91 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Sun, 16 Sep 2018 09:44:04 +0930 Subject: [PATCH] rtmp: remove unsafe and C imports from amf.go unsafe importing functions moved to rtmp.go. --- rtmp/amf.go | 43 ------------------------------------------- rtmp/rtmp.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 43 deletions(-) diff --git a/rtmp/amf.go b/rtmp/amf.go index 0a48ca2d..d46ea16e 100644 --- a/rtmp/amf.go +++ b/rtmp/amf.go @@ -33,16 +33,10 @@ LICENSE */ package rtmp -/* -#include -*/ -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 { diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 3541da53..6ae887ea 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -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