WireFormat.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Google.ProtocolBuffers {
  5. public class WireFormat {
  6. public enum WireType : uint {
  7. Varint = 0,
  8. Fixed64 = 1,
  9. LengthDelimited = 2,
  10. StartGroup = 3,
  11. EndGroup = 4,
  12. Fixed32 = 5
  13. }
  14. internal class MessageSetField {
  15. internal const int Item = 1;
  16. internal const int TypeID = 2;
  17. internal const int Message = 3;
  18. }
  19. private const int TagTypeBits = 3;
  20. private const uint TagTypeMask = (1 << TagTypeBits) - 1;
  21. /// <summary>
  22. /// Given a tag value, determines the wire type (lower 3 bits).
  23. /// </summary>
  24. public static WireType GetTagWireType(uint tag) {
  25. return (WireType) (tag & TagTypeMask);
  26. }
  27. /// <summary>
  28. /// Given a tag value, determines the field number (the upper 29 bits).
  29. /// </summary>
  30. public static uint GetTagFieldNumber(uint tag) {
  31. return tag >> TagTypeBits;
  32. }
  33. /// <summary>
  34. /// Makes a tag value given a field number and wire type.
  35. /// </summary>
  36. public static uint MakeTag(int fieldNumber, WireType wireType) {
  37. return (uint) (fieldNumber << TagTypeBits) | (uint) wireType;
  38. }
  39. }
  40. }