public int Decode(byte[] pBuffer, int bufferOffset, int nSize, bool bDecodeName) { int nOriginalSize = nSize; bool bError = false; // if there is an error while decoding - try to at least find the end mark 0x000009 while (nSize >= 3) { if (RTMP.ReadInt24(pBuffer, bufferOffset) == 0x00000009) { nSize -= 3; bError = false; break; } if (bError) { nSize--; bufferOffset++; continue; } AMFObjectProperty prop = new AMFObjectProperty(); int nRes = prop.Decode(pBuffer, bufferOffset, nSize, bDecodeName); if (nRes == -1) bError = true; else { nSize -= nRes; bufferOffset += nRes; m_properties.Add(prop); } } if (bError) return -1; return nOriginalSize - nSize; }
public static AMFObject ParseAMF(string amfString) { int depth = 0; AMFObject obj = new AMFObject(); string[] args = amfString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string arg in args) { AMFObjectProperty prop = new AMFObjectProperty(); string p; if (arg[1] == ':') { p = arg.Substring(2); switch (arg[0]) { case 'B': prop.m_type = AMFDataType.AMF_BOOLEAN; prop.p_number = int.Parse(p); break; case 'S': prop.m_type = AMFDataType.AMF_STRING; prop.m_strVal = p; break; case 'N': prop.m_type = AMFDataType.AMF_NUMBER; prop.p_number = double.Parse(p); break; case 'Z': prop.m_type = AMFDataType.AMF_NULL; break; case 'O': int i = int.Parse(p); if (i > 0) { prop.m_type = AMFDataType.AMF_OBJECT; } else { depth--; return obj; } break; default: return null; } } else if (arg[2] == ':' && arg[0] == 'N') { int secondColonIndex = arg.IndexOf(':', 3); if (secondColonIndex < 0 || depth <= 0) return null; prop.m_strName = arg.Substring(3); p = arg.Substring(secondColonIndex + 1); switch (arg[1]) { case 'B': prop.m_type = AMFDataType.AMF_BOOLEAN; prop.p_number = int.Parse(p); break; case 'S': prop.m_type = AMFDataType.AMF_STRING; prop.m_strVal = p; break; case 'N': prop.m_type = AMFDataType.AMF_NUMBER; prop.p_number = double.Parse(p); break; case 'O': prop.m_type = AMFDataType.AMF_OBJECT; break; default: return null; } } else return null; if (depth > 0) { AMFObject o2; for (int i = 0; i < depth; i++) { o2 = obj.GetProperty(obj.GetPropertyCount() - 1).GetObject(); obj = o2; } } obj.AddProperty(prop); if (prop.m_type == AMFDataType.AMF_OBJECT) depth++; } return obj; }
public int DecodeArray(byte[] buffer, int offset, int nSize, int nArrayLen, bool bDecodeName) { int nOriginalSize = nSize; bool bError = false; while (nArrayLen > 0) { nArrayLen--; AMFObjectProperty prop = new AMFObjectProperty(); int nRes = prop.Decode(buffer, offset, nSize, bDecodeName); if (nRes == -1) bError = true; else { nSize -= nRes; offset += nRes; m_properties.Add(prop); } } if (bError) return -1; return nOriginalSize - nSize; }
public void AddProperty(AMFObjectProperty prop) { m_properties.Add(prop); }