Ejemplo n.º 1
0
 public RepositoryState RegenerateState()
 {
     lock (this)
     {
         RepositoryState state = new RepositoryState(currentState.RevisionNumber() + 1);
         foreach (KeyValuePair <CacheKey, CachedBelief> entry in beliefCache)
         {
             state.Add(entry.Key, entry.Value.GetHash());
         }
         return(state);
     }
 }
Ejemplo n.º 2
0
        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);
        }