예제 #1
0
        public void AddEntriesFrom(ref ParseContext ctx, Codec codec)
        {
            var adapter = new Codec.MessageAdapter(codec);

            do
            {
                adapter.Reset();
                ctx.ReadMessage(adapter);
                this[adapter.Key] = adapter.Value;
            } while (ParsingPrimitives.MaybeConsumeTag(ref ctx.buffer, ref ctx.state, codec.MapTag));
        }
예제 #2
0
        /// <summary>
        /// Adds entries to the map from the given stream.
        /// </summary>
        /// <remarks>
        /// It is assumed that the stream is initially positioned after the tag specified by the codec.
        /// This method will continue reading entries from the stream until the end is reached, or
        /// a different tag is encountered.
        /// </remarks>
        /// <param name="input">Stream to read from</param>
        /// <param name="codec">Codec describing how the key/value pairs are encoded</param>
        public void AddEntriesFrom(CodedInputStream input, Codec codec)
        {
            var adapter = new Codec.MessageAdapter(codec);

            do
            {
                adapter.Reset();
                input.ReadMessage(adapter);
                this[adapter.Key] = adapter.Value;
            } while (input.MaybeConsumeTag(codec.MapTag));
        }
예제 #3
0
        public void WriteTo(ref WriteContext ctx, Codec codec)
        {
            var message = new Codec.MessageAdapter(codec);

            foreach (var entry in list)
            {
                message.Key   = entry.Key;
                message.Value = entry.Value;
                ctx.WriteTag(codec.MapTag);
                ctx.WriteMessage(message);
            }
        }
예제 #4
0
        /// <summary>
        /// Writes the contents of this map to the given coded output stream, using the specified codec
        /// to encode each entry.
        /// </summary>
        /// <param name="output">The output stream to write to.</param>
        /// <param name="codec">The codec to use for each entry.</param>
        public void WriteTo(CodedOutputStream output, Codec codec)
        {
            var message = new Codec.MessageAdapter(codec);

            foreach (var entry in list)
            {
                message.Key   = entry.Key;
                message.Value = entry.Value;
                output.WriteTag(codec.MapTag);
                output.WriteMessage(message);
            }
        }
예제 #5
0
        /// <summary>
        /// Calculates the size of this map based on the given entry codec.
        /// </summary>
        /// <param name="codec">The codec to use to encode each entry.</param>
        /// <returns></returns>
        public int CalculateSize(Codec codec)
        {
            if (Count == 0)
            {
                return(0);
            }
            var message = new Codec.MessageAdapter(codec);
            int size    = 0;

            foreach (var entry in list)
            {
                message.Key   = entry.Key;
                message.Value = entry.Value;
                size         += CodedOutputStream.ComputeRawVarint32Size(codec.MapTag);
                size         += CodedOutputStream.ComputeMessageSize(message);
            }
            return(size);
        }