# FrameWriter

<div class="jsdoc-content"><header>
    
        <h2><span class="attribs"><span class="type-signature"></span></span>FrameWriter<span class="signature">()</span><span class="type-signature"></span></h2>
        
            <div class="class-description"><p>Encodes values into values frames, in the request frame layout:
<code>[u16 count]</code>, then for each value <code>[i32 length][bytes]</code>.
Length -1 is null, and -2 is unset.</p>
<p>The writer reuses its buffer between frames.
A frame is a view of that buffer, valid until the next frame of the same writer.
Thus, pass a frame to Rust immediately.
This is safe, because Rust copies the frame before the native call returns.</p>
<p>Callers must obey these rules. Otherwise, concurrent requests can send
each other's values, with no error:</p>
<ul>
<li>Do not <code>await</code> between writing a frame and passing it to Rust.
Another request can write its own frame during the <code>await</code>.</li>
<li>Do not keep a frame after the native call returns.
Copy it if you need it later, for example in a test.</li>
</ul>
<p>In the driver, only <code>RustSession</code> uses a writer.
Its structure enforces these rules. See its documentation.</p>
<p>A writer writes one frame at a time.
A nested frame on the same writer throws, because it would overwrite the frame in progress.</p></div>
        
    
</header>


    
        

    
    </div>

## Constructor

<div class="jsdoc-content">
    

    
    <h4 class="name" id="FrameWriter"><span class="type-signature"></span>new FrameWriter<span class="signature">()</span><span class="type-signature"></span></h4>
    

    















<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.7.1/lib/frame-writer.ts#L42" target="_blank" rel="noopener">frame-writer.ts, line 42</a></p></div>




















    
    

    

    

    

    

    

    

    

    
        </div>

## Methods

<div class="jsdoc-content">

        
            

    

    
    <h4 class="name" id="batch"><span class="type-signature"></span>batch<span class="signature">(expectedTypes, params, encoder)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Encodes the params of all statements of a batch into one frame:
<code>[u16 statement count]</code>, then one params row per statement.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>expectedTypes</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"><p>List of expected types, one list per statement.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>params</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"><p>Params, one array per statement.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>encoder</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.7.1/lib/frame-writer.ts#L74" target="_blank" rel="noopener">frame-writer.ts, line 74</a></p></div>













<h5>Throws:</h5>

        

    <div class="param-desc">
    
        <p>ArgumentError when there are more than 65,535 statements,
or more than 65,535 params in one statement</p>
    
    </div>


    


<h5>Returns:</h5>

        
<div class="param-desc">
    <p>The frame, valid until the next frame of this writer.</p>
</div>



    





        
            

    

    
    <h4 class="name" id="buffers"><span class="type-signature"></span>buffers<span class="signature">(values)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Writes values that are already encoded into one frame.
<code>null</code> is written as null, and <code>undefined</code> as unset.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>values</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"><p>Encoded values.</p></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.7.1/lib/frame-writer.ts#L108" target="_blank" rel="noopener">frame-writer.ts, line 108</a></p></div>













<h5>Throws:</h5>
<ul>
        <li>

    <div class="param-desc">
    
        <p>TypeError when a value is not a Uint8Array, null or undefined</p>
    
    </div>

</li>
    
        <li>

    <div class="param-desc">
    
        <p>ArgumentError when there are more than 65,535 values</p>
    
    </div>

</li>
    </ul>


<h5>Returns:</h5>

        
<div class="param-desc">
    <p>The frame, valid until the next frame of this writer.</p>
</div>



    





        
            

    

    
    <h4 class="name" id="params"><span class="type-signature"></span>params<span class="signature">(expectedTypes, params, encoder)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Encodes all params of a statement into one frame.</p>
</div>









    <h5>Parameters:</h5>
    

<table class="params docutils align-default">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>expectedTypes</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"><p>List of expected types.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>params</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>encoder</code></td>
            

            <td class="type">
            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    
    </tbody>
</table>






<div class="admonition note"><p class="admonition-title">Source</p><p><a href="https://github.com/scylladb/nodejs-rs-driver/blob/v0.7.1/lib/frame-writer.ts#L54" target="_blank" rel="noopener">frame-writer.ts, line 54</a></p></div>













<h5>Throws:</h5>

        

    <div class="param-desc">
    
        <p>ArgumentError when there are more than 65,535 params</p>
    
    </div>


    


<h5>Returns:</h5>

        
<div class="param-desc">
    <p>The frame, valid until the next frame of this writer.</p>
</div></div>
