void ISerializer <decimal> .Write(ref ProtoWriter.State state, decimal value) { ulong low; uint high, signScale; if (s_decimalOptimized) // the JIT should remove the non-preferred implementation, at least on modern runtimes { var dec = new DecimalAccessor(value); ulong a = ((ulong)dec.Mid) << 32, b = ((ulong)dec.Lo) & 0xFFFFFFFFL; low = a | b; high = (uint)dec.Hi; signScale = (uint)(((dec.Flags >> 15) & 0x01FE) | ((dec.Flags >> 31) & 0x0001)); } else { int[] bits = decimal.GetBits(value); ulong a = ((ulong)bits[1]) << 32, b = ((ulong)bits[0]) & 0xFFFFFFFFL; low = a | b; high = (uint)bits[2]; signScale = (uint)(((bits[3] >> 15) & 0x01FE) | ((bits[3] >> 31) & 0x0001)); } if (low != 0) { state.WriteFieldHeader(FieldDecimalLow, WireType.Varint); state.WriteUInt64(low); } if (high != 0) { state.WriteFieldHeader(FieldDecimalHigh, WireType.Varint); state.WriteUInt32(high); } if (signScale != 0) { state.WriteFieldHeader(FieldDecimalSignScale, WireType.Varint); state.WriteUInt32(signScale); } }
public void Write(ref ProtoWriter.State state, object value) { state.WriteUInt32((uint)value); }