Fix XDR handling of int16

This commit is contained in:
Jakob Borg 2014-07-13 09:16:40 +02:00
parent 0a633c526f
commit a6d67d30f5
2 changed files with 5 additions and 81 deletions

View File

@ -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 {

View File

@ -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) {