Exemplo n.º 1
0
        private static void ProcessExtraData(SerializationContext read, int fieldTag, WireType wireType, SerializationContext write)
        {
            int len;

            switch (wireType)
            {
            case WireType.Variant:
                len = read.ReadRawVariant();
                write.WriteBlock(read.Workspace, 0, len);
                break;

            case WireType.Fixed32:
                read.ReadBlock(4);
                write.WriteBlock(read.Workspace, 0, 4);
                break;

            case WireType.Fixed64:
                read.ReadBlock(8);
                write.WriteBlock(read.Workspace, 0, 8);
                break;

            case WireType.String:
                len = read.DecodeInt32();
                write.EncodeInt32(len);
                read.WriteTo(write, len);
                break;

            case WireType.StartGroup:
                read.StartGroup(fieldTag);
                uint prefix;
                while (read.TryReadFieldPrefix(out prefix))
                {
                    write.EncodeUInt32(prefix);
                    Serializer.ParseFieldToken(prefix, out wireType, out fieldTag);
                    if (wireType == WireType.EndGroup)
                    {
                        read.EndGroup(fieldTag);
                        break;
                    }
                    ProcessExtraData(read, fieldTag, wireType, write);
                }
                break;

            case WireType.EndGroup:
                throw new ProtoException("End-group not expected at this location");

            default:
                throw new ProtoException("Unknown wire-type " + wireType);
            }
        }