func (w *writer) writeUUID(v interface{}, u uuid.UUID) (err error) { w.setRef(v) s := w.stream if err = s.WriteByte(TagGuid); err == nil { if err = s.WriteByte(TagOpenbrace); err == nil { if _, err = s.WriteString(u.String()); err == nil { err = s.WriteByte(TagClosebrace) } } } return err }
func main() { flag.Parse() if number > 1 { for i := 0; i < number; i++ { var id uuid.UUID = uuid.Rand() fmt.Println(strings.Replace(id.Hex(), "-", "", -1)) } } else { var id uuid.UUID = uuid.Rand() fmt.Println(id.Hex()) fmt.Println(strings.Replace(id.Hex(), "-", "", -1)) } }
func TestSimpleReaderUUID(t *testing.T) { b := new(bytes.Buffer) writer := NewSimpleWriter(b) u := uuid.NewUUID() writer.Serialize(u) writer.Serialize(u) writer.Serialize(u.String()) writer.Serialize([]byte(u)) writer.Serialize(nil) writer.Serialize(nil) reader := NewSimpleReader(b) var x uuid.UUID var p *uuid.UUID var err error if err = reader.Unserialize(&x); err != nil { t.Error(err.Error()) } if x.String() != u.String() { t.Error(x) } if err = reader.Unserialize(&p); err != nil { t.Error(err.Error()) } if (*p).String() != u.String() { t.Error(*p) } if err = reader.Unserialize(&x); err != nil { t.Error(err.Error()) } if x.String() != u.String() { t.Error(x) } if err = reader.Unserialize(&p); err != nil { t.Error(err.Error()) } if (*p).String() != u.String() { t.Error(*p) } if err = reader.Unserialize(&x); err != nil { t.Error(err.Error()) } if x.String() != "" { t.Error(x) } if err = reader.Unserialize(&p); err != nil { t.Error(err.Error()) } if p != nil { t.Error(*p) } }