/// <summary> /// Set property value. /// </summary> /// <param name="index">Zero-based property index.</param> /// <param name="value">Value</param> /// <returns>Indicator when the property is set.</returns> protected internal AsyncReply <object> _Set(byte index, object value) { if (index >= properties.Length) { return(null); } var reply = new AsyncReply <object>(); var parameters = Codec.Compose(value, connection); connection.SendRequest(Packets.IIPPacket.IIPPacketAction.SetProperty) .AddUInt32(instanceId) .AddUInt8(index) .AddUInt8Array(parameters) .Done() .Then((res) => { // not really needed, server will always send property modified, // this only happens if the programmer forgot to emit in property setter properties[index] = value; reply.Trigger(null); }); return(reply); }
public override byte[] Compose() { var name = base.Compose(); var hdr = Inherited ? (byte)0x80 : (byte)0; if (Annotation != null) { var exp = DC.ToBytes(Annotation); hdr |= 0x70; return(new BinaryList() .AddUInt8(hdr) .AddUInt8((byte)name.Length) .AddUInt8Array(name) .AddUInt8Array(ValueType.Compose()) .AddUInt8Array(Codec.Compose(Value, null)) .AddInt32(exp.Length) .AddUInt8Array(exp) .ToArray()); } else { hdr |= 0x60; return(new BinaryList() .AddUInt8(hdr) .AddUInt8((byte)name.Length) .AddUInt8Array(name) .AddUInt8Array(ValueType.Compose()) .AddUInt8Array(Codec.Compose(Value, null)) .ToArray()); } }
public static byte[] ArrayComposer(IEnumerable value, DistributedConnection connection) { if (value == null) { return(null); } var rt = new List <byte>(); foreach (var i in value) { rt.AddRange(Codec.Compose(i, connection)); } return(rt.ToArray()); }
public static unsafe (TransmissionTypeIdentifier, byte[]) MapComposer(object value, DistributedConnection connection) { if (value == null) { return(TransmissionTypeIdentifier.Null, new byte[0]); } var rt = new List <byte>(); var map = (IMap)value; foreach (var el in map.Serialize()) { rt.AddRange(Codec.Compose(el, connection)); } return(TransmissionTypeIdentifier.Map, rt.ToArray()); }
public static unsafe (TransmissionTypeIdentifier, byte[]) RecordComposer(object value, DistributedConnection connection) { var rt = new List <byte>();// BinaryList(); var record = (IRecord)value; var template = Warehouse.GetTemplateByType(record.GetType()); rt.AddRange(template.ClassId.ToByteArray()); foreach (var pt in template.Properties) { var propValue = pt.PropertyInfo.GetValue(record, null); rt.AddRange(Codec.Compose(propValue, connection)); } return(TransmissionTypeIdentifier.Record, rt.ToArray()); }
public static byte[] HistoryComposer(KeyList <PropertyTemplate, PropertyValue[]> history, DistributedConnection connection, bool prependLength = false) { //@TODO:Test var rt = new BinaryList(); for (var i = 0; i < history.Count; i++) { rt.AddUInt8(history.Keys.ElementAt(i).Index) .AddUInt8Array(Codec.Compose(history.Values.ElementAt(i), connection)); } if (prependLength) { rt.InsertInt32(0, rt.Length); } return(rt.ToArray()); }
//public static byte[] PropertyValueComposer(PropertyValue propertyValue, DistributedConnection connection)//, bool includeAge = true) //{ // var rt = new BinaryList(); // return // .AddUInt64(propertyValue.Age) // .AddDateTime(propertyValue.Date) // .AddUInt8Array(Codec.Compose(propertyValue.Value, connection)) // .ToArray(); //} public static (TransmissionTypeIdentifier, byte[]) PropertyValueArrayComposer(object value, DistributedConnection connection) { if (value == null) { return(TransmissionTypeIdentifier.Null, new byte[0]); } var rt = new List <byte>(); var ar = value as PropertyValue[]; foreach (var pv in ar) { rt.AddRange(Codec.Compose(pv.Age, connection)); rt.AddRange(Codec.Compose(pv.Date, connection)); rt.AddRange(Codec.Compose(pv.Value, connection)); } return(TransmissionTypeIdentifier.List, rt.ToArray()); }
public static (TransmissionTypeIdentifier, byte[]) TypedMapComposer(object value, Type keyType, Type valueType, DistributedConnection connection) { if (value == null) { return(TransmissionTypeIdentifier.Null, new byte[0]); } var kt = RepresentationType.FromType(keyType).Compose(); var vt = RepresentationType.FromType(valueType).Compose(); var rt = new List <byte>(); rt.AddRange(kt); rt.AddRange(vt); var map = (IMap)value; foreach (var el in map.Serialize()) { rt.AddRange(Codec.Compose(el, connection)); } return(TransmissionTypeIdentifier.TypedMap, rt.ToArray()); }