private static void EncodeSharedObject(RtmpContext context, ISharedObjectMessage so, ByteBuffer output) { RtmpWriter writer = new RtmpWriter(output); writer.WriteUTF(so.Name); writer.WriteInt32(so.Version); writer.WriteInt32(so.IsPersistent ? 2 : 0); writer.WriteInt32(0); int num2 = 0; foreach (ISharedObjectEvent event2 in so.Events) { int position; byte num3 = SharedObjectTypeMapping.ToByte(event2.Type); switch (event2.Type) { case SharedObjectEventType.SERVER_CONNECT: case SharedObjectEventType.CLIENT_CLEAR_DATA: case SharedObjectEventType.CLIENT_INITIAL_DATA: { writer.WriteByte(num3); writer.WriteInt32(0); continue; } case SharedObjectEventType.SERVER_DISCONNECT: { writer.WriteByte(num3); output.PutInt((int)output.Position, 0); continue; } case SharedObjectEventType.SERVER_SET_ATTRIBUTE: case SharedObjectEventType.CLIENT_UPDATE_DATA: { if (event2.Key != null) { break; } IDictionary dictionary = event2.Value as IDictionary; foreach (DictionaryEntry entry in dictionary) { writer.WriteByte(num3); position = (int)output.Position; output.Skip(4); string key = entry.Key as string; object data = entry.Value; writer.WriteUTF(key); writer.WriteData(context.ObjectEncoding, data); num2 = (((int)output.Position) - position) - 4; output.PutInt(position, num2); } continue; } case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE: case SharedObjectEventType.CLIENT_DELETE_DATA: case SharedObjectEventType.CLIENT_UPDATE_ATTRIBUTE: { writer.WriteByte(num3); position = (int)output.Position; output.Skip(4); writer.WriteUTF(event2.Key); num2 = (((int)output.Position) - position) - 4; output.PutInt(position, num2); continue; } case SharedObjectEventType.SERVER_SEND_MESSAGE: case SharedObjectEventType.CLIENT_SEND_MESSAGE: { writer.WriteByte(num3); position = (int)output.Position; output.Skip(4); writer.WriteData(context.ObjectEncoding, event2.Key); foreach (object obj3 in event2.Value as IList) { writer.WriteData(context.ObjectEncoding, obj3); } num2 = (((int)output.Position) - position) - 4; output.PutInt(position, num2); continue; } case SharedObjectEventType.CLIENT_STATUS: { writer.WriteByte(num3); position = (int)output.Position; output.Skip(4); writer.WriteUTF(event2.Key); writer.WriteUTF(event2.Value as string); num2 = (((int)output.Position) - position) - 4; output.PutInt(position, num2); continue; } default: goto Label_033A; } writer.WriteByte(num3); position = (int)output.Position; output.Skip(4); writer.WriteUTF(event2.Key); writer.WriteData(context.ObjectEncoding, event2.Value); num2 = (((int)output.Position) - position) - 4; output.PutInt(position, num2); continue; Label_033A: _log.Error("Unknown event " + event2.Type.ToString()); writer.WriteByte(num3); position = (int)output.Position; output.Skip(4); if (event2.Key != null) { writer.WriteUTF(event2.Key); writer.WriteData(context.ObjectEncoding, event2.Value); } num2 = (((int)output.Position) - position) - 4; output.PutInt(position, num2); } }
static void EncodeSharedObject(RtmpContext context, ISharedObjectMessage so, ByteBuffer output) { RtmpWriter writer = new RtmpWriter(output); //Set legacy collection flag from context writer.UseLegacyCollection = context.UseLegacyCollection; writer.UseLegacyThrowable = context.UseLegacyThrowable; writer.WriteUTF(so.Name); // SO version writer.WriteInt32(so.Version); // Encoding (this always seems to be 2 for persistent shared objects) writer.WriteInt32(so.IsPersistent ? 2 : 0); // unknown field writer.WriteInt32(0); int mark, len = 0; foreach(ISharedObjectEvent sharedObjectEvent in so.Events) { byte type = SharedObjectTypeMapping.ToByte(sharedObjectEvent.Type); switch(sharedObjectEvent.Type) { case SharedObjectEventType.SERVER_CONNECT: case SharedObjectEventType.CLIENT_INITIAL_DATA: case SharedObjectEventType.CLIENT_CLEAR_DATA: writer.WriteByte(type); writer.WriteInt32(0); break; case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE: case SharedObjectEventType.CLIENT_DELETE_DATA: case SharedObjectEventType.CLIENT_UPDATE_ATTRIBUTE: writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back writer.WriteUTF(sharedObjectEvent.Key); len = (int)output.Position - mark - 4; output.PutInt(mark, len); break; case SharedObjectEventType.SERVER_SET_ATTRIBUTE: case SharedObjectEventType.CLIENT_UPDATE_DATA: if (sharedObjectEvent.Key == null) { // Update multiple attributes in one request IDictionary initialData = sharedObjectEvent.Value as IDictionary; foreach(DictionaryEntry entry in initialData) { writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back string key = entry.Key as string; object value = entry.Value; writer.WriteUTF(key); writer.WriteData(context.ObjectEncoding, value); len = (int)output.Position - mark - 4; output.PutInt(mark, len); } } else { writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back writer.WriteUTF(sharedObjectEvent.Key); writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Value); //writer.WriteData(sharedObjectEvent.Value); len = (int)output.Position - mark - 4; output.PutInt(mark, len); } break; case SharedObjectEventType.CLIENT_SEND_MESSAGE: case SharedObjectEventType.SERVER_SEND_MESSAGE: // Send method name and value writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back // Serialize name of the handler to call writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Key); //writer.WriteUTF(sharedObjectEvent.Key); // Serialize the arguments foreach(object arg in sharedObjectEvent.Value as IList) { writer.WriteData(context.ObjectEncoding, arg); } //writer.WriteData(sharedObjectEvent.Value as IList); len = (int)output.Position - mark - 4; //output.PutInt(mark, len); output.PutInt(mark, len); break; case SharedObjectEventType.CLIENT_STATUS: writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back writer.WriteUTF(sharedObjectEvent.Key); writer.WriteUTF(sharedObjectEvent.Value as string); len = (int)output.Position - mark - 4; output.PutInt(mark, len); break; case SharedObjectEventType.SERVER_DISCONNECT: writer.WriteByte(type); output.PutInt((int)output.Position, 0); break; default: #if !SILVERLIGHT _log.Error("Unknown event " + sharedObjectEvent.Type.ToString()); #endif writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back if (sharedObjectEvent.Key != null) { writer.WriteUTF(sharedObjectEvent.Key); writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Value); } len = (int)output.Position - mark - 4; output.PutInt(mark, len); break; } } }
static void EncodeSharedObject(RtmpContext context, ISharedObjectMessage so, ByteBuffer output) { RtmpWriter writer = new RtmpWriter(output); //Set legacy collection flag from context writer.UseLegacyCollection = context.UseLegacyCollection; writer.UseLegacyThrowable = context.UseLegacyThrowable; writer.WriteUTF(so.Name); // SO version writer.WriteInt32(so.Version); // Encoding (this always seems to be 2 for persistent shared objects) writer.WriteInt32(so.IsPersistent ? 2 : 0); // unknown field writer.WriteInt32(0); int mark, len = 0; foreach (ISharedObjectEvent sharedObjectEvent in so.Events) { byte type = SharedObjectTypeMapping.ToByte(sharedObjectEvent.Type); switch (sharedObjectEvent.Type) { case SharedObjectEventType.SERVER_CONNECT: case SharedObjectEventType.CLIENT_INITIAL_DATA: case SharedObjectEventType.CLIENT_CLEAR_DATA: writer.WriteByte(type); writer.WriteInt32(0); break; case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE: case SharedObjectEventType.CLIENT_DELETE_DATA: case SharedObjectEventType.CLIENT_UPDATE_ATTRIBUTE: writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back writer.WriteUTF(sharedObjectEvent.Key); len = (int)output.Position - mark - 4; output.PutInt(mark, len); break; case SharedObjectEventType.SERVER_SET_ATTRIBUTE: case SharedObjectEventType.CLIENT_UPDATE_DATA: if (sharedObjectEvent.Key == null) { // Update multiple attributes in one request IDictionary initialData = sharedObjectEvent.Value as IDictionary; foreach (DictionaryEntry entry in initialData) { writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back string key = entry.Key as string; object value = entry.Value; writer.WriteUTF(key); writer.WriteData(context.ObjectEncoding, value); len = (int)output.Position - mark - 4; output.PutInt(mark, len); } } else { writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back writer.WriteUTF(sharedObjectEvent.Key); writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Value); //writer.WriteData(sharedObjectEvent.Value); len = (int)output.Position - mark - 4; output.PutInt(mark, len); } break; case SharedObjectEventType.CLIENT_SEND_MESSAGE: case SharedObjectEventType.SERVER_SEND_MESSAGE: // Send method name and value writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back // Serialize name of the handler to call writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Key); //writer.WriteUTF(sharedObjectEvent.Key); // Serialize the arguments foreach (object arg in sharedObjectEvent.Value as IList) { writer.WriteData(context.ObjectEncoding, arg); } //writer.WriteData(sharedObjectEvent.Value as IList); len = (int)output.Position - mark - 4; //output.PutInt(mark, len); output.PutInt(mark, len); break; case SharedObjectEventType.CLIENT_STATUS: writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back writer.WriteUTF(sharedObjectEvent.Key); writer.WriteUTF(sharedObjectEvent.Value as string); len = (int)output.Position - mark - 4; output.PutInt(mark, len); break; case SharedObjectEventType.SERVER_DISCONNECT: writer.WriteByte(type); output.PutInt((int)output.Position, 0); break; default: #if !SILVERLIGHT _log.Error("Unknown event " + sharedObjectEvent.Type.ToString()); #endif writer.WriteByte(type); mark = (int)output.Position; output.Skip(4); // we will be back if (sharedObjectEvent.Key != null) { writer.WriteUTF(sharedObjectEvent.Key); writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Value); } len = (int)output.Position - mark - 4; output.PutInt(mark, len); break; } } }