コード例 #1
0
        /// <summary>
        /// Writes a message or group as a field
        /// </summary>
        protected override void WriteMessageOrGroup(string field, IMessageLite message)
        {
            DictionaryWriter writer = Create();

            writer.WriteMessage(message);

            _output[field] = writer.ToDictionary();
        }
コード例 #2
0
        /// <summary>
        /// Writes an array of field values
        /// </summary>
        protected override void WriteArray(FieldType fieldType, string field, IEnumerable items)
        {
            List <object> objects = new List <object>();

            foreach (object o in items)
            {
                switch (fieldType)
                {
                case FieldType.Group:
                case FieldType.Message:
                {
                    DictionaryWriter writer = Create();
                    writer.WriteMessage((IMessageLite)o);
                    objects.Add(writer.ToDictionary());
                }
                break;

                case FieldType.Bytes:
                    objects.Add(((ByteString)o).ToByteArray());
                    break;

                case FieldType.Enum:
                    if (o is IEnumLite)
                    {
                        objects.Add(((IEnumLite)o).Number);
                    }
                    else
                    {
                        objects.Add((int)o);
                    }
                    break;

                default:
                    objects.Add(o);
                    break;
                }
            }

            _output[field] = objects.ToArray();
        }