public static int SizeDouble(int fieldIndex, double value) { if (value < double.Epsilon) { return(0); } return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Fixed64)) + 8); }
public static int SizeFloat(int fieldIndex, float value) { if (value < float.Epsilon) { return(0); } return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Fixed32)) + 4); }
public static int SizeBool(int fieldIndex, bool value) { if (value == false) { return(0); } return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) + 1); }
public static int SizeUInt64(int fieldIndex, ulong value) { if (value == 0) { return(0); } return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) + ComputeRawVarint64Size(value)); }
public static int SizeUInt32(int fieldIndex, uint value) { if (value == 0) { return(0); } return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) + GetVarint32Size(value)); }
public static int SizeFloat(int fieldIndex, List <float> value) { if (value == null || value.Count == 0) { return(0); } int size = value.Count * 4; return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Bytes)) + GetVarint32Size((uint)size) + size); }
public static int SizeString(int fieldIndex, string value) { if (string.IsNullOrEmpty(value)) { return(0); } int strLen = Encoding.UTF8.GetByteCount(value); return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) + GetVarint32Size((uint)strLen) + strLen); }
public static int SizeBytes(int fieldIndex, byte[] value) { if (value == null || value.Length == 0) { return(0); } int size = value.Length; return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Bytes)) + GetVarint32Size((uint)size) + size); }
public static int SizeInt64(int fieldIndex, long value) { if (value == 0) { return(0); } if (value > 0) { return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) + ComputeRawVarint64Size((ulong)value)); } return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Fixed64)) + 8); }
public static int SizeInt32(int fieldIndex, int value) { if (value == 0) { return(0); } if (value > 0) { return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) + GetVarint32Size((uint)value)); } return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Fixed32)) + 4); }
public static int SizeEnum <T>(int fieldIndex, List <T> value) where T : struct, IConvertible { if (value == null || value.Count == 0) { return(0); } int size = 0; for (int i = 0; i < value.Count; i++) { size += GetVarint32Size((uint)Convert.ToInt32(value[i])); } return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Bytes)) + GetVarint32Size((uint)size) + size); }
public static int SizeStruct(int fieldIndex, IProtoStruct value) { if (value == null) { return(0); } var size = value.GetSize(); if (size == 0) { return(0); } return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Varint)) + GetVarint32Size((uint)size) + size); }
public static int SizeUInt64(int fieldIndex, List <ulong> value) { if (value == null || value.Count == 0) { return(0); } int size = 0; for (int i = 0; i < value.Count; i++) { size += ComputeRawVarint64Size(value[i]); } return(GetVarint32Size(WireFormat.MakeTag(fieldIndex, WireFormat.WireType.Bytes)) + GetVarint32Size((uint)size) + size); }
void WriteTag(int fieldNumber, WireFormat.WireType type) { WriteVarint32(WireFormat.MakeTag(fieldNumber, type)); }