src/SerializeHandler.h
branchv_0
changeset 2 d2ba14aa4e20
parent 1 c0a1a008982c
child 3 9e16e31fa756
equal deleted inserted replaced
1:c0a1a008982c 2:d2ba14aa4e20
    85 		relationContext = RelationContext();
    85 		relationContext = RelationContext();
    86 
    86 
    87 		relationContext.name = name;
    87 		relationContext.name = name;
    88 		relationContext.readerMetadata = attributes;
    88 		relationContext.readerMetadata = attributes;
    89 
    89 
    90 		recordContext = RecordContext();
       
    91 		recordContext.writer.reset(relpipe::writer::Factory::create(recordContext.buffer));
       
    92 
       
    93 		for (relpipe::reader::handlers::AttributeMetadata readerMetadata : attributes) {
    90 		for (relpipe::reader::handlers::AttributeMetadata readerMetadata : attributes) {
    94 			relationContext.writerMetadata.push_back({readerMetadata.getAttributeName(), writer->toTypeId(readerMetadata.getTypeName())});
    91 			relationContext.writerMetadata.push_back({readerMetadata.getAttributeName(), writer->toTypeId(readerMetadata.getTypeName())});
    95 		}
    92 		}
    96 	}
    93 	}
    97 
    94 
    98 	void attribute(const relpipe::common::type::StringX& value) override {
    95 	void attribute(const relpipe::common::type::StringX& value) override {
    99 		if (recordContext.attributeIndex == 0) {
    96 		if (recordContext.attributeIndex == 0) {
       
    97 			recordContext = RecordContext();
       
    98 			recordContext.writer.reset(relpipe::writer::Factory::create(recordContext.buffer));
   100 			recordContext.writer->startRelation(relationContext.name, relationContext.writerMetadata, true);
    99 			recordContext.writer->startRelation(relationContext.name, relationContext.writerMetadata, true);
   101 		}
   100 		}
   102 
   101 
   103 		recordContext.writer->writeAttribute(value); // TODO: typed values instead of strings
   102 		recordContext.writer->writeAttribute(value); // TODO: typed values instead of strings
   104 		recordContext.attributeIndex++;
   103 		recordContext.attributeIndex++;
   105 
   104 
   106 		if (recordContext.attributeIndex % relationContext.readerMetadata.size() == 0) {
   105 		if (recordContext.attributeIndex % relationContext.readerMetadata.size() == 0) {
   107 			writer->writeAttribute(toHex(recordContext.buffer.str()));
   106 			writer->writeAttribute(toHex(recordContext.buffer.str()));
   108 			recordContext = RecordContext();
   107 			recordContext.attributeIndex = 0;
   109 			recordContext.writer.reset(relpipe::writer::Factory::create(recordContext.buffer));
       
   110 		}
   108 		}
   111 	}
   109 	}
   112 
   110 
   113 	void endOfPipe() {
   111 	void endOfPipe() {
   114 		// TODO: check number of attribute values
   112 		// TODO: check number of attribute values