protected override void DoWrite(object obj, Hessian2Writer writer) { var type = obj.GetType(); if (!writer.WriteObjectHeader(type.AssemblyQualifiedName)) { writer.WriteInt(1); writer.WriteString("value"); writer.WriteObjectHeader(type.AssemblyQualifiedName); } writer.WriteString(obj.ToString()); }
protected override void DoWrite(object obj, Hessian2Writer writer) { var type = obj.GetType(); var name = Enum.GetName(type, obj); var nameAttr = type.GetCustomAttribute <NameAttribute>(); if (!writer.WriteObjectHeader(nameAttr == null ? type.AssemblyQualifiedName : nameAttr.TargetName)) { writer.WriteInt(1); writer.WriteString("name"); writer.WriteObjectHeader(type.AssemblyQualifiedName); } writer.WriteString(name); }
public static void EncodeRequest(Request request, Stream outputStream) { var header = new byte[HeaderLength]; header.WriteUShort(Magic); header[2] = RequestFlag | HessianSerialize; if (request.IsEvent) { header[2] |= EventFlag; } if (request.IsTwoWay) { header[2] |= TwowayFlag; } header.WriteLong(request.RequestId, 4); using (var dataStream = new PoolMemoryStream()) { var output = new Hessian2Writer(dataStream); if (request.IsEvent) { output.WriteNull(); } else { output.WriteString("2.0.0"); output.WriteObject(request.Service); output.WriteObject(request.Version); output.WriteObject(request.MethodName); output.WriteString(request.ParameterTypeInfo); if (request.Arguments != null && request.Arguments.Length > 0) { foreach (var arg in request.Arguments) { output.WriteObject(arg); } } output.WriteObject(request.Attachments); } header.WriteInt((int)dataStream.Length, 12); outputStream.Write(header, 0, header.Length); dataStream.CopyTo(outputStream); } }
protected override void DoWrite(object obj, Hessian2Writer writer) { if (!writer.WriteObjectHeader(_typeName)) { writer.WriteInt(_propertyInfos.Count); foreach (var key in _propertyInfos.Keys) { writer.WriteString(key); } writer.WriteObjectHeader(_typeName); } foreach (var fieldInfo in _propertyInfos.Values) { writer.WriteObject(fieldInfo.GetValue(obj)); } }
protected override void DoWrite(object obj, Hessian2Writer writer) { if (!writer.WriteObjectHeader(_typeName)) { writer.WriteInt(_fieldInfos.Length); foreach (var field in _fieldInfos) { writer.WriteString(field.Name); } writer.WriteObjectHeader(_typeName); } foreach (var fieldInfo in _fieldInfos) { writer.WriteObject(fieldInfo.GetValue(obj)); } }
public void WriteObject(object obj, Hessian2Writer writer) { if (IsRefrenceType(_type) && writer.WriteRef(obj)) { return; } switch (_type) { case BasicType.Null: writer.WriteNull(); break; case BasicType.Bool: writer.WriteBool((bool)obj); break; case BasicType.Byte: case BasicType.SByte: case BasicType.Short: case BasicType.UShort: case BasicType.Int: writer.WriteInt(Convert.ToInt32(obj)); break; case BasicType.UInt: case BasicType.Long: writer.WriteLong(Convert.ToInt64(obj)); break; case BasicType.Float: case BasicType.Double: writer.WriteDouble(Convert.ToDouble(obj)); break; case BasicType.Char: writer.WriteChars(new[] { (char)obj }); break; case BasicType.CharArray: writer.WriteChars((char[])obj); break; case BasicType.String: writer.WriteString(Convert.ToString(obj)); break; case BasicType.Date: writer.WriteDateTime(Convert.ToDateTime(obj)); break; case BasicType.Object: writer.WriteObject(obj); break; case BasicType.BoolArray: var boolArray = (bool[])obj; writer.WriteListStart(boolArray.Length, "[boolean"); foreach (var s in boolArray) { writer.WriteBool(s); } break; case BasicType.ShortArray: var shortArray = (short[])obj; writer.WriteListStart(shortArray.Length, "[short"); foreach (var s in shortArray) { writer.WriteInt(s); } break; case BasicType.IntArray: var intArray = (int[])obj; writer.WriteListStart(intArray.Length, "[int"); foreach (var s in intArray) { writer.WriteInt(s); } break; case BasicType.LongArray: var longArray = (long[])obj; writer.WriteListStart(longArray.Length, "[long"); foreach (var s in longArray) { writer.WriteLong(s); } break; case BasicType.FloatArray: var floatArray = (float[])obj; writer.WriteListStart(floatArray.Length, "[float"); foreach (var s in floatArray) { writer.WriteDouble(s); } break; case BasicType.DoubleArray: var doubleArray = (double[])obj; writer.WriteListStart(doubleArray.Length, "[double"); foreach (var s in doubleArray) { writer.WriteDouble(s); } break; case BasicType.StringArray: var stringArray = (string[])obj; writer.WriteListStart(stringArray.Length, "[string"); foreach (var s in stringArray) { writer.WriteString(s); } break; case BasicType.ByteArray: var byteArray = (byte[])obj; writer.WriteBytes(byteArray); break; case BasicType.SByteArray: var sbyteArray = (int[])obj; writer.WriteListStart(sbyteArray.Length, "[int"); foreach (var s in sbyteArray) { writer.WriteInt(s); } break; case BasicType.UShortArray: var ushortArray = (int[])obj; writer.WriteListStart(ushortArray.Length, "[int"); foreach (var s in ushortArray) { writer.WriteInt(s); } break; case BasicType.UIntArray: var uintArray = (uint[])obj; writer.WriteListStart(uintArray.Length, "[long"); foreach (var s in uintArray) { writer.WriteLong(s); } break; case BasicType.DateArray: var dateArray = (DateTime[])obj; writer.WriteListStart(dateArray.Length, "[date"); foreach (var item in dateArray) { writer.WriteDateTime(item); } break; case BasicType.ObjectArray: var objArray = (object[])obj; writer.WriteListStart(objArray.Length, "[object"); foreach (var item in objArray) { writer.WriteObject(item); } break; default: throw new ArgumentOutOfRangeException(); } }