ripple/BRRippleSerialize.c
/**
 * Calculate the buffer size needed to store a serialized transaction
 *
 * @param fields      An array of fields
 * @param num_fields  The size of the array
 * @return the size of the buffer needed
 */
Calculate the buffer size needed to store a serialized transaction
@param fields      An array of fields
@param num_fields  The size of the array
@return the size of the buffer needed
Calculate the buffer size needed to store a serialized transaction @param fields An array of fields @param num_fields The size of the array @return the size of the buffer needed
uint32_t calculate_buffer_size(BRRippleField *fields, uint32_t num_fields)
{
    int size = num_fields * 4;
    for(int i = 0; i < num_fields; i++) {
        switch (fields[i].typeCode) {
            case 1:
                size += 2; 
                break;
            case 2:
                size += 4; 
                break;
            case 6:
                size += 8; 
                break;
            case 7:
                if (fields[i].fieldCode == 4) {
                    size += sizeof(fields[i].data.signature.signature);
                    size += 4; 
                } else if (fields[i].fieldCode == 3) {
                    size += sizeof(fields[i].data.publicKey.pubKey);
                    size += 4; 
                }
                break;
            case 8:
                if (fields[i].fieldCode == 1 || fields[i].fieldCode == 3) {
                    size += 21; 
                }
                break;
        }
    }
    return size;
}
uint32_t calculate_buffer_size ( BRRippleField * fields , uint32_t num_fields ) { int size = num_fields * 4 ; for ( int i = 0 ; i < num_fields ; i ++ ) { switch ( fields [ i ] . typeCode ) { case 1 : size += 2 ; break ; case 2 : size += 4 ; break ; case 6 : size += 8 ; break ; case 7 : if ( fields [ i ] . fieldCode == 4 ) { size += sizeof ( fields [ i ] . data . signature . signature ) ; size += 4 ; } else if ( fields [ i ] . fieldCode == 3 ) { size += sizeof ( fields [ i ] . data . publicKey . pubKey ) ; size += 4 ; } break ; case 8 : if ( fields [ i ] . fieldCode == 1 || fields [ i ] . fieldCode == 3 ) { size += 21 ; } break ; } } return size ; }
Calculate the buffer size needed to store a serialized transaction
 @param fields      An array of fields
 @param num_fields  The size of the array
 @return the size of the buffer needed
Calculate the buffer size needed to store a serialized transaction @param fields An array of fields @param num_fields The size of the array @return the size of the buffer needed
// The fieldid is stored as 2-4 bytes. Since a few extra bytes won't hurt // just allocate 4 bytes per field to be safe. // Figure out the approximate size of the buffer we need to make // Add on the potential size of the fieldid // 16-bit integers // 32-bit integers // 64-bit integers // max needed to store length // max needed to store length // Accounts - which is really the address of 20 bytes plus // 1 extra byte for the size. // 20 bytes for the address, 1 for the length