Esempio n. 1
0
            public static Option <DeserializeInfo <B> > deserialize(
                IDeserializer <A> aDeserializer, Fn <A, Option <B> > mapper,
                byte[] serialized, int startIndex
                )
            {
                var aInfoOpt = aDeserializer.deserialize(serialized, startIndex);

                if (aInfoOpt.isNone)
                {
                    return(Option <DeserializeInfo <B> > .None);
                }
                var aInfo = aInfoOpt.get;
                var bOpt  = mapper(aInfo.value);

                if (bOpt.isNone)
                {
                    return(Option <DeserializeInfo <B> > .None);
                }
                var bInfo = new DeserializeInfo <B>(bOpt.get, aInfo.bytesRead);

                return(F.some(bInfo));
            }
Esempio n. 2
0
 public Option <DeserializeInfo <Tpl <A, B> > > deserialize(byte[] serialized, int startIndex)
 {
     try {
         var aOpt = aRW.deserialize(serialized, startIndex);
         if (aOpt.isNone)
         {
             return(Option <DeserializeInfo <Tpl <A, B> > > .None);
         }
         var aInfo = aOpt.get;
         var bOpt  = bRW.deserialize(serialized, startIndex + aInfo.bytesRead);
         if (bOpt.isNone)
         {
             return(Option <DeserializeInfo <Tpl <A, B> > > .None);
         }
         var bInfo = bOpt.get;
         var info  = new DeserializeInfo <Tpl <A, B> >(
             F.t(aInfo.value, bInfo.value),
             aInfo.bytesRead + bInfo.bytesRead
             );
         return(F.some(info));
     }
     catch (Exception) { return(Option <DeserializeInfo <Tpl <A, B> > > .None); }
 }
Esempio n. 3
0
 static A valueFromInfo <A>(DeserializeInfo <A> info, int serializedLength)
 {
     info.bytesRead.shouldEqual(serializedLength);
     return(info.value);
 }