public override object ReadValue(HessianReader reader, HessianContext context, Type objectType, byte initialOctet) { var builder = new StringBuilder(); int len = 0; while (Constants.BC_STRING_CHUNK == initialOctet) { len = reader.ReadUInt16(); builder.Append(reader.ReadString(len)); initialOctet = reader.ReadByte(); } if (0x00 <= initialOctet && initialOctet <= 0x1f) { len = initialOctet; } else if (0x30 <= initialOctet && initialOctet <= 0x34) { var b0 = reader.ReadByte(); len = ((initialOctet - 0x30) << 8) + b0; } else if (Constants.BC_STRING == initialOctet) { len = reader.ReadUInt16(); } else { throw Exceptions.UnExpectedInitialOctet(this, initialOctet); } builder.Append(reader.ReadString(len)); return(builder.ToString()); }
public override object ReadValue(HessianReader reader, HessianContext context, Type objectType, byte initialOctet) { using (var stream = new MemoryStream()) { while (initialOctet == Constants.BC_BINARY_CHUNK) { int len = reader.ReadInt16(); FillBuffer(reader, stream, len); initialOctet = reader.ReadByte(); } if (initialOctet == Constants.BC_BINARY) { int len = reader.ReadInt16(); FillBuffer(reader, stream, len); } else if (Constants.BC_BINARY_DIRECT <= initialOctet && initialOctet <= Constants.BC_BINARY_DIRECT + Constants.BINARY_DIRECT_MAX) { FillBuffer(reader, stream, initialOctet - Constants.BC_BINARY_DIRECT); } else { throw Exceptions.UnExpectedInitialOctet(this, initialOctet); } return(stream.ToArray()); } }
public override object ReadValue(HessianReader reader, HessianContext context, Type objectType, byte initialOctet) { if (0x80 <= initialOctet && initialOctet <= 0xbf) { return(initialOctet - 0x90); } else if (0xc0 <= initialOctet && initialOctet <= 0xcf) { var b0 = reader.ReadByte(); return(((initialOctet - 0xc8) << 8) + b0); } else if (0xd0 <= initialOctet && initialOctet <= 0xd7) { var s = reader.ReadUInt16(); return(((initialOctet - 0xd4) << 16) + s); } else if (Constants.BC_INT == initialOctet) { return(reader.ReadInt32()); } else { throw Exceptions.UnExpectedInitialOctet(this, initialOctet); } }
public override object ReadValue(HessianReader reader, HessianContext context, Type objectType, byte initialOctet) { if (0xd8 <= initialOctet && initialOctet <= 0xef) { return((long)(initialOctet - 0xe0)); } else if (0xf0 <= initialOctet && initialOctet <= 0xff) { var b0 = reader.ReadByte(); return((long)(((initialOctet - 0xf8) << 8) + b0)); } else if (0x38 <= initialOctet && initialOctet <= 0x3f) { var s = reader.ReadUInt16(); return((long)(((initialOctet - 0x3c) << 16) + s)); } else if (Constants.BC_LONG_INT == initialOctet) { return((long)reader.ReadInt32()); } else if (Constants.BC_LONG == initialOctet) { return(reader.ReadInt64()); } else { throw Exceptions.UnExpectedInitialOctet(this, initialOctet); } }
public virtual object ReadValue(HessianReader reader, HessianContext context, Type objectType) { var initialOctet = reader.ReadByte(); if (initialOctet == Constants.BC_NULL) { return(null); } return(ReadValue(reader, context, objectType, initialOctet)); }
public override object ReadValueNotExisted(HessianReader reader, HessianContext context, Type objectType, byte initialOctet) { if (Constants.BC_MAP_UNTYPED == initialOctet) { var dict = new Dictionary <object, object>(); context.ValueRefs.AddItem(dict); initialOctet = reader.ReadByte(); while (Constants.BC_END != initialOctet) { var key = AutoConverter.ReadValue(reader, context, typeof(object), initialOctet); var value = AutoConverter.ReadValue(reader, context, typeof(object)); dict.Add(key, value); initialOctet = reader.ReadByte(); } return(dict); } else { throw Exceptions.UnExpectedInitialOctet(this, initialOctet); } }
public override object ReadValueNotExisted(HessianReader reader, HessianContext context, Type objectType, byte initialOctet) { Type listType = null; Type elementType = null; HessianConverter itemConverter = null; if (Constants.BC_LIST_VARIABLE_UNTYPED == initialOctet) { listType = typeof(List <object>); elementType = typeof(object); itemConverter = AutoConverter; } else if (Constants.BC_LIST_VARIABLE == initialOctet) { listType = (Type)TypeConverter.ReadValue(reader, context, null); elementType = listType.GenericTypeArguments[0]; itemConverter = AutoConverter.GetConverter(elementType); } else { throw Exceptions.UnExpectedInitialOctet(this, initialOctet); } var addMethod = listType.GetMethod("Add"); var list = Activator.CreateInstance(listType); context.ValueRefs.AddItem(list); initialOctet = reader.ReadByte(); var parameters = new object[1]; while (Constants.BC_END != initialOctet) { parameters[0] = itemConverter.ReadValue(reader, context, elementType, initialOctet); addMethod.Invoke(list, parameters); initialOctet = reader.ReadByte(); } return(list); }
public override object ReadValueNotExisted(HessianReader reader, HessianContext context, Type objectType, byte initialOctet) { if (ClassDefinitionConverter.CanRead(initialOctet)) { ClassDefinitionConverter.ReadValue(reader, context, typeof(ClassDefinition), initialOctet); initialOctet = reader.ReadByte(); } int definitionIndex = 0; if (0x60 <= initialOctet && initialOctet <= 0x6f) { definitionIndex = initialOctet - Constants.BC_OBJECT_DIRECT; } else if (Constants.BC_OBJECT == initialOctet) { definitionIndex = (int)IntConverter.ReadValue(reader, context, typeof(int)); } var definition = context.ClassRefs.GetItem(definitionIndex); object value = null; if (definition.Type.IsEnum) { definition.VisitFields(field => { var fieldValue = AutoConverter.ReadValue(reader, context, field.Type); if (field.Name == "name") { value = Enum.Parse(definition.Type, (string)fieldValue); context.ValueRefs.AddItem(value); } }); } else { value = Activator.CreateInstance(definition.Type); context.ValueRefs.AddItem(value); definition.VisitFields(field => { var fieldValue = AutoConverter.ReadValue(reader, context, field.Type); field.Setter(value, fieldValue); }); } return(value); }