diff --git a/src/userland/buffersTests/include/buffers.h b/src/userland/buffersTests/include/buffers.h index 003539b..39995d6 100644 --- a/src/userland/buffersTests/include/buffers.h +++ b/src/userland/buffersTests/include/buffers.h @@ -115,20 +115,22 @@ #define STRING_Length_id() STRING_Length #define MAP_Length_id() MAP_Length -#define LENGTH(type, ...) DEFER(type##_Length_id)()(__VA_ARGS__) +#define ARRAY_Length(contents) arrayLength(contents(ONE, +)) + contents(LENGTH, +) +#define MAP_Length(contents) mapLength(contents(ONE, +)) + contents(LENGTH, +) +#define LENGTH(type, ...) DEFER(type##_Length_id)()(__VA_ARGS__) #define _INTEGER_WRITE(x, type, ...) buffer = integerWrite(buffer, x, type); #define INTEGER_Write(x, ...) _INTEGER_WRITE(x, ##__VA_ARGS__ , Unsigned) #define INTEGER_Write_id() INTEGER_Write +#define ARRAY_Write_id() ARRAY_Write + +#define ARRAY_Write(contents) buffer = arrayWrite(buffer, contents(ONE, +)); contents(WRITE, NOTHING) #define WRITE(type, ...) DEFER(type##_Write_id)()(__VA_ARGS__) #define CONTENTS contents (LENGTH, +) -#define ARRAY_Length(contents) arrayLength(contents(ONE, +)) + contents(LENGTH, +) -#define MAP_Length(contents) mapLength(contents(ONE, +)) + contents(LENGTH, +) - #define CREATE(name, definition) \ uint32_t name##Length = EXPAND(definition(LENGTH)); \ void *name = malloc(name##Length); \ diff --git a/src/userland/buffersTests/include/buffers.h b/src/userland/buffersTests/include/buffers.h index 003539b..39995d6 100644 --- a/src/userland/buffersTests/include/buffers.h +++ b/src/userland/buffersTests/include/buffers.h @@ -115,20 +115,22 @@ #define STRING_Length_id() STRING_Length #define MAP_Length_id() MAP_Length -#define LENGTH(type, ...) DEFER(type##_Length_id)()(__VA_ARGS__) +#define ARRAY_Length(contents) arrayLength(contents(ONE, +)) + contents(LENGTH, +) +#define MAP_Length(contents) mapLength(contents(ONE, +)) + contents(LENGTH, +) +#define LENGTH(type, ...) DEFER(type##_Length_id)()(__VA_ARGS__) #define _INTEGER_WRITE(x, type, ...) buffer = integerWrite(buffer, x, type); #define INTEGER_Write(x, ...) _INTEGER_WRITE(x, ##__VA_ARGS__ , Unsigned) #define INTEGER_Write_id() INTEGER_Write +#define ARRAY_Write_id() ARRAY_Write + +#define ARRAY_Write(contents) buffer = arrayWrite(buffer, contents(ONE, +)); contents(WRITE, NOTHING) #define WRITE(type, ...) DEFER(type##_Write_id)()(__VA_ARGS__) #define CONTENTS contents (LENGTH, +) -#define ARRAY_Length(contents) arrayLength(contents(ONE, +)) + contents(LENGTH, +) -#define MAP_Length(contents) mapLength(contents(ONE, +)) + contents(LENGTH, +) - #define CREATE(name, definition) \ uint32_t name##Length = EXPAND(definition(LENGTH)); \ void *name = malloc(name##Length); \ diff --git a/src/userland/buffersTests/main.c b/src/userland/buffersTests/main.c index ada8f69..aff8951 100644 --- a/src/userland/buffersTests/main.c +++ b/src/userland/buffersTests/main.c @@ -224,10 +224,39 @@ } uint32_t arrayLength(uint32_t elementCount) { - // TODO + if ((elementCount & formatInfo[FORMAT_FIXARRAY].readTypeParameter) == elementCount) { + return 1; + } + if ((uint16_t)elementCount == elementCount) { + return 3; + } + if ((uint32_t)elementCount == elementCount) { + return 5; + } + // TODO: 64 bit numbers return 1; } +void *arrayWrite(void *buffer, uint32_t elementCount) { + uint8_t *bufferByte = buffer; + if ((elementCount & formatInfo[FORMAT_FIXARRAY].readTypeParameter) == elementCount) { + *bufferByte = formatInfo[FORMAT_FIXARRAY].min + elementCount; + return buffer + 1; + } + if ((uint16_t)elementCount == elementCount) { + *bufferByte = formatInfo[FORMAT_ARRAY16].min; + *(uint16_t *)(buffer + 1) = (uint16_t) elementCount; + return buffer + 3; + } + if ((uint32_t)elementCount == elementCount) { + *bufferByte = formatInfo[FORMAT_ARRAY32].min; + *(uint32_t *)(buffer + 1) = (uint32_t) elementCount; + return buffer + 5; + } + // TODO: 64 bit numbers + return buffer; +} + uint32_t mapLength(uint32_t elementCount) { // TODO return 1; @@ -236,12 +265,13 @@ #define SAMPLE_1(X) \ X(INTEGER, 500, Signed) -#define SAMPLE_2_ARRAY_CONTENTS(X, S) \ +#define SAMPLE_2_ARRAY_CONTENT(X, S) \ X(INTEGER, 1) S \ - X(STRING, "hi") \ + X(INTEGER, 500, Signed) + // X(STRING, "hi") \ #define SAMPLE_2(X) \ - X(ARRAY, SAMPLE_2_ARRAY_CONTENTS) + X(ARRAY, SAMPLE_2_ARRAY_CONTENT) #define SAMPLE_3_MAP_CONTENTS(X, S) \ X(INTEGER, 1) S \ @@ -257,7 +287,7 @@ initialize(); } printf("dumping test data...\n"); - CREATE(test, SAMPLE_1); + CREATE(test, SAMPLE_2); printf("test 1 length: %i\n", testLength); dumpPack(test, 0); free(test);