-
Notifications
You must be signed in to change notification settings - Fork 0
/
outputstream.go
57 lines (46 loc) · 1.15 KB
/
outputstream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package nxamf
import (
"math"
"encoding/binary"
)
type OutputStream struct {
RawData string
}
func (a *OutputStream) WriteBuffer(buf string) {
a.RawData+=buf
}
func (a *OutputStream) WriteByte(bt int) {
a.RawData+=string(bt)
}
func (a *OutputStream) WriteInt(integer uint16) {
bytes := make([]byte, 4)
binary.BigEndian.PutUint16(bytes, integer)
a.RawData+=string(bytes[:2])
}
func (a *OutputStream) WriteDouble(double float64) {
var buf [8]byte
binary.BigEndian.PutUint64(buf[:], math.Float64bits(double))
a.RawData+=string(buf[:])
// bits := math.Float64bits(double)
// bytes := make([]byte, 8)
// binary.LittleEndian.PutUint64(bytes, bits)
// a.RawData+=strrev(string(bytes))
}
func (a *OutputStream) WriteLongMinus1() {
bytes := make([]byte, 8)
binary.BigEndian.PutUint64(bytes, 4294967295)
a.RawData+=string(bytes[4:])
}
func (a *OutputStream) WriteLong(long uint64) {
bytes := make([]byte, 8)
binary.BigEndian.PutUint64(bytes, long)
a.RawData+=string(bytes[4:])
}
func (a *OutputStream) GetRawData() string {
return a.RawData
}
func NewOutputStream() *OutputStream {
a := new(OutputStream)
a.RawData = ""
return a
}