/// <summary>
        ///     Generate Bytes
        /// </summary>
        /// <returns>byte[]</returns>
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // create vectors
            var signatureVector = RegisterNamespaceTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = RegisterNamespaceTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var feeVector       = TransferTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var deadlineVector  =
                RegisterNamespaceTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var namespaceIdVector =
                RegisterNamespaceTransactionBuffer.CreateNamespaceIdVector(builder, NamespaceId.Id.ToUInt8Array());
            var durationParentId = NamespaceType == NamespaceType.ROOT_NAMESPACE
                ? Duration?.ToUInt8Array()
                : ParentId.Id.ToUInt8Array();
            var durationParentIdVector =
                RegisterNamespaceTransactionBuffer.CreateDurationParentIdVector(builder, durationParentId);



            // header, ns type, duration, ns id, name size, name
            int totalSize = GetSerializedSize();

            // create version
            var version = GetTxVersionSerialization();

            var name = builder.CreateString(NamespaceName);

            // ADD to buffer
            RegisterNamespaceTransactionBuffer.StartRegisterNamespaceTransactionBuffer(builder);
            RegisterNamespaceTransactionBuffer.AddSize(builder, (uint)totalSize);
            RegisterNamespaceTransactionBuffer.AddSignature(builder, signatureVector);
            RegisterNamespaceTransactionBuffer.AddSigner(builder, signerVector);
            RegisterNamespaceTransactionBuffer.AddVersion(builder, (uint)version);
            RegisterNamespaceTransactionBuffer.AddType(builder, TransactionType.GetValue());
            RegisterNamespaceTransactionBuffer.AddMaxFee(builder, feeVector);
            RegisterNamespaceTransactionBuffer.AddDeadline(builder, deadlineVector);
            RegisterNamespaceTransactionBuffer.AddNamespaceType(builder, NamespaceType.GetValueInByte());
            RegisterNamespaceTransactionBuffer.AddDurationParentId(builder, durationParentIdVector);
            RegisterNamespaceTransactionBuffer.AddNamespaceId(builder, namespaceIdVector);
            RegisterNamespaceTransactionBuffer.AddNamespaceNameSize(builder, (byte)NamespaceName.Length);
            RegisterNamespaceTransactionBuffer.AddNamespaceName(builder, name);

            // Calculate size
            var codedNamespace = RegisterNamespaceTransactionBuffer.EndRegisterNamespaceTransactionBuffer(builder);

            builder.Finish(codedNamespace.Value);

            var output = new RegisterNamespaceTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }
        internal override byte[] GenerateBytes()
        {
            var builder = new FlatBufferBuilder(1);

            // create message
            var bytePayload = Message.GetPayload();
            var payload     = MessageBuffer.CreatePayloadVector(builder, bytePayload);

            MessageBuffer.StartMessageBuffer(builder);
            MessageBuffer.AddType(builder, Message.GetMessageType());
            MessageBuffer.AddPayload(builder, payload);
            var messageVector = MessageBuffer.EndMessageBuffer(builder);

            // create mosaics
            var mosaicBuffers = new Offset <MosaicBuffer> [Mosaics.Count];

            for (var index = 0; index < Mosaics.Count; ++index)
            {
                var mosaic = Mosaics[index];
                var id     = MosaicBuffer.CreateIdVector(builder, mosaic.Id.Id.ToUInt8Array());
                var amount = MosaicBuffer.CreateAmountVector(builder, mosaic.Amount.ToUInt8Array());
                MosaicBuffer.StartMosaicBuffer(builder);
                MosaicBuffer.AddId(builder, id);
                MosaicBuffer.AddAmount(builder, amount);
                mosaicBuffers[index] = MosaicBuffer.EndMosaicBuffer(builder);
            }

            // create recipient
            byte[] recipientBytes = Recipient.GetBytes();

            // create vectors
            var signatureVector = TransferTransactionBuffer.CreateSignatureVector(builder, new byte[64]);
            var signerVector    = TransferTransactionBuffer.CreateSignerVector(builder, GetSigner());
            var deadlineVector  = TransferTransactionBuffer.CreateDeadlineVector(builder, Deadline.Ticks.ToUInt8Array());
            var feeVector       = TransferTransactionBuffer.CreateMaxFeeVector(builder, MaxFee?.ToUInt8Array());
            var recipientVector =
                TransferTransactionBuffer.CreateRecipientVector(builder, recipientBytes);
            var mosaicsVector = TransferTransactionBuffer.CreateMosaicsVector(builder, mosaicBuffers);

            // total size of transaction

            /*var totalSize = HEADER_SIZE
             + 25 // recipient
             + 2 // message size is short
             + 1 // message type byte
             + 1 // no of mosaics
             + ((8 + 8) * Mosaics.Count) //each mosaic has id(8bytes) and amount(8bytes)
             + bytePayload.Length; // number of message bytes*/

            var totalSize = GetSerializedSize();

            // create version
            var version = GetTxVersionSerialization();


            // add vectors
            TransferTransactionBuffer.StartTransferTransactionBuffer(builder);
            TransferTransactionBuffer.AddSize(builder, (uint)totalSize);
            TransferTransactionBuffer.AddSignature(builder, signatureVector);
            TransferTransactionBuffer.AddSigner(builder, signerVector);
            TransferTransactionBuffer.AddVersion(builder, (uint)version);
            TransferTransactionBuffer.AddType(builder, EntityType.TRANSFER.GetValue());
            TransferTransactionBuffer.AddMaxFee(builder, feeVector);
            TransferTransactionBuffer.AddDeadline(builder, deadlineVector);

            TransferTransactionBuffer.AddRecipient(builder, recipientVector);
            TransferTransactionBuffer.AddNumMosaics(builder, (byte)Mosaics.Count);
            TransferTransactionBuffer.AddMessageSize(builder, (ushort)(bytePayload.Length + 1));
            TransferTransactionBuffer.AddMessage(builder, messageVector);
            TransferTransactionBuffer.AddMosaics(builder, mosaicsVector);

            // end build
            var codedTransfer = TransferTransactionBuffer.EndTransferTransactionBuffer(builder);

            builder.Finish(codedTransfer.Value);

            // validate size
            var output = new TransferTransactionSchema().Serialize(builder.SizedByteArray());

            if (output.Length != totalSize)
            {
                throw new SerializationException("Serialized form has incorrect length");
            }

            return(output);
        }