예제 #1
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();
  }
예제 #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::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;
        }
    }
}
 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();
 }
예제 #5
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();
}