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);
            }
        }
Exemplo n.º 2
0
        internal static void SkipData(SerializationContext context, int fieldTag, WireType wireType)
        {
            switch (wireType)
            {
            case WireType.Variant:
                context.ReadRawVariant();
                break;

            case WireType.Fixed32:
                context.ReadBlock(4);
                break;

            case WireType.Fixed64:
                context.ReadBlock(8);
                break;

            case WireType.String:
                int len = context.DecodeInt32();
                context.WriteTo(Stream.Null, len);
                break;

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

            case WireType.StartGroup:
                context.StartGroup(fieldTag);     // will be ended internally
                Serializer <UnknownType> .Build();

                UnknownType ut = UnknownType.Default;
                Serializer <UnknownType> .Deserialize <UnknownType>(ref ut, context);

                break;

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