public void TestLeft() { const int value = int.MaxValue; var leftVal = Either <int, string> .Left(value); var serialized = rw.serialize(leftVal); checkWithNoise(rw, serialized, leftVal); }
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() ))); }
public void TestTpl() { var t = F.t(1, "foo"); var serialized = rw.serialize(t); checkWithNoise(rw, serialized, t); }
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));
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 );
public void TestEmpty() { var s = ""; checkWithNoise(rw, rw.serialize(s), s); }
public void Test() { const byte value = 8; checkWithNoise(rw, rw.serialize(value), value); }
public void TestNone() { var serialized = rw.serialize(Option <int> .None); checkWithNoise(rw, serialized, Option <int> .None); }
public void Test() { var value = Guid.NewGuid(); checkWithNoise(rw, rw.serialize(value), value); }
public static A clone <A>(this A a, ISerializedRW <A> rw) { var bytes = rw.serialize(a).toArray(); return(rw.deserialize(bytes, 0).rightOrThrow.value); }
public Rope <byte> serialize(B b) => a1RW.serialize(getA1(b)) + a2RW.serialize(getA2(b)) + a3RW.serialize(getA3(b));
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);
public Rope <byte> serialize(Option <A> a) => a.isSome ? OptByteArrayRW.DISCRIMINATOR_SOME_ROPE + rw.serialize(a.get) : OptByteArrayRW.DISCRIMINATOR_NONE_ROPE;
public Rope <byte> serialize(Tpl <A, B> a) => aRW.serialize(a._1) + bRW.serialize(a._2);