MCPcopy Create free account
hub / github.com/apache/avro / __construct

Method __construct

lang/php/lib/DataFile/AvroDataIOWriter.php:80–115  ·  view source on GitHub ↗

* @param AvroIO $io * @param AvroIODatumWriter $datum_writer * @param AvroSchema $writers_schema * @param string $codec */

($io, $datum_writer, $writers_schema = null, $codec = AvroDataIO::NULL_CODEC)

Source from the content-addressed store, hash-verified

78 * @param string $codec
79 */
80 public function __construct($io, $datum_writer, $writers_schema = null, $codec = AvroDataIO::NULL_CODEC)
81 {
82 if (!($io instanceof AvroIO)) {
83 throw new AvroDataIOException('io must be instance of AvroIO');
84 }
85
86 $this->io = $io;
87 $this->encoder = new AvroIOBinaryEncoder($this->io);
88 $this->datum_writer = $datum_writer;
89 $this->buffer = new AvroStringIO();
90 $this->buffer_encoder = new AvroIOBinaryEncoder($this->buffer);
91 $this->block_count = 0;
92 $this->metadata = array();
93
94 if ($writers_schema) {
95 if (!AvroDataIO::isValidCodec($codec)) {
96 throw new AvroDataIOException(
97 sprintf('codec %s is not supported', $codec)
98 );
99 }
100
101 $this->sync_marker = self::generateSyncMarker();
102 $this->metadata[AvroDataIO::METADATA_CODEC_ATTR] = $this->codec = $codec;
103 $this->metadata[AvroDataIO::METADATA_SCHEMA_ATTR] = (string) $writers_schema;
104 $this->writeHeader();
105 } else {
106 $dfr = new AvroDataIOReader($this->io, new AvroIODatumReader());
107 $this->sync_marker = $dfr->sync_marker;
108 $this->metadata[AvroDataIO::METADATA_CODEC_ATTR] = $this->codec
109 = $dfr->metadata[AvroDataIO::METADATA_CODEC_ATTR];
110 $schema_from_file = $dfr->metadata[AvroDataIO::METADATA_SCHEMA_ATTR];
111 $this->metadata[AvroDataIO::METADATA_SCHEMA_ATTR] = $schema_from_file;
112 $this->datum_writer->writersSchema = AvroSchema::parse($schema_from_file);
113 $this->seek(0, SEEK_END);
114 }
115 }
116
117 /**
118 * @returns string a new, unique sync marker.

Callers

nothing calls this directly

Calls 5

generateSyncMarkerMethod · 0.95
writeHeaderMethod · 0.95
seekMethod · 0.95
isValidCodecMethod · 0.80
parseMethod · 0.65

Tested by

no test coverage detected