VersionMessage.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package at.acdp.urweb.sclient.data;
  2. import at.acdp.urweb.CountDataInputStream;
  3. import java.io.IOException;
  4. public class VersionMessage implements IRead {
  5. public int msgType;
  6. public long tstamp;
  7. public int source;
  8. public int robotMsgType;
  9. public String name;
  10. public int majorVersion;
  11. public int minorVersion;
  12. public int bugFixVersion;
  13. public int buildNumber;
  14. public String buildDate;
  15. @Override
  16. public String toString() {
  17. return "{\"VersionMessage\":{"
  18. + " \"msgType\":\"" + msgType + "\""
  19. + ", \"tstamp\":\"" + tstamp + "\""
  20. + ", \"source\":\"" + source + "\""
  21. + ", \"robotMsgType\":\"" + robotMsgType + "\""
  22. + ", \"name\":\"" + name + "\""
  23. + ", \"majorVersion\":\"" + majorVersion + "\""
  24. + ", \"minorVersion\":\"" + minorVersion + "\""
  25. + ", \"bugFixVersion\":\"" + bugFixVersion + "\""
  26. + ", \"buildNumber\":\"" + buildNumber + "\""
  27. + ", \"buildDate\":\"" + buildDate + "\""
  28. + "}}";
  29. }
  30. public void read(CountDataInputStream in, int size) throws IOException {
  31. int before=in.getCount();
  32. int msgSize = in.readInt();
  33. msgType = in.readUnsignedByte();
  34. tstamp = in.readLong();
  35. source = in.readByte();
  36. robotMsgType = in.readByte();
  37. int projectNameSize = in.readUnsignedByte();
  38. byte[] nameBytes = new byte[projectNameSize];
  39. in.readFully(nameBytes);
  40. name = new String(nameBytes);
  41. majorVersion = in.readByte() & 0xff;
  42. minorVersion = in.readByte() & 0xff;
  43. bugFixVersion = in.readInt();
  44. buildNumber = in.readInt();
  45. byte[] buildDateBytes = new byte[msgSize - (16 + projectNameSize + 10)];
  46. in.readFully(buildDateBytes);
  47. buildDate = new String(buildDateBytes);
  48. int diff=in.getCount()-before;
  49. if(diff!=msgSize) {
  50. throw new RuntimeException("Versionmessage length mismatch: "+diff);
  51. }
  52. }
  53. }