mirror of https://bitbucket.org/ausocean/av.git
rtmp: encode/decode typed boolean
This commit is contained in:
parent
470e61a465
commit
f005c31b44
23
rtmp/amf.go
23
rtmp/amf.go
|
@ -125,11 +125,8 @@ func C_AMF_DecodeNumber(data *byte) float64 {
|
||||||
|
|
||||||
// int AMF_DecodeBoolean(const char *data);
|
// int AMF_DecodeBoolean(const char *data);
|
||||||
// amf.c +132
|
// amf.c +132
|
||||||
func C_AMF_DecodeBoolean(data *byte) int32 {
|
func C_AMF_DecodeBoolean(data *byte) bool {
|
||||||
if *data != 0 {
|
return *data != 0
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// char* AMF_EncodeInt16(char* output, char* outend, short nVal);
|
// char* AMF_EncodeInt16(char* output, char* outend, short nVal);
|
||||||
|
@ -240,15 +237,15 @@ func C_AMF_EncodeNumber(output *byte, outend *byte, dVal float64) *byte {
|
||||||
|
|
||||||
// char* AMF_EncodeBoolean(char* output, char* outend, int bVal);
|
// char* AMF_EncodeBoolean(char* output, char* outend, int bVal);
|
||||||
// amf.c +260
|
// amf.c +260
|
||||||
func C_AMF_EncodeBoolean(output *byte, outend *byte, bVal int) *byte {
|
func C_AMF_EncodeBoolean(output *byte, outend *byte, bVal bool) *byte {
|
||||||
if int(uintptr(unsafe.Pointer(output)))+2 > int(uintptr(unsafe.Pointer(outend))) {
|
if int(uintptr(unsafe.Pointer(output)))+2 > int(uintptr(unsafe.Pointer(outend))) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
*(*byte)(unsafe.Pointer(output)) = AMF_BOOLEAN
|
*(*byte)(unsafe.Pointer(output)) = AMF_BOOLEAN
|
||||||
output = (*byte)(incBytePtr(unsafe.Pointer(output), 1))
|
output = (*byte)(incBytePtr(unsafe.Pointer(output), 1))
|
||||||
val := byte(0x01)
|
var val byte
|
||||||
if bVal == 0 {
|
if bVal {
|
||||||
val = byte(0x00)
|
val = 1
|
||||||
}
|
}
|
||||||
*(*byte)(unsafe.Pointer(output)) = val
|
*(*byte)(unsafe.Pointer(output)) = val
|
||||||
output = (*byte)(incBytePtr(unsafe.Pointer(output), 1))
|
output = (*byte)(incBytePtr(unsafe.Pointer(output), 1))
|
||||||
|
@ -285,7 +282,7 @@ func C_AMF_EncodeNamedNumber(output *byte, outend *byte, key string, val float64
|
||||||
|
|
||||||
// char* AMF_EncodeNamedBoolean(char* output, char* outend, const C_AVal* strname, int bVal);
|
// char* AMF_EncodeNamedBoolean(char* output, char* outend, const C_AVal* strname, int bVal);
|
||||||
// amf.c +299
|
// amf.c +299
|
||||||
func C_AMF_EncodeNamedBoolean(output *byte, outend *byte, key string, val int) *byte {
|
func C_AMF_EncodeNamedBoolean(output *byte, outend *byte, key string, val bool) *byte {
|
||||||
buflen := int(uintptr(unsafe.Pointer(outend)) - uintptr(unsafe.Pointer(output)))
|
buflen := int(uintptr(unsafe.Pointer(outend)) - uintptr(unsafe.Pointer(output)))
|
||||||
if 2+len(key) > buflen {
|
if 2+len(key) > buflen {
|
||||||
return nil
|
return nil
|
||||||
|
@ -356,11 +353,7 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byt
|
||||||
case AMF_NUMBER:
|
case AMF_NUMBER:
|
||||||
pBuffer = C_AMF_EncodeNumber(pBuffer, pBufEnd, float64(p.p_vu.p_number))
|
pBuffer = C_AMF_EncodeNumber(pBuffer, pBufEnd, float64(p.p_vu.p_number))
|
||||||
case AMF_BOOLEAN:
|
case AMF_BOOLEAN:
|
||||||
val := 0
|
pBuffer = C_AMF_EncodeBoolean(pBuffer, pBufEnd, p.p_vu.p_number != 0)
|
||||||
if p.p_vu.p_number != 0 {
|
|
||||||
val = 1
|
|
||||||
}
|
|
||||||
pBuffer = C_AMF_EncodeBoolean(pBuffer, pBufEnd, val)
|
|
||||||
case AMF_STRING:
|
case AMF_STRING:
|
||||||
pBuffer = C_AMF_EncodeString(pBuffer, pBufEnd, CAV(&p.p_vu.p_aval))
|
pBuffer = C_AMF_EncodeString(pBuffer, pBufEnd, CAV(&p.p_vu.p_aval))
|
||||||
case AMF_NULL:
|
case AMF_NULL:
|
||||||
|
|
|
@ -778,7 +778,7 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Link.protocol&RTMP_FEATURE_WRITE == 0 {
|
if r.Link.protocol&RTMP_FEATURE_WRITE == 0 {
|
||||||
enc = C_AMF_EncodeNamedBoolean(enc, pend, CAV(&av_fpad), 0)
|
enc = C_AMF_EncodeNamedBoolean(enc, pend, CAV(&av_fpad), false)
|
||||||
if enc == nil {
|
if enc == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -827,7 +827,7 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
|
||||||
|
|
||||||
/* add auth string */
|
/* add auth string */
|
||||||
if r.Link.auth.av_len != 0 {
|
if r.Link.auth.av_len != 0 {
|
||||||
enc = C_AMF_EncodeBoolean(enc, pend, int(r.Link.lFlags&RTMP_LF_AUTH))
|
enc = C_AMF_EncodeBoolean(enc, pend, r.Link.lFlags&RTMP_LF_AUTH != 0)
|
||||||
if enc == nil {
|
if enc == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue