예제 #1
0
 inline void marshall_json(rapidjson::Writer<rapidjson::StringBuffer>& writer, const cluster_info& info)
 {
     writer.StartObject();
     writer.String("name"); marshall_json(writer, info.name);
     writer.String("type"); marshall_json(writer, info.type);
     writer.EndObject();
 };
예제 #2
0
void Serializer::WriteMessageField(google::protobuf::Message const& value, google::protobuf::FieldDescriptor const* field)
{
    _writer.Key(field->name().c_str());
    if (field->is_repeated())
    {
        _writer.StartArray();
        WriteRepeatedMessageField(value, field);
        _writer.EndArray();
    }
    else
        WriteSimpleMessageField(value, field);
}
예제 #3
0
void Serializer::WriteMessage(google::protobuf::Message const& value)
{
    google::protobuf::Reflection const* reflection = value.GetReflection();
    std::vector<google::protobuf::FieldDescriptor const*> fields;
    reflection->ListFields(value, &fields);

    _writer.StartObject();
    for (std::size_t i = 0; i < fields.size(); ++i)
        WriteMessageField(value, fields[i]);

    _writer.EndObject();
}
예제 #4
0
void Serializer::WriteRepeatedMessageField(google::protobuf::Message const& value, google::protobuf::FieldDescriptor const* field)
{
    google::protobuf::Reflection const* reflection = value.GetReflection();
    for (int32 i = 0; i < reflection->FieldSize(value, field); ++i)
    {
        switch (field->cpp_type())
        {
            case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
                WriteInt32(reflection->GetRepeatedInt32(value, field, i));
                break;
            case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
                WriteInt64(reflection->GetRepeatedInt64(value, field, i));
                break;
            case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
                WriteUInt32(reflection->GetRepeatedUInt32(value, field, i));
                break;
            case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
                WriteUInt64(reflection->GetRepeatedUInt64(value, field, i));
                break;
            case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
                WriteDouble(reflection->GetRepeatedDouble(value, field, i));
                break;
            case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
                WriteFloat(reflection->GetRepeatedFloat(value, field, i));
                break;
            case google::protobuf::FieldDescriptor::CPPTYPE_BOOL:
                WriteBool(reflection->GetRepeatedBool(value, field, i));
                break;
            case google::protobuf::FieldDescriptor::CPPTYPE_ENUM:
                WriteEnum(reflection->GetRepeatedEnum(value, field, i));
                break;
            case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
            {
                std::string strValue = reflection->GetRepeatedString(value, field, i);
                if (field->type() == google::protobuf::FieldDescriptor::TYPE_STRING)
                    WriteString(strValue);
                else
                {
                    _writer.StartArray();
                    for (std::size_t j = 0; j < strValue.length(); ++j)
                        WriteUInt32(uint32(strValue[j]));
                    _writer.EndArray();
                }
                break;
            }
            case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE:
                WriteMessage(reflection->GetRepeatedMessage(value, field, i));
                break;
            default:
                break;
        }
    }
}
예제 #5
0
 inline void marshall_json(rapidjson::Writer<rapidjson::StringBuffer>& writer, const deploy_info& info)
 {
     writer.StartObject();
     writer.String("cluster"); marshall_json(writer, info.cluster);
     writer.String("error"); marshall_json(writer, info.error);
     writer.String("name"); marshall_json(writer, info.name);
     writer.String("package_id"); marshall_json(writer, info.package_id);
     writer.String("service_url"); marshall_json(writer, info.service_url);
     writer.String("status"); marshall_json(writer, info.status);
     writer.EndObject();
 };
 void RequestActionReturnableLongPolling_GetZoneMediaList::addMediaListToJson(const std::string &_zoneUDN, std::vector<std::shared_ptr<Raumkernel::Media::Item::MediaItem>> &_mediaList, rapidjson::Writer<rapidjson::StringBuffer> &_jsonWriter)
 {          
     _jsonWriter.StartObject();
     _jsonWriter.Key("udn"); _jsonWriter.String(_zoneUDN.c_str());
     _jsonWriter.Key("items");
     _jsonWriter.StartArray();
     for (auto mediaItem : _mediaList)
     {                
         _jsonWriter.StartObject();
         MediaItemJsonCreator::addJson(mediaItem, _jsonWriter);           
         _jsonWriter.EndObject();
     }
     _jsonWriter.EndArray();
     _jsonWriter.EndObject();
 }
예제 #7
0
void Branch::exportToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer) const {
  writer.StartObject();
    writer.Key("type");
    writer.String("branch");

    writer.Key("sub-nodes");
    writer.StartArray();
    
    for (Node* p : this->sub_nodes) {
      p->exportToJson(writer);
    }

    writer.EndArray();
  writer.EndObject();
}
예제 #8
0
  void Trajectory::json(rapidjson::Writer<rapidjson::StringBuffer>& w) const {
    EpiState x(initialState);
    size_t ntrans = transitionCount();
    double time = 0.0;

    w.StartArray();

    w.StartObject(); {
      w.String("time"); w.Double(time);
      w.String("state"); w.StartArray(); {
        for (size_t j = 0; j < x.numStates(); ++j) w.Int(x[j]);
      } w.EndArray();
    }w.EndObject();

    for (size_t i = 0; i < ntrans; ++i) {
      x += transitions[i].getTrans();
      time += transitions[i].atTime();
      w.StartObject(); {
        w.String("time"); w.Double(time);
        w.String("state"); w.StartArray(); {
          for (size_t j = 0; j < x.numStates(); ++j) w.Int(x[j]);
        } w.EndArray();
      } w.EndObject();
    }

    w.EndArray();
  }
예제 #9
0
inline void Squirrel::serialize(rapidjson::Writer<rapidjson::StringBuffer>& writer) const {
  writer.StartObject();

  writer.Key("key");
  writer.Uint(key);

  writer.Key("name");
  writer.String(name_);

  writer.Key("age");
  writer.Uint(age_);

  writer.Key("occupation");
  writer.String(occupation_);

  writer.Key("created_at");
  long hest = created_at_;
  struct tm* tt =
    gmtime (&hest);
  char datebuf[32];
  strftime(datebuf, sizeof datebuf, "%FT%TZ", tt);
  writer.String(datebuf);

  writer.EndObject();
}
예제 #10
0
 inline void marshall_json(rapidjson::Writer<rapidjson::StringBuffer>& writer, const std::string& str)
 {
     writer.String(str.c_str());
 };
예제 #11
0
 inline void marshall_json(rapidjson::Writer<rapidjson::StringBuffer>& writer, const cluster_type& type)
 {
     writer.String(rm_type_prefix(enum_to_string(type)));
 };
예제 #12
0
void Copy::serialize(rapidjson::PrettyWriter<rapidjson::StringBuffer>& writer) const
#else
void Copy::serialize(rapidjson::Writer<rapidjson::StringBuffer>& writer) const
#endif
{
  writer.StartObject();

  // Result
  writer.String("type");
  writer.String("copy");

  // Output URL
  writer.String("output_url");
  writer.String("file://" + mOutputFile);

  if (mStatus == CopyStatusSuccess)
  {
    // Result
    writer.String("result");
    writer.Bool(true);

  }
  else
  {
    // Result
    writer.String("result");
    writer.Bool(false);

    // Error message
    if ((mStatus == CopyStatusError) &&  !mErrorMessage.empty())
    {
      writer.String("error_message");
      writer.String(mErrorMessage);
    }
  }

  writer.EndObject();
}