This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/main by this push:
     new e62c8ee22 AVRO-1830 [Perl] Support containers without codec (#2965)
e62c8ee22 is described below

commit e62c8ee22132f345aa56f7782811b1e001512b11
Author: José Joaquín Atria <[email protected]>
AuthorDate: Mon Jun 24 12:53:15 2024 +0100

    AVRO-1830 [Perl] Support containers without codec (#2965)
---
 lang/perl/Changes                    |  3 +++
 lang/perl/lib/Avro/DataFileReader.pm |  4 ++--
 lang/perl/t/04_datafile.t            | 17 +++++++++++++++++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/lang/perl/Changes b/lang/perl/Changes
index 83cb2342f..c17ed779b 100644
--- a/lang/perl/Changes
+++ b/lang/perl/Changes
@@ -4,6 +4,9 @@ Revision history for Perl extension Avro
           multiple JSON backends
         - Drop dependency on IO::String, since we don't need
           it now we depend on Perl 5.10.1 or greater
+        - Support object containers without an explicit
+          codec. It will be assumed to be 'null' as mandated
+          by the spec.
 
 1.00  Fri Jan 17 15:00:00 2014
         - Relicense under apache license 2.0
diff --git a/lang/perl/lib/Avro/DataFileReader.pm 
b/lang/perl/lib/Avro/DataFileReader.pm
index e6341cc46..0ef5f02cf 100644
--- a/lang/perl/lib/Avro/DataFileReader.pm
+++ b/lang/perl/lib/Avro/DataFileReader.pm
@@ -55,7 +55,7 @@ sub new {
 
 sub codec {
     my $datafile = shift;
-    return $datafile->metadata->{'avro.codec'};
+    return $datafile->metadata->{'avro.codec'} || 'null';
 }
 
 sub writer_schema {
@@ -99,7 +99,7 @@ sub read_file_header {
     $datafile->{sync_marker} = $data->{sync}
         or croak "sync marker appears invalid";
 
-    my $codec = $data->{meta}{'avro.codec'} || "";
+    my $codec = $data->{meta}{'avro.codec'} || 'null';
 
     throw Avro::DataFile::Error::UnsupportedCodec($codec)
         unless Avro::DataFile->is_codec_valid($codec);
diff --git a/lang/perl/t/04_datafile.t b/lang/perl/t/04_datafile.t
index 281c18f0d..df7861b19 100644
--- a/lang/perl/t/04_datafile.t
+++ b/lang/perl/t/04_datafile.t
@@ -221,4 +221,21 @@ is_deeply $all[0], $data, "Our data is intact!";
     is scalar @next, 0, "no more objects back";
 }
 
+## Test with a datafile that has no codec
+{
+    my $container = join '',
+        "Obj\x{01}",
+        "\x{02}\x{16}avro.schema\x{10}\x{22}string\x{22}\x{00}",
+        "\x{de}\x{ad}\x{be}\x{ef}" x 4,
+        "\x{02}\x{08}\x{06}foo",
+        "\x{de}\x{ad}\x{be}\x{ef}" x 4;
+
+    open my $fh, '<', \$container or die "Could not open memory handle: $!";
+
+    my $reader = Avro::DataFileReader->new( fh => $fh );
+
+    my ($data) = $reader->next(1);
+    is $data, 'foo', 'Can read data from container without a codec';
+}
+
 done_testing;

Reply via email to