public static ArraySegment <byte> ToByteArray(GrainReference GrainRef)
        {
            var KeyString = GrainRef.ToKeyString();
            var Ref       = new SerializationGrainReference(0);

            // Parse grain reference key string
            string grainIdStr;
            int    grainIdIndex = (GRAIN_REFERENCE_STR + "=").Length;

            int genericIndex      = KeyString.IndexOf(GENERIC_ARGUMENTS_STR + "=", StringComparison.Ordinal);
            int observerIndex     = KeyString.IndexOf(OBSERVER_ID_STR + "=", StringComparison.Ordinal);
            int systemTargetIndex = KeyString.IndexOf(SYSTEM_TARGET_STR + "=", StringComparison.Ordinal);

            if (genericIndex >= 0)
            {
                grainIdStr = KeyString.Substring(grainIdIndex, genericIndex - grainIdIndex).Trim();

                string genericStr = KeyString.Substring(genericIndex + (GENERIC_ARGUMENTS_STR + "=").Length);
                if (!String.IsNullOrEmpty(genericStr))
                {
                    Ref.GenericArgs = ParseAndConvertGenericArgsString(genericStr);
                }
            }
            else if (observerIndex >= 0)
            {
                grainIdStr = KeyString.Substring(grainIdIndex, observerIndex - grainIdIndex).Trim();

                string observerIdStr = KeyString.Substring(observerIndex + (OBSERVER_ID_STR + "=").Length);
                Ref.ObserverReferenceId = Guid.Parse(observerIdStr);
            }
            else if (systemTargetIndex >= 0)
            {
                grainIdStr = KeyString.Substring(grainIdIndex, systemTargetIndex - grainIdIndex).Trim();

                string systemTargetStr = KeyString.Substring(systemTargetIndex + (SYSTEM_TARGET_STR + "=").Length);
                Ref.SystemTargetSiloAddress = systemTargetStr;
            }
            else
            {
                grainIdStr = KeyString.Substring(grainIdIndex);
            }

            ParseGrainId(grainIdStr, out ulong n0, out ulong n1, out ulong typeCode, out string keyExt);
            Ref.IdN0         = n0;
            Ref.IdN1         = n1;
            Ref.TypeCodeData = typeCode;
            Ref.KeyExt       = keyExt;

            return(BondSerializer.Serialize(Ref));
        }
Example #2
0
 public byte[] GetKey(GrainReference GrainRef)
 {
     return(SerializationGrainReference.ToByteArray(GrainRef).ToArray());
 }
Example #3
0
 public GrainReference GetGrain(byte[] Key)
 {
     return(SerializationGrainReference.FromByteArray(new ArraySegment <byte>(Key), GrainReferenceConverter));
 }
Example #4
0
 public static IAddressable Convert(ArraySegment <byte> value, IAddressable unused, Type ExpectedType)
 {
     return((IAddressable)GetAsReferenceMethodInfo(ExpectedType).Invoke(null, new object[] { SerializationGrainReference.FromByteArray(value, GrainReferenceConverter) }));
 }