Mercurial > gemma
view auth/encode.go @ 256:1ff9aec9326f
db-setup script: Be more quiet during creation.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 27 Jul 2018 12:49:39 +0200 |
parents | f345edb409b2 |
children |
line wrap: on
line source
package auth import ( "encoding/binary" "io" ) type binReader struct { r io.Reader err error } func (r *binReader) read(x interface{}) { if r.err == nil { r.err = binary.Read(r.r, binary.BigEndian, x) } } func (r *binReader) readString(s *string) { if r.err != nil { return } var l uint32 if r.err = binary.Read(r.r, binary.BigEndian, &l); r.err != nil { return } b := make([]byte, l) if r.err = binary.Read(r.r, binary.BigEndian, b); r.err != nil { return } *s = string(b) } type binWriter struct { w io.Writer err error } func (w *binWriter) write(x interface{}) { if w.err == nil { w.err = binary.Write(w.w, binary.BigEndian, x) } } func (w *binWriter) writeString(s string) { if w.err == nil { w.err = binary.Write(w.w, binary.BigEndian, uint32(len(s))) } if w.err == nil { w.err = binary.Write(w.w, binary.BigEndian, []byte(s)) } }