Exemplo n.º 1
0
 public static Offset <LineItemKey> CreateLineItemKey(FlatBufferBuilder builder,
                                                      StringOffset prodCodeOffset = default(StringOffset),
                                                      int orderId = 0)
 {
     builder.StartObject(2);
     LineItemKey.AddOrderId(builder, orderId);
     LineItemKey.AddProdCode(builder, prodCodeOffset);
     return(LineItemKey.EndLineItemKey(builder));
 }
Exemplo n.º 2
0
 public static Offset <KdSoft.Lmdb.Tests.fbs.LineItemKey> CreateLineItemKey(FlatBufferBuilder builder,
                                                                            StringOffset prod_codeOffset = default(StringOffset),
                                                                            int order_id = 0)
 {
     builder.StartTable(2);
     LineItemKey.AddOrderId(builder, order_id);
     LineItemKey.AddProdCode(builder, prod_codeOffset);
     return(LineItemKey.EndLineItemKey(builder));
 }
Exemplo n.º 3
0
        public void SimpleStoreRetrieve()
        {
            var        config = new DatabaseConfiguration(DatabaseOptions.Create);
            Database   dbase;
            Statistics stats;

            using (var tx = fixture.Env.BeginDatabaseTransaction(TransactionModes.None)) {
                dbase = tx.OpenDatabase("TestDb3", config);
                stats = dbase.GetStats(tx);
                tx.Commit();
            }

            var buffer = fixture.Buffers.Acquire(1024);

            try {
                FlatBufferBuilder liBuilder    = new FlatBufferBuilder(64);
                FlatBufferBuilder liKeyBuilder = new FlatBufferBuilder(32);

                // in FlatBuffers, each serializable item is backed by a byte buffer, the item itself is a struct
                byte[] liBytes;
                byte[] li2Bytes;
                using (var tx = fixture.Env.BeginTransaction(TransactionModes.None)) {
                    var prodCode = liKeyBuilder.CreateString("GIN");
                    var lik      = LineItemKey.CreateLineItemKey(liKeyBuilder, prodCode, 1);
                    liKeyBuilder.Finish(lik.Value);

                    prodCode = liBuilder.CreateString("GIN");
                    lik      = LineItemKey.CreateLineItemKey(liBuilder, prodCode, 1);
                    var li = LineItem.CreateLineItem(liBuilder, lik, 24);
                    liBuilder.Finish(li.Value);

                    liBytes = liBuilder.SizedByteArray();

                    // lineItem points into the liBuilder's data buffer
                    var lineItem = LineItem.GetRootAsLineItem(liBuilder.DataBuffer);

                    var keySpan  = liKeyBuilder.DataBuffer.ToSpan();
                    var dataSpan = liBuilder.DataBuffer.ToSpan();
                    dbase.Put(tx, keySpan, dataSpan, PutOptions.None);

                    liKeyBuilder.Clear();
                    liBuilder.Clear();

                    prodCode = liKeyBuilder.CreateString("WHISKY");
                    lik      = LineItemKey.CreateLineItemKey(liKeyBuilder, prodCode, 2);
                    liKeyBuilder.Finish(lik.Value);

                    prodCode = liBuilder.CreateString("WHISKY");
                    lik      = LineItemKey.CreateLineItemKey(liBuilder, prodCode, 2);
                    li       = LineItem.CreateLineItem(liBuilder, lik, 32);
                    liBuilder.Finish(li.Value);

                    li2Bytes = liBuilder.SizedByteArray();

                    keySpan  = liKeyBuilder.DataBuffer.ToSpan();
                    dataSpan = liBuilder.DataBuffer.ToSpan();
                    dbase.Put(tx, keySpan, dataSpan, PutOptions.None);

                    tx.Commit();
                }

                byte[] liOutBytes;
                byte[] liOut2Bytes;
                using (var tx = fixture.Env.BeginReadOnlyTransaction(TransactionModes.None)) {
                    liKeyBuilder.Clear();
                    var prodCode = liKeyBuilder.CreateString("GIN");
                    var lik      = LineItemKey.CreateLineItemKey(liKeyBuilder, prodCode, 1);
                    liKeyBuilder.Finish(lik.Value);

                    var keySpan = liKeyBuilder.DataBuffer.ToSpan();

                    Assert.True(dbase.Get(tx, keySpan, out ReadOnlySpan <byte> dataSpan));
                    liOutBytes = dataSpan.ToArray();

                    // lineItemOut points into liOutBytes
                    var lineItemOut = LineItem.GetRootAsLineItem(new ByteBuffer(liOutBytes));

                    liKeyBuilder.Clear();
                    prodCode = liKeyBuilder.CreateString("WHISKY");
                    lik      = LineItemKey.CreateLineItemKey(liKeyBuilder, prodCode, 2);
                    liKeyBuilder.Finish(lik.Value);

                    keySpan = liKeyBuilder.DataBuffer.ToSpan();

                    Assert.True(dbase.Get(tx, keySpan, out dataSpan));
                    liOut2Bytes = dataSpan.ToArray();

                    tx.Commit();
                }

                Assert.True(liBytes.SequenceEqual(liOutBytes));
                Assert.True(li2Bytes.SequenceEqual(liOut2Bytes));
            }
            finally {
                fixture.Buffers.Return(buffer);
                using (var tx = fixture.Env.BeginDatabaseTransaction(TransactionModes.None)) {
                    dbase.Drop(tx);
                    tx.Commit();
                }
            }
        }
Exemplo n.º 4
0
 public static LineItemKey GetRootAsLineItemKey(ByteBuffer _bb, LineItemKey obj)
 {
     return(obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }