func (this *OutputStream) WriteBytes(data []byte) error { // array size size := uint16(len(data)) err := this.WriteUI16(size) if err != nil { return faults.Wrap(err) } // string data if size > 0 { _, err = this.writer.Write(data) if err != nil { return faults.Wrap(err) } } return nil }
func (this *InputStream) readBytes(size int) ([]byte, error) { var data = make([]byte, size) if _, err := io.ReadFull(this.reader, data); err != nil { return nil, faults.Wrap(err) } return data, nil }
func (this *InputStream) ReadBytes() ([]byte, error) { // reads byte array size size, err := this.ReadUI16() if err != nil { return nil, faults.Wrap(err) } if size > 0 { return this.readBytes(int(size)) } return nil, nil }
func (this *InputStream) ReadString() (string, error) { data := []byte{0} var s bytes.Buffer for { if _, err := io.ReadFull(this.reader, data); err != nil { return "", faults.Wrap(err) } if data[0] == STRING_END { break } else { s.WriteByte(data[0]) } } return string(s.Bytes()), nil }
func (this *OutputStream) WriteString(s string) error { data := append([]byte(s), STRING_END) _, err := this.writer.Write([]byte(data)) return faults.Wrap(err) }
func (this *OutputStream) WriteUI64(data uint64) error { var buf64 = make([]byte, 8) binary.LittleEndian.PutUint64(buf64, data) _, err := this.writer.Write(buf64) return faults.Wrap(err) }
func (this *OutputStream) WriteUI32(data uint32) error { var buf32 = make([]byte, 4) binary.LittleEndian.PutUint32(buf32, data) _, err := this.writer.Write(buf32) return faults.Wrap(err) }
func (this *OutputStream) WriteUI16(data uint16) error { var buf16 = make([]byte, 2) binary.LittleEndian.PutUint16(buf16, data) _, err := this.writer.Write(buf16) return faults.Wrap(err) }
func (this *OutputStream) WriteUI8(data uint8) error { var buf8 = make([]byte, 1) buf8[0] = data _, err := this.writer.Write(buf8) return faults.Wrap(err) }