/// <summary> /// Parse the build in type and return the length of object in the bytes and record /// </summary> /// <param name="rawData"></param> /// <param name="type"></param> /// <param name="offset"></param> /// <returns></returns> private Tuple <int, dynamic> ParseBuildInTypes(byte[] rawData, string type, int offset = 0) { switch (type) { case "string": var len = (int)BitConverter.ToInt32(rawData, offset); return(new Tuple <int, dynamic>(len + 4, Encoding.UTF8.GetString(rawData, offset + 4, len))); case "bool": return(new Tuple <int, dynamic>(1, BitConverter.ToBoolean(rawData, offset))); case "int8": return(new Tuple <int, dynamic>(1, rawData[offset])); case "uint8": return(new Tuple <int, dynamic>(1, rawData[offset])); case "int16": return(new Tuple <int, dynamic>(2, BitConverter.ToInt16(rawData, offset))); case "uint16": return(new Tuple <int, dynamic>(2, BitConverter.ToUInt16(rawData, offset))); case "int32": return(new Tuple <int, dynamic>(4, BitConverter.ToInt32(rawData, offset))); case "uint32": return(new Tuple <int, dynamic>(4, BitConverter.ToUInt32(rawData, offset))); case "int64": return(new Tuple <int, dynamic>(8, BitConverter.ToInt64(rawData, offset))); case "uint64": return(new Tuple <int, dynamic>(8, BitConverter.ToUInt64(rawData, offset))); case "float32": return(new Tuple <int, dynamic>(4, BitConverter.ToSingle(rawData, offset))); case "float64": return(new Tuple <int, dynamic>(8, BitConverter.ToDouble(rawData, offset))); case "time": return(new Tuple <int, dynamic>(8, RosTime.FromRosBytes(rawData, offset))); case "duration": return(new Tuple <int, dynamic>(8, RosDuration.FromRosBytes(rawData, offset))); case "header": case "Header": var header = RosHeader.FromRosBytes(rawData, offset); return(new Tuple <int, dynamic>(header.HeaderByteSize, header)); } return(null); }
public static RosHeader FromRosBytes(byte[] headerBytes) { return(RosHeader.FromRosBytes(headerBytes, 0)); }