Add WriteEcmaArray func for AMF proto
This commit is contained in:
+18
-2
@@ -60,6 +60,9 @@ func (a *AMF) ReadItem() (any, error) {
|
|||||||
case TypeObject:
|
case TypeObject:
|
||||||
return a.ReadObject()
|
return a.ReadObject()
|
||||||
|
|
||||||
|
case TypeEcmaArray:
|
||||||
|
return a.ReadEcmaArray()
|
||||||
|
|
||||||
case TypeNull:
|
case TypeNull:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
||||||
@@ -174,7 +177,18 @@ func (a *AMF) WriteString(s string) {
|
|||||||
|
|
||||||
func (a *AMF) WriteObject(obj map[string]any) {
|
func (a *AMF) WriteObject(obj map[string]any) {
|
||||||
a.buf = append(a.buf, TypeObject)
|
a.buf = append(a.buf, TypeObject)
|
||||||
|
a.writeKV(obj)
|
||||||
|
a.buf = append(a.buf, 0, 0, TypeObjectEnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AMF) WriteEcmaArray(obj map[string]any) {
|
||||||
|
n := len(obj)
|
||||||
|
a.buf = append(a.buf, TypeEcmaArray, byte(n>>24), byte(n>>16), byte(n>>8), byte(n))
|
||||||
|
a.writeKV(obj)
|
||||||
|
a.buf = append(a.buf, 0, 0, TypeObjectEnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AMF) writeKV(obj map[string]any) {
|
||||||
for k, v := range obj {
|
for k, v := range obj {
|
||||||
n := len(k)
|
n := len(k)
|
||||||
a.buf = append(a.buf, byte(n>>8), byte(n))
|
a.buf = append(a.buf, byte(n>>8), byte(n))
|
||||||
@@ -185,14 +199,16 @@ func (a *AMF) WriteObject(obj map[string]any) {
|
|||||||
a.WriteString(v)
|
a.WriteString(v)
|
||||||
case int:
|
case int:
|
||||||
a.WriteNumber(float64(v))
|
a.WriteNumber(float64(v))
|
||||||
|
case uint32:
|
||||||
|
a.WriteNumber(float64(v))
|
||||||
|
case float64:
|
||||||
|
a.WriteNumber(v)
|
||||||
case bool:
|
case bool:
|
||||||
a.WriteBool(v)
|
a.WriteBool(v)
|
||||||
default:
|
default:
|
||||||
panic(v)
|
panic(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a.buf = append(a.buf, 0, 0, TypeObjectEnd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AMF) WriteNull() {
|
func (a *AMF) WriteNull() {
|
||||||
|
|||||||
Reference in New Issue
Block a user