Esempio n. 1
0
   void to_stream( T& os, const variant& v, json::output_formatting format )
   {
      switch( v.get_type() )
      {
         case variant::null_type:
              os << "null";
              return;
         case variant::int64_type:
         {
              int64_t i = v.as_int64();
              if( format == json::stringify_large_ints_and_doubles &&
                  i > 0xffffffff )
                 os << '"'<<v.as_string()<<'"';
              else
                 os << i;

              return;
         }
         case variant::uint64_type:
         {
              uint64_t i = v.as_uint64();
              if( format == json::stringify_large_ints_and_doubles &&
                  i > 0xffffffff )
                 os << '"'<<v.as_string()<<'"';
              else
                 os << i;

              return;
         }
         case variant::double_type:
              if (format == json::stringify_large_ints_and_doubles)
                 os << '"'<<v.as_string()<<'"';
              else
                 os << v.as_string();
              return;
         case variant::bool_type:
              os << v.as_string();
              return;
         case variant::string_type:
              escape_string( v.get_string(), os );
              return;
         case variant::blob_type:
              escape_string( v.as_string(), os );
              return;
         case variant::array_type:
           {
              const variants&  a = v.get_array();
              to_stream( os, a, format );
              return;
           }
         case variant::object_type:
           {
              const variant_object& o =  v.get_object();
              to_stream(os, o, format );
              return;
           }
      }
   }
Esempio n. 2
0
 void to_stream( T& os, const variant& v, json::output_formatting format, uint32_t max_depth )
 {
    FC_ASSERT( max_depth > 0, "Too many nested objects!" );
    switch( v.get_type() )
    {
       case variant::null_type:
            os << "null";
            return;
       case variant::int64_type:
            if( format == json::stringify_large_ints_and_doubles &&
                ( v.as_int64() > INT32_MAX || v.as_int64() < INT32_MIN ) )
               os << '"'<<v.as_string()<<'"';
            else
               os << v.as_int64();
            return;
       case variant::uint64_type:
            if( format == json::stringify_large_ints_and_doubles &&
                v.as_uint64() > 0xffffffff )
               os << '"'<<v.as_string()<<'"';
            else
               os << v.as_uint64();
            return;
       case variant::double_type:
            if (format == json::stringify_large_ints_and_doubles)
               os << '"'<<v.as_string()<<'"';
            else
               os << v.as_string();
            return;
       case variant::bool_type:
            os << v.as_string();
            return;
       case variant::string_type:
            escape_string( v.get_string(), os );
            return;
       case variant::blob_type:
            escape_string( v.as_string(), os );
            return;
       case variant::array_type:
            to_stream( os, v.get_array(), format, max_depth - 1 );
            return;
       case variant::object_type:
            to_stream(os, v.get_object(), format, max_depth - 1 );
            return;
       default:
          FC_THROW_EXCEPTION( fc::invalid_arg_exception, "Unsupported variant type: ${type}", ( "type", v.get_type() ) );
    }
 }