コード例 #1
0
 public void Serialize(System.IO.Stream s)
 {
     s.WriteInt32(Items.Count.Swap());
     foreach (var item in Items)
     {
         HydraUtf8String keyString = new HydraUtf8String(item.Key);
         s.WriteUInt8((byte)HydraDataType.Utf8String);
         keyString.Serialize(s);
         s.WriteUInt8((byte)item.Value.DataType);
         item.Value.Serialize(s);
     }
 }
コード例 #2
0
        public void Deserialize(System.IO.Stream s)
        {
            int itemCount = s.ReadInt32().Swap();

            for (int i = 0; i < itemCount; i++)
            {
                IHydraItem key = HydraItemDeserializer.Deserialize(s);
                if (!(key is HydraUtf8String))
                {
                    throw new NotImplementedException();
                }
                HydraUtf8String stringKey = key as HydraUtf8String;

                IHydraItem value = HydraItemDeserializer.Deserialize(s);

                Items.Add(stringKey.Value, value);
            }
        }
コード例 #3
0
        public static IHydraItem Deserialize(Stream s)
        {
            HydraDataType type = (HydraDataType)s.ReadUInt8();

            switch (type)
            {
            case HydraDataType.None:
            {
                HydraNone hNone = new HydraNone();
                hNone.Deserialize(s);
                return(hNone);
            }

            case HydraDataType.Int32:
            {
                HydraInt32 hInt32 = new HydraInt32();
                hInt32.Deserialize(s);
                return(hInt32);
            }

            case HydraDataType.Binary:
            {
                HydraBinary hBinary = new HydraBinary();
                hBinary.Deserialize(s);
                return(hBinary);
            }

            case HydraDataType.Bool:
            {
                HydraBool hBool = new HydraBool();
                hBool.Deserialize(s);
                return(hBool);
            }

            case HydraDataType.Float64:
            {
                HydraFloat64 hFloat64 = new HydraFloat64();
                hFloat64.Deserialize(s);
                return(hFloat64);
            }

            case HydraDataType.DateTime:
            {
                HydraDateTime hDateTime = new HydraDateTime();
                hDateTime.Deserialize(s);
                return(hDateTime);
            }

            case HydraDataType.Array:
            {
                HydraArray hArray = new HydraArray();
                hArray.Deserialize(s);
                return(hArray);
            }

            case HydraDataType.Int64:
            {
                HydraInt64 hInt64 = new HydraInt64();
                hInt64.Deserialize(s);
                return(hInt64);
            }

            case HydraDataType.Hashmap:
            {
                HydraHashMap hHashMap = new HydraHashMap();
                hHashMap.Deserialize(s);
                return(hHashMap);
            }

            case HydraDataType.Utf8String:
            {
                HydraUtf8String hUtf8String = new HydraUtf8String();
                hUtf8String.Deserialize(s);
                return(hUtf8String);
            }

            default:
                throw new NotImplementedException(String.Format("Deserialization for {0} is not implemented!", type));
            }
        }