public static bool ExtendCustomType(Type type, byte bSign, BinDeserializeFunc func) { customTypeExtends[bSign] = new CustomType(type, bSign, null, func); return(true); }
public static bool ExtendCustomType(Type type, byte bSign, BinSerializeFunc func) { customTypeExtends[type] = new CustomType(type, bSign, func, null); return(true); }
public object Object() { byte c = this.Byte(); switch (c) { case Types.Byte: return(this.Byte()); case Types.Bool: return(this.Bool()); case Types.Short: return(this.Short()); case Types.Int: return(this.Int()); case Types.Long: return(this.Long()); case Types.String: return(this.String()); case Types.Float: return(this.Float()); case Types.Ints: return(this.Ints()); case Types.Array: return(this.Array()); case Types.Hash: return(this.Hash()); case Types.Null: if (this.Byte() == 0) { return(null); } break; case Types.Native: return(this.Native()); default: if (customTypeExtends.ContainsKey(c)) { CustomType custom = customTypeExtends[c]; if (custom.binDeserializeFunc != null) { return(custom.binDeserializeFunc(this)); } else { int length = this.Int(); object ret = customTypeExtends[c].deserializeFunc(this.buffer); this.offset += length; return(ret); } } return(null); } return(null); }
public void PushObject(object value) { if (value == null) { this.PushByte(Types.Null); this.PushByte((byte)0); return; } Type type = value.GetType(); if (type == typeof(byte)) { this.PushByte(Types.Byte); this.PushByte((byte)value); } else if (type == typeof(bool)) { this.PushByte(Types.Bool); this.PushBool((bool)value); } else if (type == typeof(short)) { this.PushByte(Types.Short); this.PushShort((short)value); } else if (type == typeof(int)) { this.PushByte(Types.Int); this.PushInt((int)value); } else if (type == typeof(long)) { this.PushByte(Types.Long); this.PushLong((long)value); } else if (type == typeof(string)) { this.PushByte(Types.String); this.PushString(value.ToString()); } else if (type == typeof(float)) { this.PushByte(Types.Float); this.PushFloat((float)value); } else if (value is Array) { if (type == typeof(int[])) { this.PushByte(Types.Ints); this.PushInts(value as int[]); } else { this.PushByte(Types.Array); this.PushArray(value as Array); } } else if (value is Dictionary <object, object> ) { this.PushByte(Types.Hash); this.PushHash(value as Dictionary <object, object>); } else if (value is Dictionary <int, int> ) { this.PushByte(Types.Hash); this.PushHash(value as Dictionary <int, int>); } else { if (customTypeExtends.ContainsKey(type)) { CustomType custom = customTypeExtends[type]; this.PushByte(custom.bSign); if (custom.binSerializeFunc != null) { custom.binSerializeFunc(this, value); } else { byte[] datas = custom.serializeFunc(value); this.PushInt(datas.Length); Buffer.BlockCopy(datas, 0, this.buffer, this.offset, datas.Length); this.offset += datas.Length; } } else { this.PushByte(Types.Native); this.PushNative(value); } } }