private static DcSimpleParameter CreateNestedField(DcSubatomicType type, uint divisor) { if (!_nestedFieldMap.TryGetValue(type, out var divisorMap)) { _nestedFieldMap[type] = divisorMap = new Dictionary <uint, DcSimpleParameter>(); } if (divisorMap.TryGetValue(divisor, out var field)) { return(field); } field = new DcSimpleParameter(type, divisor); divisorMap[divisor] = field; return(field); }
public DcSimpleParameter(DcSubatomicType type, uint divisor = 1, DcLongRange?range = null) { Type = type; Divisor = divisor; HasModulus = false; HasFixedByteSize = false; PackType = DcPackType.Invalid; NestedType = DcSubatomicType.Invalid; HasNestedFields = false; BytesPerElement = 0; NumLengthBytes = 2; switch (Type) { case DcSubatomicType.Int8Array: PackType = DcPackType.Array; NestedType = DcSubatomicType.Int8; HasNestedFields = true; BytesPerElement = 1; break; case DcSubatomicType.Int16Array: PackType = DcPackType.Array; NestedType = DcSubatomicType.Int16; HasNestedFields = true; BytesPerElement = 2; break; case DcSubatomicType.Int32Array: PackType = DcPackType.Array; NestedType = DcSubatomicType.Int32; HasNestedFields = true; BytesPerElement = 4; break; case DcSubatomicType.UInt8Array: PackType = DcPackType.Array; NestedType = DcSubatomicType.UInt8; HasNestedFields = true; BytesPerElement = 1; break; case DcSubatomicType.UInt16Array: PackType = DcPackType.Array; NestedType = DcSubatomicType.UInt16; HasNestedFields = true; BytesPerElement = 2; break; case DcSubatomicType.UInt32Array: PackType = DcPackType.Array; NestedType = DcSubatomicType.UInt32; HasNestedFields = true; BytesPerElement = 4; break; case DcSubatomicType.UInt32UInt8Array: PackType = DcPackType.Array; HasNestedFields = true; BytesPerElement = 5; break; case DcSubatomicType.Blob32: NumLengthBytes = 4; PackType = DcPackType.Blob; NestedType = DcSubatomicType.UInt8; HasNestedFields = true; BytesPerElement = 1; break; case DcSubatomicType.Blob: PackType = DcPackType.Blob; NestedType = DcSubatomicType.UInt8; HasNestedFields = true; BytesPerElement = 1; break; case DcSubatomicType.String: PackType = DcPackType.String; NestedType = DcSubatomicType.Char; HasNestedFields = true; BytesPerElement = 1; break; case DcSubatomicType.Char: PackType = DcPackType.String; HasFixedByteSize = true; BytesPerElement = 1; break; case DcSubatomicType.Int8: PackType = DcPackType.Int; HasFixedByteSize = true; FixedByteSize = 1; break; case DcSubatomicType.Int16: PackType = DcPackType.Int; HasFixedByteSize = true; FixedByteSize = 2; break; case DcSubatomicType.Int32: PackType = DcPackType.Int; HasFixedByteSize = true; FixedByteSize = 4; break; case DcSubatomicType.Int64: PackType = DcPackType.Int64; HasFixedByteSize = true; FixedByteSize = 8; break; case DcSubatomicType.UInt8: PackType = DcPackType.UInt; HasFixedByteSize = true; FixedByteSize = 1; break; case DcSubatomicType.UInt16: PackType = DcPackType.UInt; HasFixedByteSize = true; FixedByteSize = 2; break; case DcSubatomicType.UInt32: PackType = DcPackType.UInt; HasFixedByteSize = true; FixedByteSize = 4; break; case DcSubatomicType.UInt64: PackType = DcPackType.UInt64; HasFixedByteSize = true; FixedByteSize = 8; break; case DcSubatomicType.Float64: PackType = DcPackType.Double; HasFixedByteSize = true; FixedByteSize = 8; break; } HasFixedStructure = HasFixedByteSize; LongRange = range ?? new DcLongRange(); SetDivisor(divisor); if (NestedType != DcSubatomicType.Invalid) { NestedField = CreateNestedField(NestedType, divisor); } else if (Type == DcSubatomicType.UInt32UInt8Array) { NestedField = UInt32UInt8Type; } else { NestedField = null; } }