[FAST-25] Integer fields cannot encode value 16384 (2^14) Created: 13/Oct/09  Updated: 15/Feb/11

Status: Open
Project: OpenFAST
Component/s: Operators, Types
Affects Version/s: 1.0.0
Fix Version/s: None

Type: Bug Priority: Critical
Reporter: Alexander Kosenkov Assignee: Jacob Northey
Resolution: Unresolved Votes: 1
Labels: None


 Description   

Value 16384 is not encoded as 16385.
It seems that there's a problem in org.openfast.template.type.codec.IntegerCodec.getUnsignedIntegerSize().



 Comments   
Comment by Alexander Kosenkov [ 13/Oct/09 ]

public class IntegerCodecTest {

@Test
public void test16384()

{ final UnsignedInteger codec = new UnsignedInteger(); test(codec, 15); test(codec, 16); test(codec, 16385); test(codec, 16384); // FAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 }

private void test(UnsignedInteger codec, int expected)

{ final byte[] bytes = codec.encode(new IntegerValue(expected)); final ScalarValue value = codec.decode(new ByteArrayInputStream(bytes)); final int actual = value.toInt(); Assert.assertEquals("encoding " + expected,expected,actual); }

}

Comment by Alexander Kosenkov [ 13/Oct/09 ]

You should replace "<=" with "<" in getUnsignedIntegerSize()

Comment by Brian Davis [ 15/Feb/11 ]

Alexander's comment is true for all predicates in getUnsignedIntegerSize(). Here is the current implementation (checked out from SVN trunk on 15-Feb-2011):

/**

  • @param value
  • The long to determine the unsigned integer
  • @return Returns an unsigned integer
    */
    public static int getUnsignedIntegerSize(long value)
    Unknown macro: { if (value < 128) { return 1; // 2 ^ 7 } if (value <= 16384) { return 2; // 2 ^ 14 } if (value <= 2097152) { return 3; // 2 ^ 21 } if (value <= 268435456) { return 4; // 2 ^ 28 } if (value <= 34359738368L) { return 5; // 2 ^ 35 } if (value <= 4398046511104L) { return 6; // 2 ^ 42 } if (value <= 562949953421312L) { return 7; // 2 ^ 49 } if (value <= 72057594037927936L) { return 8; // 2 ^ 56 } return 9; }

Here is the equivalent function from the C language reference implementation available from the FIX protocol website (http://www.fixprotocol.org/documents/2317/fastapi-1.0.zip, fastapi-1.0/fastapi.c):

static int u32_to_size (u32 data)
{
if (data < 0x00000080) return 1; // 128
if (data < 0x00004000) return 2; // 16384
if (data < 0x00200000) return 3; // 2097152
if (data < 0x10000000) return 4; // 268435456

return 5;
}

Generated at Sat Nov 23 18:24:42 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.