| 1 |
|
| 2 |
|
| 3 |
package primitive |
| 4 |
|
| 5 |
import ( |
| 6 |
"inet.af/netstack/gohacks" |
| 7 |
"inet.af/netstack/hostarch" |
| 8 |
"inet.af/netstack/marshal" |
| 9 |
"io" |
| 10 |
"reflect" |
| 11 |
"runtime" |
| 12 |
"unsafe" |
| 13 |
) |
| 14 |
|
| 15 |
|
| 16 |
var _ marshal.Marshallable = (*Int16)(nil) |
| 17 |
var _ marshal.Marshallable = (*Int32)(nil) |
| 18 |
var _ marshal.Marshallable = (*Int64)(nil) |
| 19 |
var _ marshal.Marshallable = (*Int8)(nil) |
| 20 |
var _ marshal.Marshallable = (*Uint16)(nil) |
| 21 |
var _ marshal.Marshallable = (*Uint32)(nil) |
| 22 |
var _ marshal.Marshallable = (*Uint64)(nil) |
| 23 |
var _ marshal.Marshallable = (*Uint8)(nil) |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
func (i *Int16) SizeBytes() int { |
| 28 |
return 2 |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
func (i *Int16) MarshalBytes(dst []byte) []byte { |
| 33 |
hostarch.ByteOrder.PutUint16(dst[:2], uint16(*i)) |
| 34 |
return dst[2:] |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
func (i *Int16) UnmarshalBytes(src []byte) []byte { |
| 39 |
*i = Int16(int16(hostarch.ByteOrder.Uint16(src[:2]))) |
| 40 |
return src[2:] |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
func (i *Int16) Packed() bool { |
| 46 |
|
| 47 |
return true |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
func (i *Int16) MarshalUnsafe(dst []byte) []byte { |
| 52 |
size := i.SizeBytes() |
| 53 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) |
| 54 |
return dst[size:] |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
func (i *Int16) UnmarshalUnsafe(src []byte) []byte { |
| 59 |
size := i.SizeBytes() |
| 60 |
gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) |
| 61 |
return src[size:] |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
func (i *Int16) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { |
| 67 |
|
| 68 |
var buf []byte |
| 69 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 70 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 71 |
hdr.Len = i.SizeBytes() |
| 72 |
hdr.Cap = i.SizeBytes() |
| 73 |
|
| 74 |
length, err := cc.CopyOutBytes(addr, buf[:limit]) |
| 75 |
|
| 76 |
|
| 77 |
runtime.KeepAlive(i) |
| 78 |
return length, err |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
func (i *Int16) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 84 |
return i.CopyOutN(cc, addr, i.SizeBytes()) |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
func (i *Int16) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 90 |
|
| 91 |
var buf []byte |
| 92 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 93 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 94 |
hdr.Len = i.SizeBytes() |
| 95 |
hdr.Cap = i.SizeBytes() |
| 96 |
|
| 97 |
length, err := cc.CopyInBytes(addr, buf) |
| 98 |
|
| 99 |
|
| 100 |
runtime.KeepAlive(i) |
| 101 |
return length, err |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
func (i *Int16) WriteTo(writer io.Writer) (int64, error) { |
| 106 |
|
| 107 |
var buf []byte |
| 108 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 109 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 110 |
hdr.Len = i.SizeBytes() |
| 111 |
hdr.Cap = i.SizeBytes() |
| 112 |
|
| 113 |
length, err := writer.Write(buf) |
| 114 |
|
| 115 |
|
| 116 |
runtime.KeepAlive(i) |
| 117 |
return int64(length), err |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
func (i *Int16) CheckedMarshal(dst []byte) ([]byte, bool) { |
| 122 |
size := i.SizeBytes() |
| 123 |
if size > len(dst) { |
| 124 |
return dst, false |
| 125 |
} |
| 126 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) |
| 127 |
return dst[size:], true |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
func (i *Int16) CheckedUnmarshal(src []byte) ([]byte, bool) { |
| 132 |
size := i.SizeBytes() |
| 133 |
if size > len(src) { |
| 134 |
return src, false |
| 135 |
} |
| 136 |
gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) |
| 137 |
return src[size:], true |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
func CopyInt16SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []int16) (int, error) { |
| 143 |
count := len(dst) |
| 144 |
if count == 0 { |
| 145 |
return 0, nil |
| 146 |
} |
| 147 |
size := (*Int16)(nil).SizeBytes() |
| 148 |
|
| 149 |
ptr := unsafe.Pointer(&dst) |
| 150 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 151 |
|
| 152 |
|
| 153 |
var buf []byte |
| 154 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 155 |
hdr.Data = uintptr(val) |
| 156 |
hdr.Len = size * count |
| 157 |
hdr.Cap = size * count |
| 158 |
|
| 159 |
length, err := cc.CopyInBytes(addr, buf) |
| 160 |
|
| 161 |
|
| 162 |
runtime.KeepAlive(dst) |
| 163 |
return length, err |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
func CopyInt16SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []int16) (int, error) { |
| 169 |
count := len(src) |
| 170 |
if count == 0 { |
| 171 |
return 0, nil |
| 172 |
} |
| 173 |
size := (*Int16)(nil).SizeBytes() |
| 174 |
|
| 175 |
ptr := unsafe.Pointer(&src) |
| 176 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 177 |
|
| 178 |
|
| 179 |
var buf []byte |
| 180 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 181 |
hdr.Data = uintptr(val) |
| 182 |
hdr.Len = size * count |
| 183 |
hdr.Cap = size * count |
| 184 |
|
| 185 |
length, err := cc.CopyOutBytes(addr, buf) |
| 186 |
|
| 187 |
|
| 188 |
runtime.KeepAlive(src) |
| 189 |
return length, err |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
func MarshalUnsafeInt16Slice(src []Int16, dst []byte) []byte { |
| 194 |
count := len(src) |
| 195 |
if count == 0 { |
| 196 |
return dst |
| 197 |
} |
| 198 |
size := (*Int16)(nil).SizeBytes() |
| 199 |
|
| 200 |
buf := dst[:size*count] |
| 201 |
gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) |
| 202 |
return dst[size*count:] |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
func UnmarshalUnsafeInt16Slice(dst []Int16, src []byte) []byte { |
| 207 |
count := len(dst) |
| 208 |
if count == 0 { |
| 209 |
return src |
| 210 |
} |
| 211 |
size := (*Int16)(nil).SizeBytes() |
| 212 |
|
| 213 |
buf := src[:size*count] |
| 214 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) |
| 215 |
return src[size*count:] |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
func (i *Int32) SizeBytes() int { |
| 221 |
return 4 |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
func (i *Int32) MarshalBytes(dst []byte) []byte { |
| 226 |
hostarch.ByteOrder.PutUint32(dst[:4], uint32(*i)) |
| 227 |
return dst[4:] |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
func (i *Int32) UnmarshalBytes(src []byte) []byte { |
| 232 |
*i = Int32(int32(hostarch.ByteOrder.Uint32(src[:4]))) |
| 233 |
return src[4:] |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
func (i *Int32) Packed() bool { |
| 239 |
|
| 240 |
return true |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
func (i *Int32) MarshalUnsafe(dst []byte) []byte { |
| 245 |
size := i.SizeBytes() |
| 246 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) |
| 247 |
return dst[size:] |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
func (i *Int32) UnmarshalUnsafe(src []byte) []byte { |
| 252 |
size := i.SizeBytes() |
| 253 |
gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) |
| 254 |
return src[size:] |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
func (i *Int32) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { |
| 260 |
|
| 261 |
var buf []byte |
| 262 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 263 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 264 |
hdr.Len = i.SizeBytes() |
| 265 |
hdr.Cap = i.SizeBytes() |
| 266 |
|
| 267 |
length, err := cc.CopyOutBytes(addr, buf[:limit]) |
| 268 |
|
| 269 |
|
| 270 |
runtime.KeepAlive(i) |
| 271 |
return length, err |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
func (i *Int32) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 277 |
return i.CopyOutN(cc, addr, i.SizeBytes()) |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
func (i *Int32) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 283 |
|
| 284 |
var buf []byte |
| 285 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 286 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 287 |
hdr.Len = i.SizeBytes() |
| 288 |
hdr.Cap = i.SizeBytes() |
| 289 |
|
| 290 |
length, err := cc.CopyInBytes(addr, buf) |
| 291 |
|
| 292 |
|
| 293 |
runtime.KeepAlive(i) |
| 294 |
return length, err |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
func (i *Int32) WriteTo(writer io.Writer) (int64, error) { |
| 299 |
|
| 300 |
var buf []byte |
| 301 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 302 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 303 |
hdr.Len = i.SizeBytes() |
| 304 |
hdr.Cap = i.SizeBytes() |
| 305 |
|
| 306 |
length, err := writer.Write(buf) |
| 307 |
|
| 308 |
|
| 309 |
runtime.KeepAlive(i) |
| 310 |
return int64(length), err |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
func (i *Int32) CheckedMarshal(dst []byte) ([]byte, bool) { |
| 315 |
size := i.SizeBytes() |
| 316 |
if size > len(dst) { |
| 317 |
return dst, false |
| 318 |
} |
| 319 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) |
| 320 |
return dst[size:], true |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
func (i *Int32) CheckedUnmarshal(src []byte) ([]byte, bool) { |
| 325 |
size := i.SizeBytes() |
| 326 |
if size > len(src) { |
| 327 |
return src, false |
| 328 |
} |
| 329 |
gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) |
| 330 |
return src[size:], true |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
func CopyInt32SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []int32) (int, error) { |
| 336 |
count := len(dst) |
| 337 |
if count == 0 { |
| 338 |
return 0, nil |
| 339 |
} |
| 340 |
size := (*Int32)(nil).SizeBytes() |
| 341 |
|
| 342 |
ptr := unsafe.Pointer(&dst) |
| 343 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 344 |
|
| 345 |
|
| 346 |
var buf []byte |
| 347 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 348 |
hdr.Data = uintptr(val) |
| 349 |
hdr.Len = size * count |
| 350 |
hdr.Cap = size * count |
| 351 |
|
| 352 |
length, err := cc.CopyInBytes(addr, buf) |
| 353 |
|
| 354 |
|
| 355 |
runtime.KeepAlive(dst) |
| 356 |
return length, err |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
func CopyInt32SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []int32) (int, error) { |
| 362 |
count := len(src) |
| 363 |
if count == 0 { |
| 364 |
return 0, nil |
| 365 |
} |
| 366 |
size := (*Int32)(nil).SizeBytes() |
| 367 |
|
| 368 |
ptr := unsafe.Pointer(&src) |
| 369 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 370 |
|
| 371 |
|
| 372 |
var buf []byte |
| 373 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 374 |
hdr.Data = uintptr(val) |
| 375 |
hdr.Len = size * count |
| 376 |
hdr.Cap = size * count |
| 377 |
|
| 378 |
length, err := cc.CopyOutBytes(addr, buf) |
| 379 |
|
| 380 |
|
| 381 |
runtime.KeepAlive(src) |
| 382 |
return length, err |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
func MarshalUnsafeInt32Slice(src []Int32, dst []byte) []byte { |
| 387 |
count := len(src) |
| 388 |
if count == 0 { |
| 389 |
return dst |
| 390 |
} |
| 391 |
size := (*Int32)(nil).SizeBytes() |
| 392 |
|
| 393 |
buf := dst[:size*count] |
| 394 |
gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) |
| 395 |
return dst[size*count:] |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
func UnmarshalUnsafeInt32Slice(dst []Int32, src []byte) []byte { |
| 400 |
count := len(dst) |
| 401 |
if count == 0 { |
| 402 |
return src |
| 403 |
} |
| 404 |
size := (*Int32)(nil).SizeBytes() |
| 405 |
|
| 406 |
buf := src[:size*count] |
| 407 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) |
| 408 |
return src[size*count:] |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
func (i *Int64) SizeBytes() int { |
| 414 |
return 8 |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
func (i *Int64) MarshalBytes(dst []byte) []byte { |
| 419 |
hostarch.ByteOrder.PutUint64(dst[:8], uint64(*i)) |
| 420 |
return dst[8:] |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
func (i *Int64) UnmarshalBytes(src []byte) []byte { |
| 425 |
*i = Int64(int64(hostarch.ByteOrder.Uint64(src[:8]))) |
| 426 |
return src[8:] |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
func (i *Int64) Packed() bool { |
| 432 |
|
| 433 |
return true |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
func (i *Int64) MarshalUnsafe(dst []byte) []byte { |
| 438 |
size := i.SizeBytes() |
| 439 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) |
| 440 |
return dst[size:] |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
func (i *Int64) UnmarshalUnsafe(src []byte) []byte { |
| 445 |
size := i.SizeBytes() |
| 446 |
gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) |
| 447 |
return src[size:] |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
func (i *Int64) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { |
| 453 |
|
| 454 |
var buf []byte |
| 455 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 456 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 457 |
hdr.Len = i.SizeBytes() |
| 458 |
hdr.Cap = i.SizeBytes() |
| 459 |
|
| 460 |
length, err := cc.CopyOutBytes(addr, buf[:limit]) |
| 461 |
|
| 462 |
|
| 463 |
runtime.KeepAlive(i) |
| 464 |
return length, err |
| 465 |
} |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
func (i *Int64) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 470 |
return i.CopyOutN(cc, addr, i.SizeBytes()) |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
func (i *Int64) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 476 |
|
| 477 |
var buf []byte |
| 478 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 479 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 480 |
hdr.Len = i.SizeBytes() |
| 481 |
hdr.Cap = i.SizeBytes() |
| 482 |
|
| 483 |
length, err := cc.CopyInBytes(addr, buf) |
| 484 |
|
| 485 |
|
| 486 |
runtime.KeepAlive(i) |
| 487 |
return length, err |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
func (i *Int64) WriteTo(writer io.Writer) (int64, error) { |
| 492 |
|
| 493 |
var buf []byte |
| 494 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 495 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 496 |
hdr.Len = i.SizeBytes() |
| 497 |
hdr.Cap = i.SizeBytes() |
| 498 |
|
| 499 |
length, err := writer.Write(buf) |
| 500 |
|
| 501 |
|
| 502 |
runtime.KeepAlive(i) |
| 503 |
return int64(length), err |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
func (i *Int64) CheckedMarshal(dst []byte) ([]byte, bool) { |
| 508 |
size := i.SizeBytes() |
| 509 |
if size > len(dst) { |
| 510 |
return dst, false |
| 511 |
} |
| 512 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) |
| 513 |
return dst[size:], true |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
func (i *Int64) CheckedUnmarshal(src []byte) ([]byte, bool) { |
| 518 |
size := i.SizeBytes() |
| 519 |
if size > len(src) { |
| 520 |
return src, false |
| 521 |
} |
| 522 |
gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) |
| 523 |
return src[size:], true |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
func CopyInt64SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []int64) (int, error) { |
| 529 |
count := len(dst) |
| 530 |
if count == 0 { |
| 531 |
return 0, nil |
| 532 |
} |
| 533 |
size := (*Int64)(nil).SizeBytes() |
| 534 |
|
| 535 |
ptr := unsafe.Pointer(&dst) |
| 536 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 537 |
|
| 538 |
|
| 539 |
var buf []byte |
| 540 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 541 |
hdr.Data = uintptr(val) |
| 542 |
hdr.Len = size * count |
| 543 |
hdr.Cap = size * count |
| 544 |
|
| 545 |
length, err := cc.CopyInBytes(addr, buf) |
| 546 |
|
| 547 |
|
| 548 |
runtime.KeepAlive(dst) |
| 549 |
return length, err |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
func CopyInt64SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []int64) (int, error) { |
| 555 |
count := len(src) |
| 556 |
if count == 0 { |
| 557 |
return 0, nil |
| 558 |
} |
| 559 |
size := (*Int64)(nil).SizeBytes() |
| 560 |
|
| 561 |
ptr := unsafe.Pointer(&src) |
| 562 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 563 |
|
| 564 |
|
| 565 |
var buf []byte |
| 566 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 567 |
hdr.Data = uintptr(val) |
| 568 |
hdr.Len = size * count |
| 569 |
hdr.Cap = size * count |
| 570 |
|
| 571 |
length, err := cc.CopyOutBytes(addr, buf) |
| 572 |
|
| 573 |
|
| 574 |
runtime.KeepAlive(src) |
| 575 |
return length, err |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
func MarshalUnsafeInt64Slice(src []Int64, dst []byte) []byte { |
| 580 |
count := len(src) |
| 581 |
if count == 0 { |
| 582 |
return dst |
| 583 |
} |
| 584 |
size := (*Int64)(nil).SizeBytes() |
| 585 |
|
| 586 |
buf := dst[:size*count] |
| 587 |
gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) |
| 588 |
return dst[size*count:] |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
func UnmarshalUnsafeInt64Slice(dst []Int64, src []byte) []byte { |
| 593 |
count := len(dst) |
| 594 |
if count == 0 { |
| 595 |
return src |
| 596 |
} |
| 597 |
size := (*Int64)(nil).SizeBytes() |
| 598 |
|
| 599 |
buf := src[:size*count] |
| 600 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) |
| 601 |
return src[size*count:] |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
func (i *Int8) SizeBytes() int { |
| 607 |
return 1 |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
func (i *Int8) MarshalBytes(dst []byte) []byte { |
| 612 |
dst[0] = byte(*i) |
| 613 |
return dst[1:] |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
func (i *Int8) UnmarshalBytes(src []byte) []byte { |
| 618 |
*i = Int8(int8(src[0])) |
| 619 |
return src[1:] |
| 620 |
} |
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
func (i *Int8) Packed() bool { |
| 625 |
|
| 626 |
return true |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
func (i *Int8) MarshalUnsafe(dst []byte) []byte { |
| 631 |
size := i.SizeBytes() |
| 632 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) |
| 633 |
return dst[size:] |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
func (i *Int8) UnmarshalUnsafe(src []byte) []byte { |
| 638 |
size := i.SizeBytes() |
| 639 |
gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) |
| 640 |
return src[size:] |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
func (i *Int8) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { |
| 646 |
|
| 647 |
var buf []byte |
| 648 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 649 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 650 |
hdr.Len = i.SizeBytes() |
| 651 |
hdr.Cap = i.SizeBytes() |
| 652 |
|
| 653 |
length, err := cc.CopyOutBytes(addr, buf[:limit]) |
| 654 |
|
| 655 |
|
| 656 |
runtime.KeepAlive(i) |
| 657 |
return length, err |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
func (i *Int8) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 663 |
return i.CopyOutN(cc, addr, i.SizeBytes()) |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
func (i *Int8) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 669 |
|
| 670 |
var buf []byte |
| 671 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 672 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 673 |
hdr.Len = i.SizeBytes() |
| 674 |
hdr.Cap = i.SizeBytes() |
| 675 |
|
| 676 |
length, err := cc.CopyInBytes(addr, buf) |
| 677 |
|
| 678 |
|
| 679 |
runtime.KeepAlive(i) |
| 680 |
return length, err |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
func (i *Int8) WriteTo(writer io.Writer) (int64, error) { |
| 685 |
|
| 686 |
var buf []byte |
| 687 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 688 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(i))) |
| 689 |
hdr.Len = i.SizeBytes() |
| 690 |
hdr.Cap = i.SizeBytes() |
| 691 |
|
| 692 |
length, err := writer.Write(buf) |
| 693 |
|
| 694 |
|
| 695 |
runtime.KeepAlive(i) |
| 696 |
return int64(length), err |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
func (i *Int8) CheckedMarshal(dst []byte) ([]byte, bool) { |
| 701 |
size := i.SizeBytes() |
| 702 |
if size > len(dst) { |
| 703 |
return dst, false |
| 704 |
} |
| 705 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(i), uintptr(size)) |
| 706 |
return dst[size:], true |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
func (i *Int8) CheckedUnmarshal(src []byte) ([]byte, bool) { |
| 711 |
size := i.SizeBytes() |
| 712 |
if size > len(src) { |
| 713 |
return src, false |
| 714 |
} |
| 715 |
gohacks.Memmove(unsafe.Pointer(i), unsafe.Pointer(&src[0]), uintptr(size)) |
| 716 |
return src[size:], true |
| 717 |
} |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
func CopyInt8SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []int8) (int, error) { |
| 722 |
count := len(dst) |
| 723 |
if count == 0 { |
| 724 |
return 0, nil |
| 725 |
} |
| 726 |
size := (*Int8)(nil).SizeBytes() |
| 727 |
|
| 728 |
ptr := unsafe.Pointer(&dst) |
| 729 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 730 |
|
| 731 |
|
| 732 |
var buf []byte |
| 733 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 734 |
hdr.Data = uintptr(val) |
| 735 |
hdr.Len = size * count |
| 736 |
hdr.Cap = size * count |
| 737 |
|
| 738 |
length, err := cc.CopyInBytes(addr, buf) |
| 739 |
|
| 740 |
|
| 741 |
runtime.KeepAlive(dst) |
| 742 |
return length, err |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
func CopyInt8SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []int8) (int, error) { |
| 748 |
count := len(src) |
| 749 |
if count == 0 { |
| 750 |
return 0, nil |
| 751 |
} |
| 752 |
size := (*Int8)(nil).SizeBytes() |
| 753 |
|
| 754 |
ptr := unsafe.Pointer(&src) |
| 755 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 756 |
|
| 757 |
|
| 758 |
var buf []byte |
| 759 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 760 |
hdr.Data = uintptr(val) |
| 761 |
hdr.Len = size * count |
| 762 |
hdr.Cap = size * count |
| 763 |
|
| 764 |
length, err := cc.CopyOutBytes(addr, buf) |
| 765 |
|
| 766 |
|
| 767 |
runtime.KeepAlive(src) |
| 768 |
return length, err |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
func MarshalUnsafeInt8Slice(src []Int8, dst []byte) []byte { |
| 773 |
count := len(src) |
| 774 |
if count == 0 { |
| 775 |
return dst |
| 776 |
} |
| 777 |
size := (*Int8)(nil).SizeBytes() |
| 778 |
|
| 779 |
buf := dst[:size*count] |
| 780 |
gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) |
| 781 |
return dst[size*count:] |
| 782 |
} |
| 783 |
|
| 784 |
|
| 785 |
func UnmarshalUnsafeInt8Slice(dst []Int8, src []byte) []byte { |
| 786 |
count := len(dst) |
| 787 |
if count == 0 { |
| 788 |
return src |
| 789 |
} |
| 790 |
size := (*Int8)(nil).SizeBytes() |
| 791 |
|
| 792 |
buf := src[:size*count] |
| 793 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) |
| 794 |
return src[size*count:] |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
func (u *Uint16) SizeBytes() int { |
| 800 |
return 2 |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
func (u *Uint16) MarshalBytes(dst []byte) []byte { |
| 805 |
hostarch.ByteOrder.PutUint16(dst[:2], uint16(*u)) |
| 806 |
return dst[2:] |
| 807 |
} |
| 808 |
|
| 809 |
|
| 810 |
func (u *Uint16) UnmarshalBytes(src []byte) []byte { |
| 811 |
*u = Uint16(uint16(hostarch.ByteOrder.Uint16(src[:2]))) |
| 812 |
return src[2:] |
| 813 |
} |
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
func (u *Uint16) Packed() bool { |
| 818 |
|
| 819 |
return true |
| 820 |
} |
| 821 |
|
| 822 |
|
| 823 |
func (u *Uint16) MarshalUnsafe(dst []byte) []byte { |
| 824 |
size := u.SizeBytes() |
| 825 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) |
| 826 |
return dst[size:] |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
func (u *Uint16) UnmarshalUnsafe(src []byte) []byte { |
| 831 |
size := u.SizeBytes() |
| 832 |
gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) |
| 833 |
return src[size:] |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
func (u *Uint16) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { |
| 839 |
|
| 840 |
var buf []byte |
| 841 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 842 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 843 |
hdr.Len = u.SizeBytes() |
| 844 |
hdr.Cap = u.SizeBytes() |
| 845 |
|
| 846 |
length, err := cc.CopyOutBytes(addr, buf[:limit]) |
| 847 |
|
| 848 |
|
| 849 |
runtime.KeepAlive(u) |
| 850 |
return length, err |
| 851 |
} |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
func (u *Uint16) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 856 |
return u.CopyOutN(cc, addr, u.SizeBytes()) |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
func (u *Uint16) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 862 |
|
| 863 |
var buf []byte |
| 864 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 865 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 866 |
hdr.Len = u.SizeBytes() |
| 867 |
hdr.Cap = u.SizeBytes() |
| 868 |
|
| 869 |
length, err := cc.CopyInBytes(addr, buf) |
| 870 |
|
| 871 |
|
| 872 |
runtime.KeepAlive(u) |
| 873 |
return length, err |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
func (u *Uint16) WriteTo(writer io.Writer) (int64, error) { |
| 878 |
|
| 879 |
var buf []byte |
| 880 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 881 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 882 |
hdr.Len = u.SizeBytes() |
| 883 |
hdr.Cap = u.SizeBytes() |
| 884 |
|
| 885 |
length, err := writer.Write(buf) |
| 886 |
|
| 887 |
|
| 888 |
runtime.KeepAlive(u) |
| 889 |
return int64(length), err |
| 890 |
} |
| 891 |
|
| 892 |
|
| 893 |
func (u *Uint16) CheckedMarshal(dst []byte) ([]byte, bool) { |
| 894 |
size := u.SizeBytes() |
| 895 |
if size > len(dst) { |
| 896 |
return dst, false |
| 897 |
} |
| 898 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) |
| 899 |
return dst[size:], true |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
func (u *Uint16) CheckedUnmarshal(src []byte) ([]byte, bool) { |
| 904 |
size := u.SizeBytes() |
| 905 |
if size > len(src) { |
| 906 |
return src, false |
| 907 |
} |
| 908 |
gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) |
| 909 |
return src[size:], true |
| 910 |
} |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
func CopyUint16SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []uint16) (int, error) { |
| 915 |
count := len(dst) |
| 916 |
if count == 0 { |
| 917 |
return 0, nil |
| 918 |
} |
| 919 |
size := (*Uint16)(nil).SizeBytes() |
| 920 |
|
| 921 |
ptr := unsafe.Pointer(&dst) |
| 922 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 923 |
|
| 924 |
|
| 925 |
var buf []byte |
| 926 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 927 |
hdr.Data = uintptr(val) |
| 928 |
hdr.Len = size * count |
| 929 |
hdr.Cap = size * count |
| 930 |
|
| 931 |
length, err := cc.CopyInBytes(addr, buf) |
| 932 |
|
| 933 |
|
| 934 |
runtime.KeepAlive(dst) |
| 935 |
return length, err |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
func CopyUint16SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []uint16) (int, error) { |
| 941 |
count := len(src) |
| 942 |
if count == 0 { |
| 943 |
return 0, nil |
| 944 |
} |
| 945 |
size := (*Uint16)(nil).SizeBytes() |
| 946 |
|
| 947 |
ptr := unsafe.Pointer(&src) |
| 948 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 949 |
|
| 950 |
|
| 951 |
var buf []byte |
| 952 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 953 |
hdr.Data = uintptr(val) |
| 954 |
hdr.Len = size * count |
| 955 |
hdr.Cap = size * count |
| 956 |
|
| 957 |
length, err := cc.CopyOutBytes(addr, buf) |
| 958 |
|
| 959 |
|
| 960 |
runtime.KeepAlive(src) |
| 961 |
return length, err |
| 962 |
} |
| 963 |
|
| 964 |
|
| 965 |
func MarshalUnsafeUint16Slice(src []Uint16, dst []byte) []byte { |
| 966 |
count := len(src) |
| 967 |
if count == 0 { |
| 968 |
return dst |
| 969 |
} |
| 970 |
size := (*Uint16)(nil).SizeBytes() |
| 971 |
|
| 972 |
buf := dst[:size*count] |
| 973 |
gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) |
| 974 |
return dst[size*count:] |
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
func UnmarshalUnsafeUint16Slice(dst []Uint16, src []byte) []byte { |
| 979 |
count := len(dst) |
| 980 |
if count == 0 { |
| 981 |
return src |
| 982 |
} |
| 983 |
size := (*Uint16)(nil).SizeBytes() |
| 984 |
|
| 985 |
buf := src[:size*count] |
| 986 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) |
| 987 |
return src[size*count:] |
| 988 |
} |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
func (u *Uint32) SizeBytes() int { |
| 993 |
return 4 |
| 994 |
} |
| 995 |
|
| 996 |
|
| 997 |
func (u *Uint32) MarshalBytes(dst []byte) []byte { |
| 998 |
hostarch.ByteOrder.PutUint32(dst[:4], uint32(*u)) |
| 999 |
return dst[4:] |
| 1000 |
} |
| 1001 |
|
| 1002 |
|
| 1003 |
func (u *Uint32) UnmarshalBytes(src []byte) []byte { |
| 1004 |
*u = Uint32(uint32(hostarch.ByteOrder.Uint32(src[:4]))) |
| 1005 |
return src[4:] |
| 1006 |
} |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
func (u *Uint32) Packed() bool { |
| 1011 |
|
| 1012 |
return true |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
func (u *Uint32) MarshalUnsafe(dst []byte) []byte { |
| 1017 |
size := u.SizeBytes() |
| 1018 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) |
| 1019 |
return dst[size:] |
| 1020 |
} |
| 1021 |
|
| 1022 |
|
| 1023 |
func (u *Uint32) UnmarshalUnsafe(src []byte) []byte { |
| 1024 |
size := u.SizeBytes() |
| 1025 |
gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) |
| 1026 |
return src[size:] |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
func (u *Uint32) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { |
| 1032 |
|
| 1033 |
var buf []byte |
| 1034 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1035 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 1036 |
hdr.Len = u.SizeBytes() |
| 1037 |
hdr.Cap = u.SizeBytes() |
| 1038 |
|
| 1039 |
length, err := cc.CopyOutBytes(addr, buf[:limit]) |
| 1040 |
|
| 1041 |
|
| 1042 |
runtime.KeepAlive(u) |
| 1043 |
return length, err |
| 1044 |
} |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
func (u *Uint32) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 1049 |
return u.CopyOutN(cc, addr, u.SizeBytes()) |
| 1050 |
} |
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
func (u *Uint32) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 1055 |
|
| 1056 |
var buf []byte |
| 1057 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1058 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 1059 |
hdr.Len = u.SizeBytes() |
| 1060 |
hdr.Cap = u.SizeBytes() |
| 1061 |
|
| 1062 |
length, err := cc.CopyInBytes(addr, buf) |
| 1063 |
|
| 1064 |
|
| 1065 |
runtime.KeepAlive(u) |
| 1066 |
return length, err |
| 1067 |
} |
| 1068 |
|
| 1069 |
|
| 1070 |
func (u *Uint32) WriteTo(writer io.Writer) (int64, error) { |
| 1071 |
|
| 1072 |
var buf []byte |
| 1073 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1074 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 1075 |
hdr.Len = u.SizeBytes() |
| 1076 |
hdr.Cap = u.SizeBytes() |
| 1077 |
|
| 1078 |
length, err := writer.Write(buf) |
| 1079 |
|
| 1080 |
|
| 1081 |
runtime.KeepAlive(u) |
| 1082 |
return int64(length), err |
| 1083 |
} |
| 1084 |
|
| 1085 |
|
| 1086 |
func (u *Uint32) CheckedMarshal(dst []byte) ([]byte, bool) { |
| 1087 |
size := u.SizeBytes() |
| 1088 |
if size > len(dst) { |
| 1089 |
return dst, false |
| 1090 |
} |
| 1091 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) |
| 1092 |
return dst[size:], true |
| 1093 |
} |
| 1094 |
|
| 1095 |
|
| 1096 |
func (u *Uint32) CheckedUnmarshal(src []byte) ([]byte, bool) { |
| 1097 |
size := u.SizeBytes() |
| 1098 |
if size > len(src) { |
| 1099 |
return src, false |
| 1100 |
} |
| 1101 |
gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) |
| 1102 |
return src[size:], true |
| 1103 |
} |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
func CopyUint32SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []uint32) (int, error) { |
| 1108 |
count := len(dst) |
| 1109 |
if count == 0 { |
| 1110 |
return 0, nil |
| 1111 |
} |
| 1112 |
size := (*Uint32)(nil).SizeBytes() |
| 1113 |
|
| 1114 |
ptr := unsafe.Pointer(&dst) |
| 1115 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 1116 |
|
| 1117 |
|
| 1118 |
var buf []byte |
| 1119 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1120 |
hdr.Data = uintptr(val) |
| 1121 |
hdr.Len = size * count |
| 1122 |
hdr.Cap = size * count |
| 1123 |
|
| 1124 |
length, err := cc.CopyInBytes(addr, buf) |
| 1125 |
|
| 1126 |
|
| 1127 |
runtime.KeepAlive(dst) |
| 1128 |
return length, err |
| 1129 |
} |
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
func CopyUint32SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []uint32) (int, error) { |
| 1134 |
count := len(src) |
| 1135 |
if count == 0 { |
| 1136 |
return 0, nil |
| 1137 |
} |
| 1138 |
size := (*Uint32)(nil).SizeBytes() |
| 1139 |
|
| 1140 |
ptr := unsafe.Pointer(&src) |
| 1141 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 1142 |
|
| 1143 |
|
| 1144 |
var buf []byte |
| 1145 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1146 |
hdr.Data = uintptr(val) |
| 1147 |
hdr.Len = size * count |
| 1148 |
hdr.Cap = size * count |
| 1149 |
|
| 1150 |
length, err := cc.CopyOutBytes(addr, buf) |
| 1151 |
|
| 1152 |
|
| 1153 |
runtime.KeepAlive(src) |
| 1154 |
return length, err |
| 1155 |
} |
| 1156 |
|
| 1157 |
|
| 1158 |
func MarshalUnsafeUint32Slice(src []Uint32, dst []byte) []byte { |
| 1159 |
count := len(src) |
| 1160 |
if count == 0 { |
| 1161 |
return dst |
| 1162 |
} |
| 1163 |
size := (*Uint32)(nil).SizeBytes() |
| 1164 |
|
| 1165 |
buf := dst[:size*count] |
| 1166 |
gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) |
| 1167 |
return dst[size*count:] |
| 1168 |
} |
| 1169 |
|
| 1170 |
|
| 1171 |
func UnmarshalUnsafeUint32Slice(dst []Uint32, src []byte) []byte { |
| 1172 |
count := len(dst) |
| 1173 |
if count == 0 { |
| 1174 |
return src |
| 1175 |
} |
| 1176 |
size := (*Uint32)(nil).SizeBytes() |
| 1177 |
|
| 1178 |
buf := src[:size*count] |
| 1179 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) |
| 1180 |
return src[size*count:] |
| 1181 |
} |
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
func (u *Uint64) SizeBytes() int { |
| 1186 |
return 8 |
| 1187 |
} |
| 1188 |
|
| 1189 |
|
| 1190 |
func (u *Uint64) MarshalBytes(dst []byte) []byte { |
| 1191 |
hostarch.ByteOrder.PutUint64(dst[:8], uint64(*u)) |
| 1192 |
return dst[8:] |
| 1193 |
} |
| 1194 |
|
| 1195 |
|
| 1196 |
func (u *Uint64) UnmarshalBytes(src []byte) []byte { |
| 1197 |
*u = Uint64(uint64(hostarch.ByteOrder.Uint64(src[:8]))) |
| 1198 |
return src[8:] |
| 1199 |
} |
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
func (u *Uint64) Packed() bool { |
| 1204 |
|
| 1205 |
return true |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
func (u *Uint64) MarshalUnsafe(dst []byte) []byte { |
| 1210 |
size := u.SizeBytes() |
| 1211 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) |
| 1212 |
return dst[size:] |
| 1213 |
} |
| 1214 |
|
| 1215 |
|
| 1216 |
func (u *Uint64) UnmarshalUnsafe(src []byte) []byte { |
| 1217 |
size := u.SizeBytes() |
| 1218 |
gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) |
| 1219 |
return src[size:] |
| 1220 |
} |
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
func (u *Uint64) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { |
| 1225 |
|
| 1226 |
var buf []byte |
| 1227 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1228 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 1229 |
hdr.Len = u.SizeBytes() |
| 1230 |
hdr.Cap = u.SizeBytes() |
| 1231 |
|
| 1232 |
length, err := cc.CopyOutBytes(addr, buf[:limit]) |
| 1233 |
|
| 1234 |
|
| 1235 |
runtime.KeepAlive(u) |
| 1236 |
return length, err |
| 1237 |
} |
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
func (u *Uint64) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 1242 |
return u.CopyOutN(cc, addr, u.SizeBytes()) |
| 1243 |
} |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
func (u *Uint64) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 1248 |
|
| 1249 |
var buf []byte |
| 1250 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1251 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 1252 |
hdr.Len = u.SizeBytes() |
| 1253 |
hdr.Cap = u.SizeBytes() |
| 1254 |
|
| 1255 |
length, err := cc.CopyInBytes(addr, buf) |
| 1256 |
|
| 1257 |
|
| 1258 |
runtime.KeepAlive(u) |
| 1259 |
return length, err |
| 1260 |
} |
| 1261 |
|
| 1262 |
|
| 1263 |
func (u *Uint64) WriteTo(writer io.Writer) (int64, error) { |
| 1264 |
|
| 1265 |
var buf []byte |
| 1266 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1267 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 1268 |
hdr.Len = u.SizeBytes() |
| 1269 |
hdr.Cap = u.SizeBytes() |
| 1270 |
|
| 1271 |
length, err := writer.Write(buf) |
| 1272 |
|
| 1273 |
|
| 1274 |
runtime.KeepAlive(u) |
| 1275 |
return int64(length), err |
| 1276 |
} |
| 1277 |
|
| 1278 |
|
| 1279 |
func (u *Uint64) CheckedMarshal(dst []byte) ([]byte, bool) { |
| 1280 |
size := u.SizeBytes() |
| 1281 |
if size > len(dst) { |
| 1282 |
return dst, false |
| 1283 |
} |
| 1284 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) |
| 1285 |
return dst[size:], true |
| 1286 |
} |
| 1287 |
|
| 1288 |
|
| 1289 |
func (u *Uint64) CheckedUnmarshal(src []byte) ([]byte, bool) { |
| 1290 |
size := u.SizeBytes() |
| 1291 |
if size > len(src) { |
| 1292 |
return src, false |
| 1293 |
} |
| 1294 |
gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) |
| 1295 |
return src[size:], true |
| 1296 |
} |
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
func CopyUint64SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []uint64) (int, error) { |
| 1301 |
count := len(dst) |
| 1302 |
if count == 0 { |
| 1303 |
return 0, nil |
| 1304 |
} |
| 1305 |
size := (*Uint64)(nil).SizeBytes() |
| 1306 |
|
| 1307 |
ptr := unsafe.Pointer(&dst) |
| 1308 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 1309 |
|
| 1310 |
|
| 1311 |
var buf []byte |
| 1312 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1313 |
hdr.Data = uintptr(val) |
| 1314 |
hdr.Len = size * count |
| 1315 |
hdr.Cap = size * count |
| 1316 |
|
| 1317 |
length, err := cc.CopyInBytes(addr, buf) |
| 1318 |
|
| 1319 |
|
| 1320 |
runtime.KeepAlive(dst) |
| 1321 |
return length, err |
| 1322 |
} |
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
func CopyUint64SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []uint64) (int, error) { |
| 1327 |
count := len(src) |
| 1328 |
if count == 0 { |
| 1329 |
return 0, nil |
| 1330 |
} |
| 1331 |
size := (*Uint64)(nil).SizeBytes() |
| 1332 |
|
| 1333 |
ptr := unsafe.Pointer(&src) |
| 1334 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 1335 |
|
| 1336 |
|
| 1337 |
var buf []byte |
| 1338 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1339 |
hdr.Data = uintptr(val) |
| 1340 |
hdr.Len = size * count |
| 1341 |
hdr.Cap = size * count |
| 1342 |
|
| 1343 |
length, err := cc.CopyOutBytes(addr, buf) |
| 1344 |
|
| 1345 |
|
| 1346 |
runtime.KeepAlive(src) |
| 1347 |
return length, err |
| 1348 |
} |
| 1349 |
|
| 1350 |
|
| 1351 |
func MarshalUnsafeUint64Slice(src []Uint64, dst []byte) []byte { |
| 1352 |
count := len(src) |
| 1353 |
if count == 0 { |
| 1354 |
return dst |
| 1355 |
} |
| 1356 |
size := (*Uint64)(nil).SizeBytes() |
| 1357 |
|
| 1358 |
buf := dst[:size*count] |
| 1359 |
gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) |
| 1360 |
return dst[size*count:] |
| 1361 |
} |
| 1362 |
|
| 1363 |
|
| 1364 |
func UnmarshalUnsafeUint64Slice(dst []Uint64, src []byte) []byte { |
| 1365 |
count := len(dst) |
| 1366 |
if count == 0 { |
| 1367 |
return src |
| 1368 |
} |
| 1369 |
size := (*Uint64)(nil).SizeBytes() |
| 1370 |
|
| 1371 |
buf := src[:size*count] |
| 1372 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) |
| 1373 |
return src[size*count:] |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
func (u *Uint8) SizeBytes() int { |
| 1379 |
return 1 |
| 1380 |
} |
| 1381 |
|
| 1382 |
|
| 1383 |
func (u *Uint8) MarshalBytes(dst []byte) []byte { |
| 1384 |
dst[0] = byte(*u) |
| 1385 |
return dst[1:] |
| 1386 |
} |
| 1387 |
|
| 1388 |
|
| 1389 |
func (u *Uint8) UnmarshalBytes(src []byte) []byte { |
| 1390 |
*u = Uint8(uint8(src[0])) |
| 1391 |
return src[1:] |
| 1392 |
} |
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
func (u *Uint8) Packed() bool { |
| 1397 |
|
| 1398 |
return true |
| 1399 |
} |
| 1400 |
|
| 1401 |
|
| 1402 |
func (u *Uint8) MarshalUnsafe(dst []byte) []byte { |
| 1403 |
size := u.SizeBytes() |
| 1404 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) |
| 1405 |
return dst[size:] |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
func (u *Uint8) UnmarshalUnsafe(src []byte) []byte { |
| 1410 |
size := u.SizeBytes() |
| 1411 |
gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) |
| 1412 |
return src[size:] |
| 1413 |
} |
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
func (u *Uint8) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error) { |
| 1418 |
|
| 1419 |
var buf []byte |
| 1420 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1421 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 1422 |
hdr.Len = u.SizeBytes() |
| 1423 |
hdr.Cap = u.SizeBytes() |
| 1424 |
|
| 1425 |
length, err := cc.CopyOutBytes(addr, buf[:limit]) |
| 1426 |
|
| 1427 |
|
| 1428 |
runtime.KeepAlive(u) |
| 1429 |
return length, err |
| 1430 |
} |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
func (u *Uint8) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 1435 |
return u.CopyOutN(cc, addr, u.SizeBytes()) |
| 1436 |
} |
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
func (u *Uint8) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error) { |
| 1441 |
|
| 1442 |
var buf []byte |
| 1443 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1444 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 1445 |
hdr.Len = u.SizeBytes() |
| 1446 |
hdr.Cap = u.SizeBytes() |
| 1447 |
|
| 1448 |
length, err := cc.CopyInBytes(addr, buf) |
| 1449 |
|
| 1450 |
|
| 1451 |
runtime.KeepAlive(u) |
| 1452 |
return length, err |
| 1453 |
} |
| 1454 |
|
| 1455 |
|
| 1456 |
func (u *Uint8) WriteTo(writer io.Writer) (int64, error) { |
| 1457 |
|
| 1458 |
var buf []byte |
| 1459 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1460 |
hdr.Data = uintptr(gohacks.Noescape(unsafe.Pointer(u))) |
| 1461 |
hdr.Len = u.SizeBytes() |
| 1462 |
hdr.Cap = u.SizeBytes() |
| 1463 |
|
| 1464 |
length, err := writer.Write(buf) |
| 1465 |
|
| 1466 |
|
| 1467 |
runtime.KeepAlive(u) |
| 1468 |
return int64(length), err |
| 1469 |
} |
| 1470 |
|
| 1471 |
|
| 1472 |
func (u *Uint8) CheckedMarshal(dst []byte) ([]byte, bool) { |
| 1473 |
size := u.SizeBytes() |
| 1474 |
if size > len(dst) { |
| 1475 |
return dst, false |
| 1476 |
} |
| 1477 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(u), uintptr(size)) |
| 1478 |
return dst[size:], true |
| 1479 |
} |
| 1480 |
|
| 1481 |
|
| 1482 |
func (u *Uint8) CheckedUnmarshal(src []byte) ([]byte, bool) { |
| 1483 |
size := u.SizeBytes() |
| 1484 |
if size > len(src) { |
| 1485 |
return src, false |
| 1486 |
} |
| 1487 |
gohacks.Memmove(unsafe.Pointer(u), unsafe.Pointer(&src[0]), uintptr(size)) |
| 1488 |
return src[size:], true |
| 1489 |
} |
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
func CopyUint8SliceIn(cc marshal.CopyContext, addr hostarch.Addr, dst []uint8) (int, error) { |
| 1494 |
count := len(dst) |
| 1495 |
if count == 0 { |
| 1496 |
return 0, nil |
| 1497 |
} |
| 1498 |
size := (*Uint8)(nil).SizeBytes() |
| 1499 |
|
| 1500 |
ptr := unsafe.Pointer(&dst) |
| 1501 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 1502 |
|
| 1503 |
|
| 1504 |
var buf []byte |
| 1505 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1506 |
hdr.Data = uintptr(val) |
| 1507 |
hdr.Len = size * count |
| 1508 |
hdr.Cap = size * count |
| 1509 |
|
| 1510 |
length, err := cc.CopyInBytes(addr, buf) |
| 1511 |
|
| 1512 |
|
| 1513 |
runtime.KeepAlive(dst) |
| 1514 |
return length, err |
| 1515 |
} |
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
func CopyUint8SliceOut(cc marshal.CopyContext, addr hostarch.Addr, src []uint8) (int, error) { |
| 1520 |
count := len(src) |
| 1521 |
if count == 0 { |
| 1522 |
return 0, nil |
| 1523 |
} |
| 1524 |
size := (*Uint8)(nil).SizeBytes() |
| 1525 |
|
| 1526 |
ptr := unsafe.Pointer(&src) |
| 1527 |
val := gohacks.Noescape(unsafe.Pointer((*reflect.SliceHeader)(ptr).Data)) |
| 1528 |
|
| 1529 |
|
| 1530 |
var buf []byte |
| 1531 |
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) |
| 1532 |
hdr.Data = uintptr(val) |
| 1533 |
hdr.Len = size * count |
| 1534 |
hdr.Cap = size * count |
| 1535 |
|
| 1536 |
length, err := cc.CopyOutBytes(addr, buf) |
| 1537 |
|
| 1538 |
|
| 1539 |
runtime.KeepAlive(src) |
| 1540 |
return length, err |
| 1541 |
} |
| 1542 |
|
| 1543 |
|
| 1544 |
func MarshalUnsafeUint8Slice(src []Uint8, dst []byte) []byte { |
| 1545 |
count := len(src) |
| 1546 |
if count == 0 { |
| 1547 |
return dst |
| 1548 |
} |
| 1549 |
size := (*Uint8)(nil).SizeBytes() |
| 1550 |
|
| 1551 |
buf := dst[:size*count] |
| 1552 |
gohacks.Memmove(unsafe.Pointer(&buf[0]), unsafe.Pointer(&src[0]), uintptr(len(buf))) |
| 1553 |
return dst[size*count:] |
| 1554 |
} |
| 1555 |
|
| 1556 |
|
| 1557 |
func UnmarshalUnsafeUint8Slice(dst []Uint8, src []byte) []byte { |
| 1558 |
count := len(dst) |
| 1559 |
if count == 0 { |
| 1560 |
return src |
| 1561 |
} |
| 1562 |
size := (*Uint8)(nil).SizeBytes() |
| 1563 |
|
| 1564 |
buf := src[:size*count] |
| 1565 |
gohacks.Memmove(unsafe.Pointer(&dst[0]), unsafe.Pointer(&buf[0]), uintptr(len(buf))) |
| 1566 |
return src[size*count:] |
| 1567 |
} |
| 1568 |
|