diff --git a/xdr/reader.go b/xdr/reader.go index 314bcefd8..3f9cd0a3d 100644 --- a/xdr/reader.go +++ b/xdr/reader.go @@ -102,53 +102,11 @@ func (r *Reader) ReadBytesMaxInto(max int, dst []byte) []byte { } func (r *Reader) ReadBool() bool { - if r.err != nil { - return false - } - r.last = time.Now() - s := r.tot - - var n int - n, r.err = io.ReadFull(r.r, r.b[:4]) - r.tot += n - if r.err != nil { - if debug { - dl.Debugf("@0x%x: rd bool: %v", r.tot, r.err) - } - return false - } - - v := r.b[3] != 0 - - if debug { - dl.Debugf("@0x%x: rd bool=%v (0x%04x)", s, v, v) - } - return v + return r.ReadUint32() != 0 } func (r *Reader) ReadUint16() uint16 { - if r.err != nil { - return 0 - } - r.last = time.Now() - s := r.tot - - var n int - n, r.err = io.ReadFull(r.r, r.b[:4]) - r.tot += n - if r.err != nil { - if debug { - dl.Debugf("@0x%x: rd uint16: %v", r.tot, r.err) - } - return 0 - } - - v := uint16(r.b[3]) | uint16(r.b[2])<<8 - - if debug { - dl.Debugf("@0x%x: rd uint16=%d (0x%04x)", s, v, v) - } - return v + return uint16(r.ReadUint32()) } func (r *Reader) ReadUint32() uint32 { diff --git a/xdr/writer.go b/xdr/writer.go index dd9a4dc45..8dd827368 100644 --- a/xdr/writer.go +++ b/xdr/writer.go @@ -77,49 +77,15 @@ func (w *Writer) WriteBytes(bs []byte) (int, error) { } func (w *Writer) WriteBool(v bool) (int, error) { - if w.err != nil { - return 0, w.err - } - - w.last = time.Now() - if debug { - dl.Debugf("wr uint16=%d", v) - } - - w.b[0] = 0 - w.b[1] = 0 - w.b[2] = 0 if v { - w.b[3] = 1 + return w.WriteUint32(1) } else { - w.b[3] = 0 + return w.WriteUint32(0) } - - var l int - l, w.err = w.w.Write(w.b[:4]) - w.tot += l - return l, w.err } func (w *Writer) WriteUint16(v uint16) (int, error) { - if w.err != nil { - return 0, w.err - } - - w.last = time.Now() - if debug { - dl.Debugf("wr uint16=%d", v) - } - - w.b[0] = 0 - w.b[1] = 0 - w.b[2] = byte(v >> 8) - w.b[3] = byte(v) - - var l int - l, w.err = w.w.Write(w.b[:4]) - w.tot += l - return l, w.err + return w.WriteUint32(uint32(v)) } func (w *Writer) WriteUint32(v uint32) (int, error) {