public static IHerculesTagsBuilder AddTags(this IHerculesTagsBuilder builder, HerculesTags tags)
        {
            foreach (var tag in tags)
            {
                var key   = tag.Key;
                var value = tag.Value;

                switch (value.Type)
                {
                case HerculesValueType.String:
                    builder.AddValue(key, value.AsString);
                    break;

                case HerculesValueType.Long:
                    builder.AddValue(key, value.AsLong);
                    break;

                case HerculesValueType.Guid:
                    builder.AddValue(key, value.AsGuid);
                    break;

                case HerculesValueType.Container:
                    builder.AddContainer(key, tagsBuilder => tagsBuilder.AddTags(value.AsContainer));
                    break;

                case HerculesValueType.Int:
                    builder.AddValue(key, value.AsInt);
                    break;

                case HerculesValueType.Double:
                    builder.AddValue(key, value.AsDouble);
                    break;

                case HerculesValueType.Bool:
                    builder.AddValue(key, value.AsBool);
                    break;

                case HerculesValueType.Null:
                    builder.AddNull(key);
                    break;

                case HerculesValueType.Byte:
                    builder.AddValue(key, value.AsByte);
                    break;

                case HerculesValueType.Short:
                    builder.AddValue(key, value.AsShort);
                    break;

                case HerculesValueType.Float:
                    builder.AddValue(key, value.AsFloat);
                    break;

                case HerculesValueType.Vector:
                    builder.AddVector(key, value.AsVector);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(value.Type), value.Type, "Unknown tag type.");
                }
            }

            return(builder);
        }
Ejemplo n.º 2
0
        private static void ReadContainer(IBinaryReader reader, IHerculesTagsBuilder builder)
        {
            var tagsCount = reader.ReadInt16();

            for (var i = 0; i < tagsCount; i++)
            {
                var key       = reader.ReadShortString();
                var valueType = (TagType)reader.ReadByte();

                switch (valueType)
                {
                case TagType.String:
                    builder.AddValue(key, reader.ReadString());
                    break;

                case TagType.Long:
                    builder.AddValue(key, reader.ReadInt64());
                    break;

                case TagType.Uuid:
                    builder.AddValue(key, reader.ReadGuid());
                    break;

                case TagType.Container:
                    builder.AddContainer(key, b => ReadContainer(reader, b));
                    break;

                case TagType.Integer:
                    builder.AddValue(key, reader.ReadInt32());
                    break;

                case TagType.Double:
                    builder.AddValue(key, reader.ReadDouble());
                    break;

                case TagType.Flag:
                    builder.AddValue(key, reader.ReadBool());
                    break;

                case TagType.Null:
                    builder.AddNull(key);
                    break;

                case TagType.Byte:
                    builder.AddValue(key, reader.ReadByte());
                    break;

                case TagType.Short:
                    builder.AddValue(key, reader.ReadInt16());
                    break;

                case TagType.Float:
                    builder.AddValue(key, reader.ReadFloat());
                    break;

                case TagType.Vector:
                    ReadVector(reader, builder, key);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(valueType), valueType, "Unexpected tag value type.");
                }
            }
        }