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));
        }
        // TODO: It would be AWESOME if we could just store this class directly, but
        // unfortunately, Bond's type aliases allow only primitive types to be aliased.
        // We should check to see if we can add support for custom types in Bond's source,
        // but for now, we're forced to do a double serialization here.
        public static ArraySegment <byte> ToByteArray(IGenericSerializable Serializable)
        {
            if (Serializable == null)
            {
                return(default(ArraySegment <byte>));
            }

            var Type   = Serializable.GetType();
            var Result = new SerializationGenericReference(0)
            {
                Type = BondSerializationUtil.GetTypeIdentifierString(Type),
                Data = BondSerializer.Serialize(Serializable)
            };

            return(BondSerializer.Serialize(Result));
        }
Exemplo n.º 3
0
 public byte[] Serialize(object Object)
 {
     return(BondSerializer.Serialize(Object).ToArray());
 }