本文整理汇总了C#中AMFWriter类的典型用法代码示例。如果您正苦于以下问题:C# AMFWriter类的具体用法?C# AMFWriter怎么用?C# AMFWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AMFWriter类属于命名空间,在下文中一共展示了AMFWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteData
public void WriteData(AMFWriter writer, object data)
{
NameObjectCollectionBase collection = data as NameObjectCollectionBase;
object[] attributes = collection.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
if (attributes != null && attributes.Length > 0)
{
DefaultMemberAttribute defaultMemberAttribute = attributes[0] as DefaultMemberAttribute;
PropertyInfo pi = collection.GetType().GetProperty(defaultMemberAttribute.MemberName, new Type[] { typeof(string) });
if (pi != null)
{
ASObject aso = new ASObject();
for (int i = 0; i < collection.Keys.Count; i++)
{
string key = collection.Keys[i];
object value = pi.GetValue(collection, new object[]{ key });
aso.Add(key, value);
}
writer.WriteByte(AMF3TypeCode.Object);
writer.WriteAMF3Object(aso);
return;
}
}
//We could not access an indexer so write out as it is.
writer.WriteByte(AMF3TypeCode.Object);
writer.WriteAMF3Object(data);
}
示例2: WriteData
public void WriteData(AMFWriter writer, object data) {
if (data is INullable) {
if ((data as INullable).IsNull) {
writer.WriteAMF3Null();
return;
}
}
if (data is SqlByte) {
writer.WriteAMF3Data(((SqlByte)data).Value);
return;
}
if (data is SqlInt16) {
writer.WriteAMF3Data(((SqlInt16)data).Value);
return;
}
if (data is SqlInt32) {
writer.WriteAMF3Data(((SqlInt32)data).Value);
return;
}
if (data is SqlInt64) {
writer.WriteAMF3Data(((SqlInt64)data).Value);
return;
}
if (data is SqlSingle) {
writer.WriteAMF3Data(((SqlSingle)data).Value);
return;
}
if (data is SqlDouble) {
writer.WriteAMF3Data(((SqlDouble)data).Value);
return;
}
if (data is SqlDecimal) {
writer.WriteAMF3Data(((SqlDecimal)data).Value);
return;
}
if (data is SqlMoney) {
writer.WriteAMF3Data(((SqlMoney)data).Value);
return;
}
if (data is SqlDateTime) {
writer.WriteAMF3Data(((SqlDateTime)data).Value);
return;
}
if (data is SqlString) {
writer.WriteAMF3String(((SqlString)data).Value);
return;
}
if (data is SqlGuid) {
writer.WriteAMF3Data(((SqlGuid)data).Value.ToString("D"));
return;
}
if (data is SqlBoolean) {
writer.WriteAMF3Bool(((SqlBoolean)data).Value);
return;
}
string msg = string.Format("Could not find serializer for type {0}", data.GetType().FullName);
if (_log.IsErrorEnabled)
_log.Error(msg);
throw new FluorineException(msg);
}
示例3: WriteData
public void WriteData(AMFWriter writer, object data)
{
var collection = data as NameObjectCollectionBase;
var attributes = collection.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
if (attributes != null && attributes.Length > 0)
{
var defaultMemberAttribute = attributes[0] as DefaultMemberAttribute;
var pi = collection.GetType().GetProperty(defaultMemberAttribute.MemberName, new[] { typeof(string) });
if (pi != null)
{
var aso = new ASObject();
for (var i = 0; i < collection.Keys.Count; i++)
{
var key = collection.Keys[i];
var value = pi.GetValue(collection, new object[]{ key });
aso.Add(key, value);
}
writer.WriteASO(ObjectEncoding.AMF0, aso);
return;
}
}
//We could not access an indexer so write out as it is.
writer.WriteObject(ObjectEncoding.AMF0, data);
}
示例4: FlvWriter
public FlvWriter(Stream stream, bool append)
{
_writer = new AMFWriter(stream);
_append = append;
if (_append)
{
if (stream.Length > 9 + 15)
{
try
{
//Skip header
stream.Position = 9;
byte[] tagBuffer = new byte[15];
//previousTagSize
stream.Read(tagBuffer, 0, 4);
//start of flv tag
byte dataType = (byte)stream.ReadByte();
if (dataType == IOConstants.TYPE_METADATA)
{
_metaPosition = stream.Position - 1;
//body size
stream.Read(tagBuffer, 5, 3);
int bodySize = tagBuffer[5] << 16 | tagBuffer[6] << 8 | tagBuffer[7];
//timestamp
stream.Read(tagBuffer, 8, 4);
//streamid
stream.Read(tagBuffer, 12, 3);
byte[] buffer = new byte[bodySize];
stream.Read(buffer, 0, buffer.Length);
MemoryStream ms = new MemoryStream(buffer);
AMFReader input = new AMFReader(ms);
string onMetaData = input.ReadData() as string;//input.ReadString();
IDictionary properties = input.ReadData() as IDictionary;
if (properties.Contains("duration"))
_duration = System.Convert.ToInt32(properties["duration"]);
else
{
#if !SILVERLIGHT
log.Warn("Could not read Flv duration from metadata");
#endif
}
}
else
{
#if !SILVERLIGHT
log.Warn("Could not read Flv duration");
#endif
}
}
catch (Exception ex)
{
#if !SILVERLIGHT
log.Warn("Error reading Flv duration", ex);
#endif
}
}
stream.Seek(0, SeekOrigin.End);//Appending
}
}
示例5: WriteData
public void WriteData(AMFWriter writer, object data) {
if (data is byte[])
data = new ByteArray(data as byte[]);
if (data is ByteArray) {
writer.WriteByteArray(data as ByteArray);
}
}
示例6: ByteArray
/// <summary>
/// Initializes a new instance of the ByteArray class.
/// </summary>
public ByteArray() {
_memoryStream = new MemoryStream();
AMFReader amfReader = new AMFReader(_memoryStream);
AMFWriter amfWriter = new AMFWriter(_memoryStream);
_dataOutput = new DataOutput(amfWriter);
_dataInput = new DataInput(amfReader);
_objectEncoding = ObjectEncoding.AMF3;
}
示例7: WriteData
public void WriteData(AMFWriter writer, object data)
{
if( data is IList )
{
IList list = data as IList;
object[] array = new object[list.Count];
list.CopyTo(array, 0);
writer.WriteArray(ObjectEncoding.AMF0, array);
return;
}
#if !(SILVERLIGHT)
IListSource listSource = data as IListSource;
if (listSource != null)
{
IList list = listSource.GetList();
object[] array = new object[list.Count];
list.CopyTo(array, 0);
writer.WriteArray(ObjectEncoding.AMF0, array);
return;
}
#endif
if(data is IDictionary)
{
writer.WriteAssociativeArray(ObjectEncoding.AMF0, data as IDictionary);
return;
}
if(data is Exception)
{
writer.WriteASO(ObjectEncoding.AMF0, new ExceptionASO(data as Exception) );
return;
}
if (data is IEnumerable)
{
List<object> tmp = new List<object>();
foreach (object element in (data as IEnumerable))
{
tmp.Add(element);
}
writer.WriteArray(ObjectEncoding.AMF0, tmp.ToArray());
return;
}
writer.WriteObject(ObjectEncoding.AMF0, data);
}
示例8: WriteData
public void WriteData(AMFWriter writer, object data)
{
writer.WriteByte(AMF0TypeCode.String);
writer.WriteUTF( new String( (char)data, 1) );
}
示例9: WriteData
public void WriteData(AMFWriter writer, object data) {
writer.WriteByte(AMF3TypeCode.Object);
writer.WriteAMF3Object(data);
}
示例10: WriteData
public void WriteData(AMFWriter writer, object data)
{
writer.WriteAMF3String(data as string);
}
示例11: WriteData
public void WriteData(AMFWriter writer, object data)
{
writer.WriteByte(AMF0TypeCode.Number);
double dbl = (double)Convert.ToInt32(data);
writer.WriteDouble(dbl);
}
示例12: Serialize
public void Serialize(AMFWriter writer)
{
writer.WriteString(this.Name);
writer.WriteString(this.Path);
writer.WriteData(ObjectEncoding.AMF0, _attributes);
}
示例13: ByteArray
/// <summary>
/// Initializes a new instance of the ByteArray class.
/// </summary>
/// <param name="buffer">The array of unsigned bytes from which to create the current ByteArray.</param>
public ByteArray(byte[] buffer)
{
_memoryStream = new MemoryStream();
_memoryStream.Write(buffer, 0, buffer.Length);
_memoryStream.Position = 0;
AMFReader amfReader = new AMFReader(_memoryStream);
AMFWriter amfWriter = new AMFWriter(_memoryStream);
_dataOutput = new DataOutput(amfWriter);
_dataInput = new DataInput(amfReader);
_objectEncoding = ObjectEncoding.AMF3;
}
示例14: InjectMetaData
/// <summary>
/// Injects metadata (other than Cue points) into a tag.
/// </summary>
/// <param name="meta">Metadata.</param>
/// <param name="tag">Tag.</param>
/// <returns></returns>
private ITag InjectMetaData(MetaData meta, ITag tag) {
MemoryStream ms = new MemoryStream();
AMFWriter writer = new AMFWriter(ms);
writer.WriteData(ObjectEncoding.AMF0, "onMetaData");
writer.WriteData(ObjectEncoding.AMF0, meta);
byte[] buffer = ms.ToArray();
return new Tag(IOConstants.TYPE_METADATA, 0, buffer.Length, buffer, tag.PreviousTagSize);
}
示例15: WriteData
public void WriteData(AMFWriter writer, object data)
{
int value = Convert.ToInt32(data);
writer.WriteAMF3Int(value);
}