16 [Trait(
"Category",
"WireFormat")]
19 #region Varint Encoding Tests 27 [InlineData(0,
new byte[] { 0x00 })]
28 [InlineData(1,
new byte[] { 0x02 })]
29 [InlineData(-1,
new byte[] { 0x01 })]
30 [InlineData(2,
new byte[] { 0x04 })]
31 [InlineData(-2,
new byte[] { 0x03 })]
32 [InlineData(63,
new byte[] { 0x7E })]
33 [InlineData(64,
new byte[] { 0x80, 0x01 })]
34 [InlineData(-64,
new byte[] { 0x7F })]
35 [InlineData(127,
new byte[] { 0xFE, 0x01 })]
36 [InlineData(-128,
new byte[] { 0xFF, 0x01 })]
37 [InlineData(8191,
new byte[] { 0xFE, 0x7F })]
38 [InlineData(8192,
new byte[] { 0x80, 0x80, 0x01 })]
39 [InlineData(
int.MaxValue,
new byte[] { 0xFE, 0xFF, 0xFF, 0xFF, 0x0F })]
40 [InlineData(
int.MinValue,
new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x0F })]
44 byte[] buffer =
new byte[10];
48 position =
kinetica.AvroEncoding.WriteVarInt(buffer, position, value);
51 byte[] actualBytes = buffer.Take(position).ToArray();
52 Assert.Equal(expectedBytes, actualBytes);
59 [InlineData(0L,
new byte[] { 0x00 })]
60 [InlineData(1L,
new byte[] { 0x02 })]
61 [InlineData(-1L,
new byte[] { 0x01 })]
62 [InlineData(
long.MaxValue,
new byte[] { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 })]
63 [InlineData(
long.MinValue,
new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 })]
67 byte[] buffer =
new byte[10];
71 position =
kinetica.AvroEncoding.WriteVarLong(buffer, position, value);
74 byte[] actualBytes = buffer.Take(position).ToArray();
75 Assert.Equal(expectedBytes, actualBytes);
80 #region Simple Type Encoding Tests 120 byte[] expectedBytes =
124 0xC3, 0xF5, 0x48, 0x40,
125 0x58, 0x39, 0xB4, 0xC8, 0x76, 0xBE, 0x05, 0x40,
127 0x08, 0x74, 0x65, 0x73, 0x74
131 var ktype = CreateSimpleRecordType();
135 byte[] actualBytes = encoder.Encode(record);
138 Assert.Equal(expectedBytes, actualBytes);
165 byte[] expectedBytes =
169 0x00, 0x00, 0x00, 0x00,
170 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175 var ktype = CreateSimpleRecordType();
179 byte[] actualBytes = encoder.Encode(record);
182 Assert.Equal(expectedBytes, actualBytes);
197 DoubleField = -2.718,
203 byte[] expectedBytes =
207 0xC3, 0xF5, 0x48, 0xC0,
208 0x58, 0x39, 0xB4, 0xC8, 0x76, 0xBE, 0x05, 0xC0,
213 var ktype = CreateSimpleRecordType();
217 byte[] actualBytes = encoder.Encode(record);
220 Assert.Equal(expectedBytes, actualBytes);
232 StringField =
"Hello™" 237 byte[] expectedStringBytes =
240 0x48, 0x65, 0x6C, 0x6C, 0x6F,
245 byte[] expectedBytes =
249 0x00, 0x00, 0x00, 0x00,
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 0x10, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0xE2, 0x84, 0xA2
255 var ktype = CreateSimpleRecordType();
259 byte[] actualBytes = encoder.Encode(record);
262 Assert.Equal(expectedBytes, actualBytes);
267 #region Nullable Type Encoding Tests 291 NullableString =
null 296 byte[] expectedBytes =
303 var ktype = CreateNullableRecordType();
307 byte[] actualBytes = encoder.Encode(record);
310 Assert.Equal(expectedBytes, actualBytes);
324 NullableString =
"test" 329 byte[] expectedBytes =
333 0x02, 0x08, 0x74, 0x65, 0x73, 0x74
336 var ktype = CreateNullableRecordType();
340 byte[] actualBytes = encoder.Encode(record);
343 Assert.Equal(expectedBytes, actualBytes);
348 #region Helper Methods 355 string schemaJson =
@"{ 356 ""type"": ""record"", 357 ""name"": ""SimpleRecord"", 359 {""name"": ""IntField"", ""type"": ""int""}, 360 {""name"": ""LongField"", ""type"": ""long""}, 361 {""name"": ""FloatField"", ""type"": ""float""}, 362 {""name"": ""DoubleField"", ""type"": ""double""}, 363 {""name"": ""BoolField"", ""type"": ""boolean""}, 364 {""name"": ""StringField"", ""type"": ""string""} 376 string schemaJson =
@"{ 377 ""type"": ""record"", 378 ""name"": ""NullableRecord"", 380 {""name"": ""NullableInt"", ""type"": [""null"", ""int""]}, 381 {""name"": ""NullableLong"", ""type"": [""null"", ""long""]}, 382 {""name"": ""NullableString"", ""type"": [""null"", ""string""]} 391 #region Regression Tests 397 [InlineData(16383,
new byte[] { 0xFE, 0xFF, 0x01 })]
398 [InlineData(2097151,
new byte[] { 0xFE, 0xFF, 0xFF, 0x01 })]
399 [InlineData(2097152,
new byte[] { 0x80, 0x80, 0x80, 0x02 })]
403 byte[] buffer =
new byte[10];
406 int position =
kinetica.AvroEncoding.WriteVarInt(buffer, 0, value);
409 byte[] actualBytes = buffer.Take(position).ToArray();
410 Assert.Equal(expectedBytes, actualBytes);
421 var ktype = CreateSimpleRecordType();
425 byte[] encoded = encoder.Encode(record);
428 Assert.Equal(0x00, encoded[^1]);
438 var longString =
new string(
'A', 1000);
439 var record =
new SimpleRecord { StringField = longString };
440 var ktype = CreateSimpleRecordType();
444 byte[] encoded = encoder.Encode(record);
450 int stringStart = 15;
451 Assert.Equal(0xD0, encoded[stringStart]);
452 Assert.Equal(0x0F, encoded[stringStart + 1]);
455 Assert.Equal(stringStart + 2 + 1000, encoded.Length);