* @param AvroIO $io * @param AvroIODatumWriter $datum_writer * @param AvroSchema $writers_schema * @param string $codec */
($io, $datum_writer, $writers_schema = null, $codec = AvroDataIO::NULL_CODEC)
| 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. |
nothing calls this directly
no test coverage detected