rtmp: make C_AMF_EncodeArray take a []byte

This commit is contained in:
Dan Kortschak 2018-09-15 10:52:36 +09:30
parent d01109ced6
commit 47e6db5ca1
1 changed files with 8 additions and 8 deletions

View File

@ -325,8 +325,7 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, dst []byte) *byte {
case AMF_ECMA_ARRAY:
pBuffer = C_AMF_EncodeEcmaArray(&p.p_vu.p_object, dst)
case AMF_STRICT_ARRAY:
b, e := b2pp(dst)
pBuffer = C_AMF_EncodeArray(&p.p_vu.p_object, b, e)
pBuffer = C_AMF_EncodeArray(&p.p_vu.p_object, dst)
default:
log.Println("C_AMF_PropEncode: invalid type!")
pBuffer = nil
@ -616,16 +615,17 @@ func C_AMF_EncodeEcmaArray(obj *C_AMFObject, dst []byte) *byte {
// char* AMF_EncodeArray(AMFObject* obj, char* pBuffer, char* pBufEnd);
// amf.c +959
func C_AMF_EncodeArray(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte {
if int(uintptr(unsafe.Pointer(pBuffer)))+4 >= int(uintptr(unsafe.Pointer(pBufEnd))) {
func C_AMF_EncodeArray(obj *C_AMFObject, dst []byte) *byte {
if len(dst) < 5 {
return nil
}
*pBuffer = AMF_STRICT_ARRAY
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
pBuffer = C_AMF_EncodeInt32(pp2b(pBuffer, pBufEnd), int32(len(obj.o_props)))
dst[0] = AMF_STRICT_ARRAY
dst = dst[1:]
binary.BigEndian.PutUint32(dst[:4], uint32(len(obj.o_props)))
dst = dst[4:]
pBuffer, pBufEnd := b2pp(dst)
for i := 0; i < len(obj.o_props); i++ {
res := C_AMF_PropEncode(&obj.o_props[i], pp2b(pBuffer, pBufEnd))
if res == nil {