public static ClaimantV0 Decode(XdrDataInputStream stream)
            {
                ClaimantV0 decodedClaimantV0 = new ClaimantV0();

                decodedClaimantV0.Destination = AccountID.Decode(stream);
                decodedClaimantV0.Predicate   = ClaimPredicate.Decode(stream);
                return(decodedClaimantV0);
            }
        public static ClaimPredicate Decode(XdrDataInputStream stream)
        {
            ClaimPredicate     decodedClaimPredicate = new ClaimPredicate();
            ClaimPredicateType discriminant          = ClaimPredicateType.Decode(stream);

            decodedClaimPredicate.Discriminant = discriminant;
            switch (decodedClaimPredicate.Discriminant.InnerValue)
            {
            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_UNCONDITIONAL:
                break;

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_AND:
                int andPredicatessize = stream.ReadInt();
                decodedClaimPredicate.AndPredicates = new ClaimPredicate[andPredicatessize];
                for (int i = 0; i < andPredicatessize; i++)
                {
                    decodedClaimPredicate.AndPredicates[i] = ClaimPredicate.Decode(stream);
                }
                break;

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_OR:
                int orPredicatessize = stream.ReadInt();
                decodedClaimPredicate.OrPredicates = new ClaimPredicate[orPredicatessize];
                for (int i = 0; i < orPredicatessize; i++)
                {
                    decodedClaimPredicate.OrPredicates[i] = ClaimPredicate.Decode(stream);
                }
                break;

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_NOT:
                int NotPredicatePresent = stream.ReadInt();
                if (NotPredicatePresent != 0)
                {
                    decodedClaimPredicate.NotPredicate = ClaimPredicate.Decode(stream);
                }
                break;

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_BEFORE_ABSOLUTE_TIME:
                decodedClaimPredicate.AbsBefore = Int64.Decode(stream);
                break;

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_BEFORE_RELATIVE_TIME:
                decodedClaimPredicate.RelBefore = Int64.Decode(stream);
                break;
            }
            return(decodedClaimPredicate);
        }
        public static void Encode(XdrDataOutputStream stream, ClaimPredicate encodedClaimPredicate)
        {
            stream.WriteInt((int)encodedClaimPredicate.Discriminant.InnerValue);
            switch (encodedClaimPredicate.Discriminant.InnerValue)
            {
            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_UNCONDITIONAL:
                break;

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_AND:
                int andPredicatessize = encodedClaimPredicate.AndPredicates.Length;
                stream.WriteInt(andPredicatessize);
                for (int i = 0; i < andPredicatessize; i++)
                {
                    ClaimPredicate.Encode(stream, encodedClaimPredicate.AndPredicates[i]);
                }
                break;

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_OR:
                int orPredicatessize = encodedClaimPredicate.OrPredicates.Length;
                stream.WriteInt(orPredicatessize);
                for (int i = 0; i < orPredicatessize; i++)
                {
                    ClaimPredicate.Encode(stream, encodedClaimPredicate.OrPredicates[i]);
                }
                break;

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_NOT:
                if (encodedClaimPredicate.NotPredicate != null)
                {
                    stream.WriteInt(1);
                    ClaimPredicate.Encode(stream, encodedClaimPredicate.NotPredicate);
                }
                else
                {
                    stream.WriteInt(0);
                }
                break;

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_BEFORE_ABSOLUTE_TIME:
                Int64.Encode(stream, encodedClaimPredicate.AbsBefore);
                break;

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_BEFORE_RELATIVE_TIME:
                Int64.Encode(stream, encodedClaimPredicate.RelBefore);
                break;
            }
        }
Beispiel #4
0
        public static ClaimPredicate FromXdr(xdr.ClaimPredicate xdr)
        {
            switch (xdr.Discriminant.InnerValue)
            {
            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_OR:
                if (xdr.OrPredicates.Length != 2)
                {
                    throw new Exception("ClaimPredicate.OrPredicates expected to have length 2");
                }
                return(Or(ClaimPredicate.FromXdr(xdr.OrPredicates[0]), ClaimPredicate.FromXdr(xdr.OrPredicates[1])));

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_AND:
                if (xdr.AndPredicates.Length != 2)
                {
                    throw new Exception("ClaimPredicate.AndPredicates expected to have length 2");
                }
                return(And(ClaimPredicate.FromXdr(xdr.AndPredicates[0]), ClaimPredicate.FromXdr(xdr.AndPredicates[1])));

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_NOT:
                if (xdr.NotPredicate == null)
                {
                    throw new Exception("ClaimPredicate.NotPredicate expected to be not null");
                }
                return(Not(ClaimPredicate.FromXdr(xdr.NotPredicate)));

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_UNCONDITIONAL:
                return(Unconditional());

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_BEFORE_ABSOLUTE_TIME:
                return(BeforeAbsoluteTime(xdr.AbsBefore.InnerValue));

            case ClaimPredicateType.ClaimPredicateTypeEnum.CLAIM_PREDICATE_BEFORE_RELATIVE_TIME:
                return(BeforeRelativeTime(xdr.RelBefore.InnerValue));

            default:
                throw new Exception("Unknown claim predicate " + xdr.Discriminant.InnerValue);
            }
        }
 public static void Encode(XdrDataOutputStream stream, ClaimantV0 encodedClaimantV0)
 {
     AccountID.Encode(stream, encodedClaimantV0.Destination);
     ClaimPredicate.Encode(stream, encodedClaimantV0.Predicate);
 }