# Encoder

<div class="jsdoc-content"><header>
    
        <h2><span class="attribs"><span class="type-signature"></span></span>Encoder<span class="signature">(protocolVersion, options)</span><span class="type-signature"></span></h2>
        
            <div class="class-description"><p>Serializes and deserializes to and from a CQL type and a Javascript Type.</p></div>
        
    
</header>


    
        

    
    </div>

## Constructor

<div class="jsdoc-content">
    

    
    <h4 class="name" id="Encoder"><span class="type-signature"></span>new Encoder<span class="signature">(protocolVersion, options)</span><span class="type-signature"></span></h4>
    

    











    <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>protocolVersion</code></td>
            

            <td class="type">
            
                
<span class="param-type">Number</span>


            
            </td>

            

            

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

    

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

            <td class="type">
            
                
<span class="param-type"><a href="globals.html#ClientOptions">ClientOptions</a></span>


            
            </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.6.1/lib/encoder.js#L2120" target="_blank" rel="noopener">encoder.js, line 2120</a></p></div>




















    
    

    

    

    

    

    

    

    

    
        </div>

## Methods

<div class="jsdoc-content">

        
            

    

    
    <h4 class="name" id="decode"><span class="type-signature"></span>decode<span class="signature">(buffer, type)</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    <p>Decodes Cassandra bytes into Javascript values.</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>buffer</code></td>
            

            <td class="type">
            
                
<span class="param-type">Buffer</span>


            
            </td>

            

            

            <td class="description last"><p>Raw buffer to be decoded.</p></td>
        </tr>

    

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

            <td class="type">
            
                
<span class="param-type"><a href="ColumnInfo.html">ColumnInfo</a></span>


            
            </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.6.1/lib/encoder.js#L2260" target="_blank" rel="noopener">encoder.js, line 2260</a></p></div>




















        
            

    

    
    <h4 class="name" id="decodeRows"><span class="type-signature"></span>decodeRows<span class="signature">(data, rowsNumber, columnNames, columnTypes)</span><span class="type-signature"> &rarr; {Array&lt;Row>}</span></h4>
    

    



<div class="description">
    <p>Decodes a whole page of results.</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>data</code></td>
            

            <td class="type">
            
                
<span class="param-type">Buffer</span>


            
            </td>

            

            

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

    

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

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

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

    

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

            <td class="type">
            
                
<span class="param-type">Array&lt;string></span>


            
            </td>

            

            

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

    

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

            <td class="type">
            
                
<span class="param-type">Array&lt;{code: number}></span>


            
            </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.6.1/lib/encoder.js#L2238" target="_blank" rel="noopener">encoder.js, line 2238</a></p></div>















<h5>Returns:</h5>

        


<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Array&lt;Row></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="encode"><span class="type-signature"></span>encode<span class="signature">(value, typeInfo)</span><span class="type-signature"> &rarr; {Buffer|null|undefined}</span></h4>
    

    



<div class="description">
    <p>Encodes Javascript types into Buffer according to the Cassandra protocol.</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>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">\*</span>


            
            </td>

            

            

            <td class="description last"><p>The value to be converted.</p></td>
        </tr>

    

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

            <td class="type">
            
                
<span class="param-type"><a href="ColumnInfo.html">ColumnInfo</a></span>
|

<span class="param-type">String</span>
|

<span class="param-type">Number</span>
|

<span class="param-type">null</span>


            
            </td>

            

            

            <td class="description last"><p>The type information.</p>
<p>It can be either a:</p>
<ul>
<li>A <code>String</code> representing the data type.</li>
<li>A <code>Number</code> with one of the values of <a href="types/index.html#~dataTypes">dataTypes</a>.</li>
<li>An <code>Object</code> containing the <code>type.code</code> as one of the values of
<a href="types/index.html#~dataTypes">dataTypes</a> and <code>type.info</code>.</li>
</ul></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.6.1/lib/encoder.js#L2290" target="_blank" rel="noopener">encoder.js, line 2290</a></p></div>













<h5>Throws:</h5>

        

<dl>
    <dt>
        <div class="param-desc">
        <p>When there is an encoding error</p>
        </div>
    </dt>
    <dd></dd>
    <dt>
        <dl>
            <dt>
                Type
            </dt>
            <dd>
                
<span class="param-type">TypeError</span>


            </dd>
        </dl>
    </dt>
    <dd></dd>
</dl>


    


<h5>Returns:</h5>

        
<div class="param-desc">
    <p>Returns <code>null</code> for null values, <code>undefined</code> for unset values and buffer for all other values.</p>
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Buffer</span>
|

<span class="param-type">null</span>
|

<span class="param-type">undefined</span>


    </dd>
</dl></div>
