Exemple #1
0
        public IEnumerable <byte> Pack(object obj)
        {
            // use f*********r then add tlv stuff
            var packedInnerObject = packer.Pack(obj);

            var tlvAttribute = ((TlvAttribute)obj.GetType().GetCustomAttributes(typeof(TlvAttribute), false)[0]);
            var packedType   = FudgeFactory.Packer(tlvAttribute.TypeLength).Pack(Convert.ChangeType(tlvAttribute.Type, tlvAttribute.TypeLength));
            var packedSize   = FudgeFactory.Packer(tlvAttribute.SizeLength).Pack(Convert.ChangeType(packedInnerObject.Count(), tlvAttribute.SizeLength));

            return(packedType.Concat(packedSize).Concat(packedInnerObject));
        }
Exemple #2
0
        public object Unpack(Type type, Stream data)
        {
            // strip tlv stuff and use f*********r
            var tlvAttribute = ((TlvAttribute)type.GetCustomAttributes(typeof(TlvAttribute), false)[0]);

            var typeDef = FudgeFactory.Packer(tlvAttribute.TypeLength).Unpack(tlvAttribute.TypeLength, data);
            var size    = FudgeFactory.Packer(tlvAttribute.SizeLength).Unpack(tlvAttribute.SizeLength, data);

            var innerObject = packer.Unpack(type, data);

            return(innerObject);
        }
Exemple #3
0
 object UnpackField(FieldInfo field, Stream stream)
 {
     return(FudgeFactory.Packer(field.FieldType).Unpack(field.FieldType, stream));
 }
Exemple #4
0
        IEnumerable <byte> PackField(object obj, FieldInfo field)
        {
            dynamic data = field.GetValue(obj);

            return(FudgeFactory.Packer(field.FieldType).Pack(data));
        }