Object read, root obj access fix
This commit is contained in:
parent
369a7c40f4
commit
dbc55a2880
1 changed files with 28 additions and 1 deletions
|
@ -10,7 +10,7 @@ type AMFObj map[interface{}]interface{}
|
||||||
|
|
||||||
func DecodeAMF(data *[]byte) (AMFObj, error) {
|
func DecodeAMF(data *[]byte) (AMFObj, error) {
|
||||||
var byte_idx uint32
|
var byte_idx uint32
|
||||||
var root_obj_idx uint8
|
var root_obj_idx int
|
||||||
amf_root_obj := make(AMFObj)
|
amf_root_obj := make(AMFObj)
|
||||||
for {
|
for {
|
||||||
top_level_obj, err := read_next(data, &byte_idx)
|
top_level_obj, err := read_next(data, &byte_idx)
|
||||||
|
@ -18,6 +18,7 @@ func DecodeAMF(data *[]byte) (AMFObj, error) {
|
||||||
return amf_root_obj, err
|
return amf_root_obj, err
|
||||||
}
|
}
|
||||||
amf_root_obj[root_obj_idx] = top_level_obj
|
amf_root_obj[root_obj_idx] = top_level_obj
|
||||||
|
|
||||||
root_obj_idx += 1
|
root_obj_idx += 1
|
||||||
if byte_idx == uint32(len(*data)) {
|
if byte_idx == uint32(len(*data)) {
|
||||||
break
|
break
|
||||||
|
@ -66,6 +67,30 @@ func read_string(data *[]byte, byte_idx *uint32) (string, error) {
|
||||||
return string(string_bytes), err
|
return string(string_bytes), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func read_object(data *[]byte, byte_idx *uint32) (AMFObj, error) {
|
||||||
|
root_obj := make(AMFObj)
|
||||||
|
for {
|
||||||
|
key, err := read_string(data, byte_idx)
|
||||||
|
if err != nil {
|
||||||
|
return root_obj, err
|
||||||
|
}
|
||||||
|
if key == "" {
|
||||||
|
if end_byte, err := read_bytes(data, byte_idx, 1); err != nil {
|
||||||
|
return root_obj, err
|
||||||
|
} else if end_byte[0] != 9 {
|
||||||
|
return root_obj, errors.New("Object should end but didnt")
|
||||||
|
}
|
||||||
|
return root_obj, nil
|
||||||
|
}
|
||||||
|
val, err := read_next(data, byte_idx)
|
||||||
|
if err != nil {
|
||||||
|
return root_obj, err
|
||||||
|
}
|
||||||
|
root_obj[key] = val
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func read_next(data *[]byte, byte_idx *uint32) (interface{}, error) {
|
func read_next(data *[]byte, byte_idx *uint32) (interface{}, error) {
|
||||||
data_type, err := read_bytes(data, byte_idx, 1)
|
data_type, err := read_bytes(data, byte_idx, 1)
|
||||||
var next_obj interface{}
|
var next_obj interface{}
|
||||||
|
@ -79,6 +104,8 @@ func read_next(data *[]byte, byte_idx *uint32) (interface{}, error) {
|
||||||
next_obj, err = read_bool(data, byte_idx)
|
next_obj, err = read_bool(data, byte_idx)
|
||||||
case 2:
|
case 2:
|
||||||
next_obj, err = read_string(data, byte_idx)
|
next_obj, err = read_string(data, byte_idx)
|
||||||
|
case 3:
|
||||||
|
next_obj, err = read_object(data, byte_idx)
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("Unhandled data type")
|
return nil, errors.New("Unhandled data type")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue