示例#1
0
        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());
        }
示例#2
0
        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);
        }
示例#3
0
        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");
            }
        }
示例#4
0
 public PerperDynamicObject(IBinaryObjectBuilder binaryObjectBuilder)
 {
     _binaryObjectBuilder = binaryObjectBuilder;
 }
示例#5
0
 // Add dynamic columns
 private static void SetColumnFields(IBinaryObjectBuilder builder)
 {
     Enumerable.Range(0, 3)
     .ToList()
     .ForEach(i => builder.SetIntField($"c{i}", i));
 }