Пример #1
0
        public void TestLeft()
        {
            const int value   = int.MaxValue;
            var       leftVal = Either <int, string> .Left(value);

            var serialized = rw.serialize(leftVal);

            checkWithNoise(rw, serialized, leftVal);
        }
Пример #2
0
 public static ICachedBlob <A> a <A>(
     ISerializedRW <A> rw, PathStr path, A defaultValue,
     ILog log = null, Log.Level onDeserializeFailureLogLevel = Log.Level.ERROR
     )
 {
     log = log ?? Log.d;
     return(new FileCachedBlob(path).bimap(BiMapper.a(
                                               (byte[] bytes) => {
         var deserializedOpt = rw.deserialize(bytes, 0);
         if (deserializedOpt.isNone)
         {
             if (log.willLog(onDeserializeFailureLogLevel))
             {
                 log.log(
                     onDeserializeFailureLogLevel,
                     $"Can't deserialize {path}, deleting and returning default value."
                     );
             }
             clear(path).getOrLog($"Couldn't clear file: '{path}'", log: log);
             return defaultValue;
         }
         return deserializedOpt.__unsafeGetValue.value;
     },
                                               a => rw.serialize(a).toArray()
                                               )));
 }
Пример #3
0
        public void TestTpl()
        {
            var t          = F.t(1, "foo");
            var serialized = rw.serialize(t);

            checkWithNoise(rw, serialized, t);
        }
Пример #4
0
 public Rope <byte> serialize(B b) =>
 a1RW.serialize(getA1(b))
 + a2RW.serialize(getA2(b))
 + a3RW.serialize(getA3(b))
 + a4RW.serialize(getA4(b))
 + a5RW.serialize(getA5(b))
 + a6RW.serialize(getA6(b));
Пример #5
0
 public static IPrefValueRW<A> custom<A>(
   ISerializedRW<A> aRW,
   PrefVal.OnDeserializeFailure onDeserializeFailure = PrefVal.OnDeserializeFailure.ReturnDefault,
   ILog log = null
 ) => custom(
   a => Convert.ToBase64String(aRW.serialize(a).toArray()),
   s => {
     try {
       var bytes = Convert.FromBase64String(s);
       return aRW.deserialize(bytes, 0).map(_ => _.value);
     }
     catch (FormatException) {
       return Option<A>.None;
     }
   },
   onDeserializeFailure,
   log
 );
Пример #6
0
        public void TestEmpty()
        {
            var s = "";

            checkWithNoise(rw, rw.serialize(s), s);
        }
Пример #7
0
        public void Test()
        {
            const byte value = 8;

            checkWithNoise(rw, rw.serialize(value), value);
        }
Пример #8
0
        public void TestNone()
        {
            var serialized = rw.serialize(Option <int> .None);

            checkWithNoise(rw, serialized, Option <int> .None);
        }
Пример #9
0
        public void Test()
        {
            var value = Guid.NewGuid();

            checkWithNoise(rw, rw.serialize(value), value);
        }
Пример #10
0
        public static A clone <A>(this A a, ISerializedRW <A> rw)
        {
            var bytes = rw.serialize(a).toArray();

            return(rw.deserialize(bytes, 0).rightOrThrow.value);
        }
Пример #11
0
 public Rope <byte> serialize(B b) =>
 a1RW.serialize(getA1(b)) + a2RW.serialize(getA2(b)) + a3RW.serialize(getA3(b));
Пример #12
0
     public Rope <byte> serialize(Either <A, B> either) =>
     either.isLeft
 ? EitherByteArrayRW.DISCRIMINATOR_LEFT_ROPE + aRW.serialize(either.__unsafeGetLeft)
 : EitherByteArrayRW.DISCRIMINATOR_RIGHT_ROPE + bRW.serialize(either.__unsafeGetRight);
Пример #13
0
     public Rope <byte> serialize(Option <A> a) =>
     a.isSome
 ? OptByteArrayRW.DISCRIMINATOR_SOME_ROPE + rw.serialize(a.get)
 : OptByteArrayRW.DISCRIMINATOR_NONE_ROPE;
Пример #14
0
 public Rope <byte> serialize(Tpl <A, B> a) =>
 aRW.serialize(a._1) + bRW.serialize(a._2);