Mercurial > gemma
view pkg/misc/encode.go @ 616:51dc26b0f066
client: avoid extra password reveal button for IE/Edge
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Tue, 11 Sep 2018 09:50:37 +0200 |
parents | f827dc4f3e95 |
children | a244b18cb916 |
line wrap: on
line source
package misc import ( "encoding/binary" "io" ) type BinReader struct { io.Reader Err error } func (r *BinReader) Read(buf []byte) (int, error) { if r.Err != nil { return 0, r.Err } var n int n, r.Err = r.Read(buf) return n, r.Err } func (r *BinReader) ReadBin(x interface{}) { if r.Err == nil { r.Err = binary.Read(r.Reader, binary.BigEndian, x) } } func (r *BinReader) ReadString(s *string) { if r.Err != nil { return } var l uint32 if r.Err = binary.Read(r.Reader, binary.BigEndian, &l); r.Err != nil { return } b := make([]byte, l) if r.Err = binary.Read(r.Reader, binary.BigEndian, b); r.Err != nil { return } *s = string(b) } type BinWriter struct { io.Writer Err error } func (w *BinWriter) Write(buf []byte) (int, error) { if w.Err != nil { return 0, w.Err } var n int n, w.Err = w.Writer.Write(buf) return n, w.Err } func (w *BinWriter) WriteBin(x interface{}) { if w.Err == nil { w.Err = binary.Write(w.Writer, binary.BigEndian, x) } } func (w *BinWriter) WriteString(s string) { if w.Err == nil { w.Err = binary.Write(w.Writer, binary.BigEndian, uint32(len(s))) } if w.Err == nil { w.Err = binary.Write(w.Writer, binary.BigEndian, []byte(s)) } }