Bend.SegmentBlockBasicEncoder.add C# (CSharp) Method

add() public method

public add ( RecordKey key, RecordUpdate data ) : void
key RecordKey
data RecordUpdate
return void
        public void add(RecordKey key, RecordUpdate data)
        {
            byte[] keybytes = key.encode();
            byte[] databytes = data.encode();

            writeEncoded(output,keybytes);
            output.WriteByte(KEY_VAL_SEP);
            writeEncoded(output,databytes);
            output.WriteByte(END_OF_LINE);
        }

Usage Example

Example #1
0
        public static void T01_BlockEncodeDecodeTest()
        {
            MemoryStream ms = new MemoryStream();
            byte[] testdata = { 0x00, 0x10, 0x78, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00 };

            // init an encoder and add one key which requires escaping
            {
                ISegmentBlockEncoder enc = new SegmentBlockBasicEncoder();
                enc.setStream(ms);

                RecordKey key = new RecordKey().appendParsedKey("TESTSETEST");
                RecordUpdate update = RecordUpdate.WithPayload(testdata);

                enc.add(key, update);
                enc.flush();
                ms.Flush();

                System.Console.WriteLine("Test Update: " + update.ToString());
            }

            byte[] block_contents = ms.ToArray();
            System.Console.WriteLine("Block Output: " + BitConverter.ToString(block_contents));

            // init the decoder
            {
                ISegmentBlockDecoder dec = new SegmentBlockBasicDecoder(new BlockAccessor(ms.ToArray()));

                foreach (var kvp in dec.sortedWalk()) {
                    System.Console.WriteLine("Payload Update: " + kvp.Value.ToString());

                    byte[] payload = kvp.Value.data;
                    Assert.AreEqual(testdata, payload, "payload data mismatch!");
                }
            }
        }
All Usage Examples Of Bend.SegmentBlockBasicEncoder::add