diff --git a/src/Server/buftest.cxx b/src/Server/buftest.cxx index f7bbe0547..46bddf47e 100644 --- a/src/Server/buftest.cxx +++ b/src/Server/buftest.cxx @@ -1,19 +1,11 @@ #include "message.hxx" -main(int argc, char **argv) +void dumpmessage(string msg) { - FGMPSMessageBuf buf1, buf2; + FGMPSMessageBuf buf; - buf1.clr(); - buf1.put(fgmps_som8, true); - buf1.put(1); - for (int i=0; i<256; i++) { - buf1.put(fgmps_uchar, true); - buf1.put(i); - } - buf1.put(fgmps_eom, true); - - buf2.set(buf1.str()); + buf.set(msg); + buf.ofs(0); bool done=false; while (!done) { @@ -29,17 +21,17 @@ main(int argc, char **argv) double vald; string vals; printf("dump: "); - for (int i=0; i<16; i++) printf("%02x ", buf2.peek(i)); + for (int i=0; i<16; i++) printf("%02x ", buf.peek(i)); printf("\n"); try { - int tag = buf2.get(true); + int tag = buf.get(true); switch (tag) { case fgmps_som8: - mid8 = *(unsigned char *)buf2.read1(); + mid8 = *(unsigned char *)buf.read1(); printf("Start Message ID = %02x\n", mid8); break; case fgmps_som16: - mid16 = *(unsigned int *)buf2.read2(); + mid16 = *(unsigned int *)buf.read2(); printf("Start Message ID = %04x\n", mid16); break; case fgmps_eom: @@ -47,28 +39,102 @@ main(int argc, char **argv) done = true; break; case fgmps_uchar: - uval8 = *(unsigned char *)buf2.read1(); + uval8 = *(unsigned char *)buf.read1(); printf("uchar = %02x\n", uval8); break; case fgmps_uint: - uval16 = *(unsigned int *)buf2.read2(); + uval16 = *(unsigned int *)buf.read2(); printf("uint = %04x\n", uval16); break; case fgmps_ulong: - uval32 = *(unsigned long *)buf2.read4(); + uval32 = *(unsigned long *)buf.read4(); printf("ulong = %08lx\n", uval32); break; case fgmps_ulonglong: - uval64 = *(unsigned long long *)buf2.read8(); + uval64 = *(unsigned long long *)buf.read8(); printf("ulonglong = %16llx\n", uval64); break; + case fgmps_char: + val8 = *(char *)buf.read1(); + printf("char = %02x\n", val8); + break; + case fgmps_int: + val16 = *(int *)buf.read2(); + printf("int = %04x\n", val16); + break; + case fgmps_long: + val32 = *(long *)buf.read4(); + printf("long = %08lx\n", val32); + break; + case fgmps_longlong: + val64 = *(long long *)buf.read8(); + printf("longlong = %16llx\n", val64); + break; + case fgmps_float: + valf = buf.readf(); + printf("float = %f\n", valf); + break; + case fgmps_double: + vald = buf.readd(); + printf("double = %g\n", vald); + break; + case fgmps_string: + uval8 = buf.get(); + vals = buf.reads(uval8); + printf("string = %s\n", vals.c_str()); + break; default: printf("Unknown prefix = %02x\n", tag); done = true; break; } } catch (FGMPSDataException e) { + printf("Data Exception\n"); done = true; } } } + +main(int argc, char **argv) +{ + FGMPSMessageBuf buf; + + unsigned char uval8; + unsigned int uval16; + unsigned long uval32; + unsigned long long uval64; + char val8; + int val16; + long val32; + long long val64; + float valf; + double vald; + string vals; + + buf.clr(); + buf.put(fgmps_som8, true); + buf.put(1); + for (int i=0; i<256; i++) { + buf.put(fgmps_uchar, true); + buf.put(i); + } + buf.put(fgmps_eom, true); + dumpmessage(buf.str()); + + buf.clr(); + buf.put(fgmps_som8, true); buf.put(1); + + uval8 = 251; buf.put(fgmps_uchar, true); buf.write1(&uval8); + uval16 = 34567; buf.put(fgmps_uint, true); buf.write2(&uval16); + uval32 = 1345678901; buf.put(fgmps_ulong, true); buf.write4(&uval32); + //uval64 = 9999999999; buf.put(fgmps_ulonglong, true); buf.write8(&uval64); + val8 = -120; buf.put(fgmps_char, true); buf.write1(&val8); + val16 = -17890; buf.put(fgmps_int, true); buf.write2(&val16); + val32 = -1345678901; buf.put(fgmps_long, true); buf.write4(&val32); + //val64 = -9999999999; buf.put(fgmps_longlong, true); buf.write8(&val64); + valf = 2 * 3.14; buf.put(fgmps_float, true); buf.writef(valf); + vald = 3 * 3.1415927; buf.put(fgmps_double, true); buf.writed(vald); + vals = "hi there"; buf.put(fgmps_string, true); buf.writes(vals); + buf.put(fgmps_eom, true); + dumpmessage(buf.str()); +} diff --git a/src/Server/messagebuf.cxx b/src/Server/messagebuf.cxx index f5ff9f218..b63509e25 100644 --- a/src/Server/messagebuf.cxx +++ b/src/Server/messagebuf.cxx @@ -72,6 +72,7 @@ void FGMPSMessageBuf::writed(double data) void FGMPSMessageBuf::writes(string data) { + put(data.length()); for (int i=0; i