-
Notifications
You must be signed in to change notification settings - Fork 0
/
zr.go
205 lines (179 loc) · 4.62 KB
/
zr.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* Copyright (c) 2000-2018, 达梦数据库有限公司.
* All rights reserved.
*/
package dm
import (
"io"
)
const (
READ_LEN = Dm_build_716
)
type iOffRowBinder interface {
read(buf *Dm_build_1498)
isReadOver() bool
getObj() interface{}
}
type offRowBinder struct {
obj interface{}
encoding string
readOver bool
buffer *Dm_build_1498
position int32
offRow bool
targetLength int64
}
func newOffRowBinder(obj interface{}, encoding string, targetLength int64) *offRowBinder {
return &offRowBinder{
obj: obj,
encoding: encoding,
targetLength: targetLength,
readOver: false,
buffer: Dm_build_1502(),
position: 0,
}
}
type offRowBytesBinder struct {
*offRowBinder
}
func newOffRowBytesBinder(obj []byte, encoding string) *offRowBytesBinder {
var binder = &offRowBytesBinder{
newOffRowBinder(obj, encoding, int64(IGNORE_TARGET_LENGTH)),
}
binder.read(binder.buffer)
binder.offRow = binder.buffer.Dm_build_1503() > Dm_build_713
return binder
}
func (b *offRowBytesBinder) read(buf *Dm_build_1498) {
if b.buffer.Dm_build_1503() > 0 {
buf.Dm_build_1535(b.buffer)
} else if !b.readOver {
var obj = b.obj.([]byte)
buf.Dm_build_1524(obj, 0, len(obj))
b.readOver = true
}
}
func (b *offRowBytesBinder) isReadOver() bool {
return b.readOver
}
func (b *offRowBytesBinder) getObj() interface{} {
return b.obj
}
type offRowBlobBinder struct {
*offRowBinder
}
func newOffRowBlobBinder(blob DmBlob, encoding string) *offRowBlobBinder {
var binder = &offRowBlobBinder{
newOffRowBinder(blob, encoding, int64(IGNORE_TARGET_LENGTH)),
}
binder.read(binder.buffer)
binder.offRow = binder.buffer.Dm_build_1503() > Dm_build_713
return binder
}
func (b *offRowBlobBinder) read(buf *Dm_build_1498) {
if b.buffer.Dm_build_1503() > 0 {
buf.Dm_build_1535(b.buffer)
} else if !b.readOver {
var obj = b.obj.(DmBlob)
var totalLen, _ = obj.GetLength()
var leaveLen = totalLen - int64(b.position)
var readLen = int32(leaveLen)
if leaveLen > READ_LEN {
readLen = READ_LEN
}
var bytes, _ = obj.getBytes(int64(b.position)+1, readLen)
b.position += readLen
if b.position == int32(totalLen) {
b.readOver = true
}
buf.Dm_build_1524(bytes, 0, len(bytes))
}
}
func (b *offRowBlobBinder) isReadOver() bool {
return b.readOver
}
func (b *offRowBlobBinder) getObj() interface{} {
return b.obj
}
type offRowClobBinder struct {
*offRowBinder
}
func newOffRowClobBinder(clob DmClob, encoding string) *offRowClobBinder {
var binder = &offRowClobBinder{
newOffRowBinder(clob, encoding, int64(IGNORE_TARGET_LENGTH)),
}
binder.read(binder.buffer)
binder.offRow = binder.buffer.Dm_build_1503() > Dm_build_713
return binder
}
func (b *offRowClobBinder) read(buf *Dm_build_1498) {
if b.buffer.Dm_build_1503() > 0 {
buf.Dm_build_1535(b.buffer)
} else if !b.readOver {
var obj = b.obj.(DmClob)
var totalLen, _ = obj.GetLength()
var leaveLen = totalLen - int64(b.position)
var readLen = int32(leaveLen)
if leaveLen > READ_LEN {
readLen = READ_LEN
}
var str, _ = obj.getSubString(int64(b.position)+1, readLen)
var bytes = Dm_build_1219.Dm_build_1432(str, b.encoding, nil)
b.position += readLen
if b.position == int32(totalLen) {
b.readOver = true
}
buf.Dm_build_1524(bytes, 0, len(bytes))
}
}
func (b *offRowClobBinder) isReadOver() bool {
return b.readOver
}
func (b *offRowClobBinder) getObj() interface{} {
return b.obj
}
type offRowReaderBinder struct {
*offRowBinder
}
func newOffRowReaderBinder(reader io.Reader, encoding string) *offRowReaderBinder {
var binder = &offRowReaderBinder{
newOffRowBinder(reader, encoding, int64(IGNORE_TARGET_LENGTH)),
}
binder.read(binder.buffer)
binder.offRow = binder.buffer.Dm_build_1503() > Dm_build_713
return binder
}
func (b *offRowReaderBinder) read(buf *Dm_build_1498) {
if b.buffer.Dm_build_1503() > 0 {
buf.Dm_build_1535(b.buffer)
} else if !b.readOver {
var err error
var readLen = READ_LEN
var reader = b.obj.(io.Reader)
var bytes = make([]byte, readLen)
readLen, err = reader.Read(bytes)
if err == io.EOF {
b.readOver = true
return
}
b.position += int32(readLen)
if readLen < len(bytes) || b.targetLength != int64(IGNORE_TARGET_LENGTH) && int64(b.position) == b.targetLength {
b.readOver = true
}
buf.Dm_build_1524(bytes[0:readLen], 0, readLen)
}
}
func (b *offRowReaderBinder) readAll() []byte {
var byteArray = Dm_build_1502()
b.read(byteArray)
for !b.readOver {
b.read(byteArray)
}
return byteArray.Dm_build_1545()
}
func (b *offRowReaderBinder) isReadOver() bool {
return b.readOver
}
func (b *offRowReaderBinder) getObj() interface{} {
return b.obj
}