public RepositoryState deserialize(NetworkBuffer buffer) { int revisionNumber = buffer.parseInt32(COMMIT_OFFSET); RepositoryState state = new RepositoryState(revisionNumber); int numberOfBeliefs = buffer.parseInt32(NUM_BELIEFS_OFFSET); int baseOffset = HEADER_SIZE; for (int i = 0; i < numberOfBeliefs; ++i, baseOffset += BELIEF_SIZE) { int typeVal = buffer.readByte(baseOffset + TYPE_OFFSET); Belief.BeliefType type = Belief.BeliefType.INVALID; if (Enum.IsDefined(typeof(Belief.BeliefType), typeVal)) { type = (Belief.BeliefType)typeVal; } else { Log.error("Invalid belief type: " + typeVal); } int customType = buffer.parseInt32(baseOffset + CUSTOM_TYPE_OFFSET); int id = buffer.parseInt32(baseOffset + BELIEF_ID_OFFSET); byte[] digest = buffer.readBytes(baseOffset + DIGEST_OFFSET, DIGEST_SIZE); Hash hash = new Hash(digest); Belief.Key key = null; if (type == Belief.BeliefType.CUSTOM) { key = new Belief.Key(customType); } else { key = new Belief.Key(type); } state.Add(new CacheKey(key, id), hash); } return(state); }
public IEnumerable <BeliefType> FindAllBeliefs <BeliefType>(Belief.BeliefType type) where BeliefType : Belief { return(beliefRepo.FindAll <BeliefType>(type)); }
public BeliefType Find <BeliefType> (Belief.BeliefType type, int id) where BeliefType : Belief { return(beliefRepo.Find <BeliefType>(type, id)); }
SortedDictionary <int, Belief> lookup(Belief.BeliefType key, SortedDictionary <Belief.Key, SortedDictionary <int, Belief> > dictionary) { return(lookup(Belief.keyOf(key), dictionary)); }
public BeliefType Find <BeliefType>(Belief.BeliefType type, int id) where BeliefType : Belief { return(Find <BeliefType>(Belief.keyOf(type), id)); }
public IEnumerable <BeliefType> FindAll <BeliefType>(Belief.BeliefType type) where BeliefType : Belief { return(GetAllCachedBeliefs() .Where(belief => belief.GetBelief() as BeliefType != null && belief.GetBelief().getBeliefType() == type) .Select(cached => (BeliefType)cached.GetBelief())); }
private SortedDictionary <int, Belief> getBeliefsFor(Belief.BeliefType type) { return(getBeliefsFor(Belief.keyOf(type))); }