-
Notifications
You must be signed in to change notification settings - Fork 0
/
mult.go
65 lines (59 loc) · 974 Bytes
/
mult.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
/*
* MULTI/FORMAT/CODEC I/O
* Copyright 2023 John Douglas Pritchard, Syntelos
*
*
* References
*
* https://github.com/multiformats/multicodec/blob/master/table.csv
* https://multiformats.io/
*/
package mult
import (
"io"
)
/*
*/
type Object []byte
/*
* Binary code user interface.
*/
type IO interface {
/*
* The MULT producer is replicating.
*/
Write(io.Writer) (error)
/*
* The MULT consumer is validating.
*/
Read(io.Reader) (Object, error)
}
/*
*/
func Copy(dst []byte, dx, dz int, src []byte, sx, sz int) ([]byte) {
for dx < dz && sx < sz {
dst[dx] = src[sx]
dx += 1
sx += 1
}
return dst
}
/*
*/
func Concatenate(a, b []byte) ([]byte) {
var a_len int = len(a)
if 0 == a_len {
return b
} else {
var b_len int = len(b)
if 0 == b_len {
return a
} else {
var c_len int = (a_len+b_len)
var c []byte = make([]byte,c_len)
c = Copy(c,0,c_len,a,0,a_len)
c = Copy(c,a_len,c_len,b,0,b_len)
return c
}
}
}