private bool UnpackHeader(byte[] buffer, int start, ref int type, ref int length) { CodedInputStream cis = new CodedInputStream(buffer, start, 8); type = (int)cis.ReadFixed32(); length = (int)cis.ReadFixed32(); if (length != 0) { return(true); } handleMessage(type, typeof(int)); return(false); }
/// <summary> /// Reads an unknown field, either parsing it and storing it or skipping it. /// </summary> /// <remarks> /// If the current set of options is empty and we manage to read a field, a new set of options /// will be created and returned. Otherwise, the return value is <c>this</c>. This allows /// us to start with a singleton empty set of options and just create new ones where necessary. /// </remarks> /// <param name="input">Input stream to read from. </param> /// <returns>The resulting set of custom options, either <c>this</c> or a new set.</returns> internal CustomOptions ReadOrSkipUnknownField(CodedInputStream input) { var tag = input.LastTag; var field = WireFormat.GetTagFieldNumber(tag); switch (WireFormat.GetTagWireType(tag)) { case WireFormat.WireType.LengthDelimited: return(AddValue(field, new FieldValue(input.ReadBytes()))); case WireFormat.WireType.Fixed32: return(AddValue(field, new FieldValue(input.ReadFixed32()))); case WireFormat.WireType.Fixed64: return(AddValue(field, new FieldValue(input.ReadFixed64()))); case WireFormat.WireType.Varint: return(AddValue(field, new FieldValue(input.ReadRawVarint64()))); // For StartGroup, EndGroup or any wire format we don't understand, // just use the normal behavior (call SkipLastField). default: input.SkipLastField(); return(this); } }
private static void SkipUnknown(CodedInputStream input, WireType wireType) { switch (wireType) { case WireType.None: break; case WireType.Variant: input.ReadRawVarint32(); break; case WireType.Fixed64: input.ReadFixed64(); break; case WireType.String: input.SkipString(); break; case WireType.StartGroup: break; case WireType.EndGroup: break; case WireType.Fixed32: input.ReadFixed32(); break; default: throw new ArgumentOutOfRangeException(); } }
public uint ParseFixed32() { const int encodedSize = sizeof(uint); CodedInputStream cis = new CodedInputStream(fixedIntInputBuffer); uint sum = 0; for (uint i = 0; i < BytesToParse / encodedSize; i++) { sum += cis.ReadFixed32(); } return(sum); }