BITFIELD and BITFIELD_RO feature by slorello89 · Pull Request #2107 · StackExchange/StackExchange.Redis
I want to play with an alternative API before we get too carried away. This feels pretty complex at the moment. What I have in mind is something like:
public readonly struct BitfieldOperation
{
long offset, value
SomeInternalEnum : byte opType
byte encoding // low 6 == width
// high 2 == by bit/enc, signed/unsigned
public static BitfieldOperation Get(long offset,
byte width, bool unsigned = false, offsetByBit = false)
public static BitfieldOperation Set(long offset,
byte width, bool unsigned = false, offsetByBit = false)
public static BitfieldOperation Increment(long offset,
byte width, BitfieldOverflow overflow = /* Todo */, bool unsigned = false, offsetByBit = false)
// Other bits not shown
}
With the main bitfield methods taking either a single BitfieldOperation or an array.
Internally, we can check the BitfieldOperation if the operand(s) to compute RO. No need for the builder, list, or packs of RedisValue - we should also be able to have each operation say "I contribute this many args", so we can do efficient write
But more importantly, it allows simple usage at the call site, i.e.
dB.Bitfield(key, [ BitfieldOperation.Get(...), BitfieldOperation.Set(...) ])
Thoughts?