public static IBinaryObject BinaryModel(Random random, IBinaryObjectBuilder builder) { var entry = new double[1000 * 32]; for (var j = 0; j < entry.Length; j++) { entry[j] = random.NextDouble(); } return(builder.SetDoubleArrayField("data", entry).Build()); }
public IBinaryObject[] GetBinaryModels(IBinaryObjectBuilder builder) { var entry = new double[1000 * 32]; var data = new IBinaryObject[Params.Instance.Value.TotalObjects]; var random = new Random(); for (var i = 0; i < data.Length; i++) { for (var j = 0; j < entry.Length; j++) { entry[j] = random.NextDouble(); } data[i] = builder.SetDoubleArrayField("data", entry).Build(); } return(data); }
private unsafe void ReadField(IBinaryObjectBuilder builder, RecordField field) { // TODO: Binary object builder seems to be inefficient because of internal structure handling. // We should try with entity classes, and each class can implement RecordField reading efficiently. var pos = field.StartPos - 1; var len = field.EndPos - pos; switch (field.Type) { case RecordFieldType.String: { // All strings are ASCII, see .dat.sql files. // Strings are padded with spaces (because fixed length). var val = Encoding.ASCII.GetString(_buffer, pos, len).TrimEnd(); builder.SetStringField(field.Name, val); break; } case RecordFieldType.Long: fixed(byte *p = &_buffer[pos]) { builder.SetLongField(field.Name, *(long *)p); break; } case RecordFieldType.Double: fixed(byte *p = &_buffer[pos]) { builder.SetDoubleField(field.Name, *(double *)p); break; } default: throw new ArgumentOutOfRangeException(nameof(field.Type), field.Type, "Invalid field type"); } }
public PerperDynamicObject(IBinaryObjectBuilder binaryObjectBuilder) { _binaryObjectBuilder = binaryObjectBuilder; }
// Add dynamic columns private static void SetColumnFields(IBinaryObjectBuilder builder) { Enumerable.Range(0, 3) .ToList() .ForEach(i => builder.SetIntField($"c{i}", i)); }