Пример #1
0
        void ISerializedType.Serialize(Serializer so, object val, bool noMarker)
        {
            ulong?number = Utils.TryGetNumber <ulong>(val, false);

            if (number.HasValue)
            {
                Serialize(so, number.Value, noMarker);
                return;
            }

            if (val is string str)
            {
                if (!Utils.IsHexString(str))
                {
                    throw new ArgumentException("Invalid hex string.");
                }

                if (str.Length > 16)
                {
                    throw new ArgumentException("Int64 is too large.");
                }

                while (str.Length < 16)
                {
                    str = "0" + str;
                }

                SerializedTypeHelper.SerializeHex(so, str, true);
                return;
            }

            throw new ArgumentException("Invalid type for Int64.");
        }
Пример #2
0
        public void Serialize(Serializer so, string val, bool noMarker = false)
        {
            if (val != null && Regex.IsMatch(val, "^[0-9A-F]{0,64}$", RegexOptions.IgnoreCase) &&
                val.Length <= 64)
            {
                SerializedTypeHelper.SerializeHex(so, val, true);
                return;
            }

            throw new ArgumentException("Invalid Hash256.");
        }
Пример #3
0
 public void Serialize(Serializer so, string val, bool noMarker = false)
 {
     SerializedTypeHelper.SerializeHex(so, val);
 }