Skip to content

Commit daef609

Browse files
committed
#795 Use big-endian RDWs when generating VRL file.
1 parent 61cb376 commit daef609

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/processor/impl/CobolProcessorToRdw.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import java.io.OutputStream
2626
/**
2727
* Implementation of the CobolProcessor trait, responsible for processing COBOL data streams
2828
* by extracting records and applying a user-defined raw record processor. This processor
29-
* converts the input format to the variable record length format with little-endian RDW records.
29+
* converts the input format to the variable record length format with big-endian RDW records.
3030
*
3131
* Please, do not use this class directly. Use `CobolProcessor.builder()` instead.
3232
*

cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/processor/impl/StreamProcessor.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ object StreamProcessor {
7070
}
7171

7272
/**
73-
* Processes a stream of COBOL raw records and writes it back as a variable length format with little-endian RDW headers.
73+
* Processes a stream of COBOL raw records and writes it back as a variable length format with big-endian RDW headers.
7474
*
7575
* @param copybook the COBOL copybook that describes the schema of the records.
7676
* @param options arbitrary options used for splitting input data into records (same as 'spark-cobol' options).
@@ -96,7 +96,7 @@ object StreamProcessor {
9696

9797
val updatedRecord = recordProcessor.processRecord(record, ctx)
9898

99-
val rdw = Array[Byte](0, 0, ((updatedRecord.length) & 0xFF).toByte, (((updatedRecord.length) >> 8) & 0xFF).toByte)
99+
val rdw = Array[Byte](((updatedRecord.length >> 8) & 0xFF).toByte, ((updatedRecord.length) & 0xFF).toByte, 0, 0)
100100

101101
outputStream.write(rdw)
102102
outputStream.write(updatedRecord)

cobol-parser/src/test/scala/za/co/absa/cobrix/cobol/processor/impl/CobolProcessorToRdwSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CobolProcessorToRdwSuite extends AnyWordSpec {
5353
assert(count == 4)
5454
assert(outputArray.length == 24)
5555
assert(outputArray.sameElements(
56-
Array(0, 0, 2, 0, -16, -16, 0, 0, 2, 0, -15, -15, 0, 0, 2, 0, -14, -14, 0, 0, 2, 0, -13, -13)
56+
Array(0, 2, 0, 0, -16, -16, 0, 2, 0, 0, -15, -15, 0, 2, 0, 0, -14, -14, 0, 2, 0, 0, -13, -13)
5757
))
5858
}
5959
}

spark-cobol/src/test/scala/za/co/absa/cobrix/spark/cobol/SparkCobolProcessorSuite.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ class SparkCobolProcessorSuite extends AnyWordSpec with SparkTestBase with Binar
130130
val outputData = readBinaryFile(outputFile)
131131

132132
assert(outputData.sameElements(
133-
Array(0, 0, 1, 0, -16, 0, 0, 1, 0, -15, 0, 0, 1, 0, -14, 0, 0, 1, 0, -13).map(_.toByte)
133+
Array(0, 1, 0, 0, -16, 0, 1, 0, 0, -15, 0, 1, 0, 0, -14, 0, 1, 0, 0, -13).map(_.toByte)
134134
))
135135

136136
val actual = spark.read
137137
.format("cobol")
138138
.option("copybook_contents", copybook)
139139
.option("record_format", "V")
140+
.option("is_rdw_big_endian", "true")
141+
.option("pedantic", "true")
140142
.load(outputFile)
141143
.toJSON
142144
.collect()

0 commit comments

Comments
 (0)