/// <summary> /// Writes a decimal to a UcAsp.RPC.ProtoBuf stream /// </summary> public static void WriteDecimal(decimal value, ProtoWriter writer) { int[] bits = decimal.GetBits(value); ulong a = ((ulong)bits[1]) << 32, b = ((ulong)bits[0]) & 0xFFFFFFFFL; ulong low = a | b; uint high = (uint)bits[2]; uint signScale = (uint)(((bits[3] >> 15) & 0x01FE) | ((bits[3] >> 31) & 0x0001)); SubItemToken token = ProtoWriter.StartSubItem(null, writer); if (low != 0) { ProtoWriter.WriteFieldHeader(FieldDecimalLow, WireType.Variant, writer); ProtoWriter.WriteUInt64(low, writer); } if (high != 0) { ProtoWriter.WriteFieldHeader(FieldDecimalHigh, WireType.Variant, writer); ProtoWriter.WriteUInt32(high, writer); } if (signScale != 0) { ProtoWriter.WriteFieldHeader(FieldDecimalSignScale, WireType.Variant, writer); ProtoWriter.WriteUInt32(signScale, writer); } ProtoWriter.EndSubItem(token, writer); }