示例#1
0
        public int BinarySerialize(byte[] ioBuffer, int inOffset)
        {
            int offset = inOffset;

            offset = BinarySerializeUtils.Serialize((byte)VariantType, ioBuffer, offset);

            switch (VariantType)
            {
            case EValueType.Bool:
            case EValueType.Byte:
                offset = BinarySerializeUtils.Serialize((byte)_ulong_value1, ioBuffer, offset); break;

            case EValueType.Short:
            case EValueType.UShort:
                offset = BinarySerializeUtils.Serialize((ushort)_ulong_value1, ioBuffer, offset); break;

            case EValueType.Int:
            case EValueType.UInt:
            case EValueType.Float:
                offset = BinarySerializeUtils.Serialize((uint)_ulong_value1, ioBuffer, offset); break;

            case EValueType.Long:
            case EValueType.ULong:
            case EValueType.Double:
                offset = BinarySerializeUtils.Serialize(_ulong_value1, ioBuffer, offset); break;

            case EValueType.String:
                offset = BinarySerializeUtils.Serialize(ToString(), ioBuffer, offset); break;

            default: throw new ArgumentException($"Unknow type of value: {VariantType}");
            }

            return(offset);
        }
示例#2
0
        public int BinarySerialize(byte[] ioBuffer, int inOffset)
        {
            int offset = inOffset;

            offset = BinarySerializeUtils.Serialize(_name, ioBuffer, offset);

            offset = BinarySerializeUtils.Serialize(IsArray, ioBuffer, offset);

            if (_values.Count > ushort.MaxValue)
            {
                throw new ArgumentException($"Key {GetPath()} has too many values (>{ushort.MaxValue})!");
            }

            offset = BinarySerializeUtils.Serialize((ushort)_values.Count, ioBuffer, offset);

            for (int i = 0; i < _values.Count; i++)
            {
                IKeyValue val = _values[i];
                offset = val.BinarySerialize(ioBuffer, offset);
            }

            if (_keys.Count > ushort.MaxValue)
            {
                throw new ArgumentException($"Key {GetPath()} has too many child keys (>{ushort.MaxValue})!");
            }

            offset = BinarySerializeUtils.Serialize((ushort)_keys.Count, ioBuffer, offset);

            //значения:
            for (int i = 0; i < _keys.Count; i++)
            {
                IKey key = _keys[i];
                offset = key.BinarySerialize(ioBuffer, offset);
            }

            return(offset);
        }