Skip to content

Commit bd46ee7

Browse files
committed
Merge branch '2.x' into 3.x
2 parents 9984267 + bae203c commit bd46ee7

File tree

5 files changed

+81
-7
lines changed

5 files changed

+81
-7
lines changed

.github/workflows/dep_build_v2.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
with:
2424
ref: 2.x
2525
- name: Set up JDK
26-
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
26+
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
2727
with:
2828
distribution: 'temurin'
2929
java-version: ${{ matrix.java_version }}

.github/workflows/dep_build_v3.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
with:
2424
ref: 3.x
2525
- name: Set up JDK
26-
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
26+
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
2727
with:
2828
distribution: 'temurin'
2929
java-version: ${{ matrix.java_version }}

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
steps:
2828
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2929
- name: Set up JDK
30-
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
30+
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
3131
with:
3232
distribution: 'temurin'
3333
java-version: ${{ matrix.java_version }}
@@ -55,7 +55,7 @@ jobs:
5555
run: ./mvnw -B -q -ff -ntp test
5656
- name: Publish code coverage
5757
if: ${{ matrix.release_build && github.event_name != 'pull_request' }}
58-
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
58+
uses: codecov/codecov-action@fdcc8476540edceab3de004e990f80d881c6cc00 # v5.5.0
5959
with:
6060
token: ${{ secrets.CODECOV_TOKEN }}
6161
files: ./target/site/jacoco/jacoco.xml

smile/src/test/java/tools/jackson/dataformat/smile/gen/SmileGeneratorNumbersTest.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void testFloatUnusedBits() throws Exception
153153
assertArrayEquals(new byte[] {
154154
0x08, 0x00, 0x00, 0x00, 0x00
155155
}, Arrays.copyOfRange(encoded, 1, encoded.length));
156-
}
156+
}
157157

158158
// [dataformats-binary#300]
159159
@Test
@@ -202,4 +202,46 @@ public void testNumbersAsString() throws Exception
202202
gen.close();
203203
assertEquals(10, out.toByteArray().length);
204204
}
205+
206+
// [dataformats-binary#608]
207+
@Test
208+
public void testFloat32FromSpecEncoding() throws Exception
209+
{
210+
final float f32 = 29.9510f;
211+
assertEquals(0x41ef9ba6, Float.floatToIntBits(f32));
212+
213+
ByteArrayOutputStream out = new ByteArrayOutputStream();
214+
try (SmileGenerator gen = smileGenerator(out, false)) {
215+
gen.writeNumber(f32);
216+
}
217+
byte[] encoded = out.toByteArray();
218+
assertEquals(6, encoded.length);
219+
assertEquals(0x28, encoded[0]); // type byte, float
220+
221+
// From 0x80 0x00 0x00 0x00 (spread over 5 x 7bits)
222+
assertArrayEquals(new byte[] {
223+
0x04, 0x0f, 0x3e, 0x37, 0x26
224+
}, Arrays.copyOfRange(encoded, 1, encoded.length));
225+
}
226+
227+
// [dataformats-binary#608]
228+
@Test
229+
public void testDouble64FromSpecEncoding() throws Exception
230+
{
231+
final double d64 = -29.9510;
232+
assertEquals(0xc03df374bc6a7efaL, Double.doubleToLongBits(d64));
233+
234+
ByteArrayOutputStream out = new ByteArrayOutputStream();
235+
try (SmileGenerator gen = smileGenerator(out, false)) {
236+
gen.writeNumber(d64);
237+
}
238+
byte[] encoded = out.toByteArray();
239+
assertEquals(11, encoded.length);
240+
assertEquals(0x29, encoded[0]); // type byte, float
241+
242+
// From 0x80 0x00 0x00 0x00 (spread over 5 x 7bits)
243+
assertArrayEquals(new byte[] {
244+
0x01, 0x40, 0x1e, 0x7c, 0x6e, 0x4b, 0x63, 0x29, 0x7d, 0x7a
245+
}, Arrays.copyOfRange(encoded, 1, encoded.length));
246+
}
205247
}

smile/src/test/java/tools/jackson/dataformat/smile/parse/SmileNumberParsingTest.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public void testArrayWithInts() throws IOException
215215
}
216216

217217
@Test
218-
public void testFloats() throws IOException
218+
public void testFloats() throws Exception
219219
{
220220
ByteArrayOutputStream bo = new ByteArrayOutputStream();
221221
SmileGenerator g = _smileGenerator(bo, false);
@@ -241,7 +241,7 @@ public void testFloats() throws IOException
241241
}
242242

243243
@Test
244-
public void testDoubles() throws IOException
244+
public void testDoubles() throws Exception
245245
{
246246
ByteArrayOutputStream bo = new ByteArrayOutputStream();
247247
SmileGenerator g = _smileGenerator(bo, false);
@@ -266,6 +266,38 @@ public void testDoubles() throws IOException
266266
p.close();
267267
}
268268

269+
// [dataformats-binary#608]
270+
@Test
271+
public void testFloat32FromSpecEncoding() throws Exception {
272+
final float f32 = 29.9510f;
273+
ByteArrayOutputStream out = new ByteArrayOutputStream();
274+
try (SmileGenerator gen = smileGenerator(out, false)) {
275+
gen.writeNumber(f32);
276+
}
277+
try (SmileParser p = _smileParser(out.toByteArray())) {
278+
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
279+
assertEquals(JsonParser.NumberType.FLOAT, p.getNumberType());
280+
assertEquals(f32, p.getFloatValue());
281+
assertNull(p.nextToken());
282+
}
283+
}
284+
285+
// [dataformats-binary#608]
286+
@Test
287+
public void testDouble64FromSpecEncoding() throws Exception {
288+
final double d64 = -29.9510;
289+
ByteArrayOutputStream out = new ByteArrayOutputStream();
290+
try (SmileGenerator gen = smileGenerator(out, false)) {
291+
gen.writeNumber(d64);
292+
}
293+
try (SmileParser p = _smileParser(out.toByteArray())) {
294+
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
295+
assertEquals(JsonParser.NumberType.DOUBLE, p.getNumberType());
296+
assertEquals(d64, p.getDoubleValue());
297+
assertNull(p.nextToken());
298+
}
299+
}
300+
269301
@Test
270302
public void testArrayWithDoubles() throws IOException
271303
{

0 commit comments

Comments
 (0)