On Tue, 28 Apr 2015 16:52:19 +0800 Shannon Zhao <zhaoshengl...@huawei.com> wrote:
> On 2015/4/28 16:15, Igor Mammedov wrote: > >>> btw: > >>> > > whole thing might be simpler if an intermediate conversion is avoided, > >>> > > just pack buffer as in spec byte by byte: > >>> > > > >>> > > /* format: aabbccdd-eeff-gghh-iijj-kkllmmnnoopp */ > >>> > > assert(strlen(uuid) == ...); > >>> > > build_append_byte(var->buf, HEX2BYTE(uuid[3]); /* dd */ > >> > > >> > use build_append_byte(var->buf, HEX2BYTE(uuid + 7); ? > >> > > >>> > > build_append_byte(var->buf, HEX2BYTE(uuid[2]); /* cc */ > >> > > >> > use build_append_byte(var->buf, HEX2BYTE(uuid + 5); ? > > if you mean hyphens /-/ then they are not encoded, > > but you surely can add checks for them to make sure that > > UUID format is as expected. > > > > I mean uuid[3] points to b not dd. Maybe use following way: > > static uint8_t Hex2Byte(char *src) or even better: Hex2Byte(char *src, byte_idx) and do pointer arithmetic inside [...] > build_append_byte(var->buf, Hex2Byte(uuid + (3 * 2))); /* dd */ build_append_byte(var->buf, Hex2Byte(uuid, 3)); /* dd - at offset 00 */ build_append_byte(var->buf, Hex2Byte(uuid, 2)); /* cc - at offset 01 */ ...