Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cefca8ad91
|
||
|
|
a86367b5b9
|
||
|
|
72818c2d5c
|
||
|
|
9b39811206
|
@@ -15,5 +15,10 @@ for f in $(find . -maxdepth 1 -type f -iname "*.adoc"); do
|
|||||||
|
|
||||||
asciidoctor -o "${docsdir}/${nosuffix}.html" "${f}"
|
asciidoctor -o "${docsdir}/${nosuffix}.html" "${f}"
|
||||||
git add "${docsdir}/${nosuffix}.html"
|
git add "${docsdir}/${nosuffix}.html"
|
||||||
|
if command -v pandoc &> /dev/null;
|
||||||
|
then
|
||||||
|
asciidoctor -b docbook -o - "${f}" | pandoc -f docbook -t markdown_strict -o "${docsdir}/${nosuffix}.md"
|
||||||
|
git add "${docsdir}/${nosuffix}.md"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
echo "Regenerated docs"
|
echo "Regenerated docs"
|
||||||
|
|||||||
13
README.adoc
13
README.adoc
@@ -23,12 +23,12 @@ Last rendered {localdatetime}
|
|||||||
|
|
||||||
[id="ref"]
|
[id="ref"]
|
||||||
== Reference
|
== Reference
|
||||||
In addition to the documentation found in this document and https://wireproto.io/[the specification^], library usage documentation can be found at https://pkg.go.dev/go.pkg.dev/r00t2.io/WireProto[the Golang module documentation page^]:
|
In addition to the documentation found in this document and https://wireproto.io/[the specification^], library usage documentation can be found at https://pkg.go.dev/r00t2.io/wireproto[the Golang module documentation page^]:
|
||||||
|
|
||||||
++++
|
++++
|
||||||
<a href="https://pkg.go.dev/go.pkg.dev/r00t2.io/wireproto">
|
<a href="https://go.pkg.dev/r00t2.io/wireproto">
|
||||||
<img src="https://pkg.go.dev/badge/go.pkg.dev/r00t2.io/wireproto.svg"
|
<img src="https://pkg.go.dev/badge/r00t2.io/wireproto.svg"
|
||||||
alt="Go Reference">
|
alt="Go Reference"/>
|
||||||
</a>
|
</a>
|
||||||
++++
|
++++
|
||||||
|
|
||||||
@@ -52,8 +52,11 @@ The following are a wishlist or things planned that may come in later versions.
|
|||||||
* More clear errors
|
* More clear errors
|
||||||
** Currently during e.g. `UnmarshalBinary` calls, just an `io.EOF` will be returned if the buffer is exhausted early. This may be able to be a little more context-helpful by using the `Err*` errors.
|
** Currently during e.g. `UnmarshalBinary` calls, just an `io.EOF` will be returned if the buffer is exhausted early. This may be able to be a little more context-helpful by using the `Err*` errors.
|
||||||
* Confirmation of read/write sizes in buffers
|
* Confirmation of read/write sizes in buffers
|
||||||
** We know the sizes they *should* be, there's no reason to not confirm it.
|
** The sizes they *should* be are known, there's no reason to not confirm it.
|
||||||
* Goroutines
|
* Goroutines
|
||||||
** This of course won't work for serializing and keeping *order* of children (e.g. RG => Record); that'd still need to be ordered, but it will allow for parallel parsing *of* those children. Should benchmark, though; it may not be worth it.
|
** This of course won't work for serializing and keeping *order* of children (e.g. RG => Record); that'd still need to be ordered, but it will allow for parallel parsing *of* those children. Should benchmark, though; it may not be worth it.
|
||||||
* `context.Context` support for `Read*` and `Write*` funcs
|
* `context.Context` support for `Read*` and `Write*` funcs
|
||||||
** This is a relatively low priority as the passed `net.Conn` will likely return an error if its own context is canceled. This can be handled in the caller downstream.
|
** This is a relatively low priority as the passed `net.Conn` will likely return an error if its own context is canceled. This can be handled in the caller downstream.
|
||||||
|
* `.Append*()` methods to append any type to any parent type. e.g. `<Response>.AppendFVP(<FieldValuePair>)` would append an FVP to the most recent ResponseRecord to the most recent ResponseRecordGroup (or create if they don't exist), `<Response>.AppendRecord(...)` for appending a record to most recent record group etc.
|
||||||
|
* Better/more strict interfaces
|
||||||
|
* Maps should be `any`, not `interface{}` values
|
||||||
|
|||||||
27
README.html
27
README.html
@@ -476,6 +476,10 @@ pre.rouge .gi {
|
|||||||
color: #116329;
|
color: #116329;
|
||||||
background-color: #dafbe1;
|
background-color: #dafbe1;
|
||||||
}
|
}
|
||||||
|
pre.rouge .ges {
|
||||||
|
font-weight: bold;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
pre.rouge .kc {
|
pre.rouge .kc {
|
||||||
color: #0550ae;
|
color: #0550ae;
|
||||||
}
|
}
|
||||||
@@ -555,7 +559,7 @@ pre.rouge .gs {
|
|||||||
<div class="details">
|
<div class="details">
|
||||||
<span id="author" class="author">Brent Saner</span><br>
|
<span id="author" class="author">Brent Saner</span><br>
|
||||||
<span id="email" class="email"><a href="mailto:bts@square-r00t.net">bts@square-r00t.net</a></span><br>
|
<span id="email" class="email"><a href="mailto:bts@square-r00t.net">bts@square-r00t.net</a></span><br>
|
||||||
<span id="revdate">Last rendered 2024-07-10 00:18:53 -0400</span>
|
<span id="revdate">Last rendered 2025-09-30 14:15:01 -0400</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="toc" class="toc2">
|
<div id="toc" class="toc2">
|
||||||
<div id="toctitle">Table of Contents</div>
|
<div id="toctitle">Table of Contents</div>
|
||||||
@@ -571,11 +575,11 @@ pre.rouge .gs {
|
|||||||
<h2 id="ref"><a class="link" href="#ref">1. Reference</a></h2>
|
<h2 id="ref"><a class="link" href="#ref">1. Reference</a></h2>
|
||||||
<div class="sectionbody">
|
<div class="sectionbody">
|
||||||
<div class="paragraph">
|
<div class="paragraph">
|
||||||
<p>In addition to the documentation found in this document and <a href="https://wireproto.io/" target="_blank" rel="noopener">the specification</a>, library usage documentation can be found at <a href="https://pkg.go.dev/go.pkg.dev/r00t2.io/WireProto" target="_blank" rel="noopener">the Golang module documentation page</a>:</p>
|
<p>In addition to the documentation found in this document and <a href="https://wireproto.io/" target="_blank" rel="noopener">the specification</a>, library usage documentation can be found at <a href="https://pkg.go.dev/r00t2.io/wireproto" target="_blank" rel="noopener">the Golang module documentation page</a>:</p>
|
||||||
</div>
|
</div>
|
||||||
<a href="https://pkg.go.dev/go.pkg.dev/r00t2.io/wireproto">
|
<a href="https://go.pkg.dev/r00t2.io/wireproto">
|
||||||
<img src="https://pkg.go.dev/badge/go.pkg.dev/r00t2.io/wireproto.svg"
|
<img src="https://pkg.go.dev/badge/r00t2.io/wireproto.svg"
|
||||||
alt="Go Reference">
|
alt="Go Reference"/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -630,7 +634,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
<div class="ulist">
|
<div class="ulist">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<p>We know the sizes they <strong>should</strong> be, there’s no reason to not confirm it.</p>
|
<p>The sizes they <strong>should</strong> be are known, there’s no reason to not confirm it.</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -655,6 +659,15 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<p><code>.Append*()</code> methods to append any type to any parent type. e.g. <code><Response>.AppendFVP(<FieldValuePair>)</code> would append an FVP to the most recent ResponseRecord to the most recent ResponseRecordGroup (or create if they don’t exist), <code><Response>.AppendRecord(…​)</code> for appending a record to most recent record group etc.</p>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<p>Better/more strict interfaces</p>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<p>Maps should be <code>any</code>, not <code>interface{}</code> values</p>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -662,7 +675,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
</div>
|
</div>
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
<div id="footer-text">
|
<div id="footer-text">
|
||||||
Last updated 2024-07-09 16:54:13 -0400
|
Last updated 2025-09-25 17:54:36 -0400
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
63
README.md
Normal file
63
README.md
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
# Reference
|
||||||
|
|
||||||
|
In addition to the documentation found in this document and [the
|
||||||
|
specification](https://wireproto.io/), library usage documentation can
|
||||||
|
be found at [the Golang module documentation
|
||||||
|
page](https://pkg.go.dev/r00t2.io/wireproto):
|
||||||
|
|
||||||
|
# License
|
||||||
|
|
||||||
|
This library is licensed for use, inclusion, and distribution under the
|
||||||
|
["3-Clause BSD" license](https://opensource.org/license/bsd-3-clause).
|
||||||
|
|
||||||
|
Copyright (c) 2024 Brent Saner (r00t^2).
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
The following are a wishlist or things planned that may come in later
|
||||||
|
versions.
|
||||||
|
|
||||||
|
- More clear errors
|
||||||
|
|
||||||
|
- Currently during e.g. `UnmarshalBinary` calls, just an `io.EOF`
|
||||||
|
will be returned if the buffer is exhausted early. This may be
|
||||||
|
able to be a little more context-helpful by using the `Err*`
|
||||||
|
errors.
|
||||||
|
|
||||||
|
- Confirmation of read/write sizes in buffers
|
||||||
|
|
||||||
|
- The sizes they **should** be are known, there’s no reason to not
|
||||||
|
confirm it.
|
||||||
|
|
||||||
|
- Goroutines
|
||||||
|
|
||||||
|
- This of course won’t work for serializing and keeping **order**
|
||||||
|
of children (e.g. RG ⇒ Record); that’d still need to be ordered,
|
||||||
|
but it will allow for parallel parsing **of** those children.
|
||||||
|
Should benchmark, though; it may not be worth it.
|
||||||
|
|
||||||
|
- `context.Context` support for `Read*` and `Write*` funcs
|
||||||
|
|
||||||
|
- This is a relatively low priority as the passed `net.Conn` will
|
||||||
|
likely return an error if its own context is canceled. This can
|
||||||
|
be handled in the caller downstream.
|
||||||
|
|
||||||
|
- `.Append*()` methods to append any type to any parent type. e.g.
|
||||||
|
`<Response>.AppendFVP(<FieldValuePair>)` would append an FVP to the
|
||||||
|
most recent ResponseRecord to the most recent ResponseRecordGroup
|
||||||
|
(or create if they don’t exist), `<Response>.AppendRecord(…)` for
|
||||||
|
appending a record to most recent record group etc.
|
||||||
|
|
||||||
|
- Better/more strict interfaces
|
||||||
|
|
||||||
|
- Maps should be `any`, not `interface{}` values
|
||||||
15
consts.go
15
consts.go
@@ -12,11 +12,14 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// IndentDefault is the [IndentChars] to use if not specified.
|
||||||
IndentDefault string = "\t"
|
IndentDefault string = "\t"
|
||||||
|
// SeperatorDefault is the [SeperatorChars] to use if not specified.
|
||||||
SeparatorDefault string = " "
|
SeparatorDefault string = " "
|
||||||
maxByteLine int = 12 // split if a value is more than this number of bytes..
|
maxByteLine int = 12 // (Split a hex string in a Model if a value is more than this number of bytes.)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Default indent levels.
|
||||||
const (
|
const (
|
||||||
indentR uint = iota
|
indentR uint = iota
|
||||||
indentRG
|
indentRG
|
||||||
@@ -26,18 +29,18 @@ const (
|
|||||||
const indentOrigRec uint = 2
|
const indentOrigRec uint = 2
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ProtoVersion specifies the protocol version for the specification of a Message.
|
// ProtoVersion specifies the protocol version for the specification of a [Message].
|
||||||
ProtoVersion uint32 = 1
|
ProtoVersion uint32 = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// PackedNumSize is the size (length of bytes) of a packed unsigned integer.
|
// PackedNumSize is the size (length of bytes) of a packed unsigned integer.
|
||||||
PackedNumSize int = 4 // They're all uint32's.
|
PackedNumSize int = 4 // (They're all uint32's.)
|
||||||
// CksumPackedSize is the size (length of bytes) of the checksum algorithm used.
|
// CksumPackedSize is the size (length of bytes) of the checksum algorithm used.
|
||||||
CksumPackedSize int = 4 // CRC32 is a big-endian uint32, but if we use a different algo we need to change this.
|
CksumPackedSize int = 4 // CRC32 is represented by a big-endian uint32, but if a different algo is used, this will need to be changed.
|
||||||
)
|
)
|
||||||
|
|
||||||
// See https://square-r00t.net/ascii.html for further details.
|
// See https://square-r00t.net/ascii.html for further details on ASCII symbols.
|
||||||
const (
|
const (
|
||||||
AsciiNUL uint8 = iota // 0x00
|
AsciiNUL uint8 = iota // 0x00
|
||||||
AsciiSOH // 0x01
|
AsciiSOH // 0x01
|
||||||
@@ -73,6 +76,7 @@ const (
|
|||||||
AsciiUS // 0x1f
|
AsciiUS // 0x1f
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Response Status indicator bytes.
|
||||||
const (
|
const (
|
||||||
RespStatusByteOK uint8 = AsciiACK
|
RespStatusByteOK uint8 = AsciiACK
|
||||||
RespStatusByteErr = AsciiNAK
|
RespStatusByteErr = AsciiNAK
|
||||||
@@ -95,5 +99,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// WriteChunkSize is the default size of chunking to use (in bytes) when using chunked Write* functions (i.e. non-segmented).
|
||||||
WriteChunkSize int = 1024
|
WriteChunkSize int = 1024
|
||||||
)
|
)
|
||||||
|
|||||||
2
doc.go
2
doc.go
@@ -5,7 +5,5 @@
|
|||||||
For more details and the actual specification, visit [WireProto].
|
For more details and the actual specification, visit [WireProto].
|
||||||
|
|
||||||
[WireProto]: https://wireproto.io/
|
[WireProto]: https://wireproto.io/
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package wireproto
|
package wireproto
|
||||||
|
|||||||
10
funcs.go
10
funcs.go
@@ -92,7 +92,15 @@ func ReadConnResponse(conn net.Conn) (resp *Response, err error) {
|
|||||||
var size int
|
var size int
|
||||||
var buf *bytes.Buffer = new(bytes.Buffer)
|
var buf *bytes.Buffer = new(bytes.Buffer)
|
||||||
|
|
||||||
// First get the checksum.
|
// Buffer in the status byte...
|
||||||
|
b = make([]byte, 1)
|
||||||
|
if _, err = conn.Read(b); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err = buf.Write(b); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Then get the checksum. Per spec, *all* responses *must* have a checksum.
|
||||||
b = make([]byte, len(hdrCKSUM))
|
b = make([]byte, len(hdrCKSUM))
|
||||||
if _, err = conn.Read(b); err != nil {
|
if _, err = conn.Read(b); err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (r *Request) MarshalBinary() (data []byte, err error) {
|
|||||||
msgSize += i.Size()
|
msgSize += i.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
// The message "body" - we do this first so we can checksum (if not nil).
|
// The message "body" - this is done first so the body can be checksummed (if not nil).
|
||||||
if _, err = msgBuf.Write(hdrBODYSTART); err != nil {
|
if _, err = msgBuf.Write(hdrBODYSTART); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -307,14 +307,14 @@ func (r *Request) UnmarshalBinary(data []byte) (err error) {
|
|||||||
}
|
}
|
||||||
r.Checksum = new(uint32)
|
r.Checksum = new(uint32)
|
||||||
*r.Checksum = byteOrder.Uint32(b)
|
*r.Checksum = byteOrder.Uint32(b)
|
||||||
// Since we've only read the checksum, we now also have to read in the MSGSTART...
|
// Since only the checksum has been read, now read the MSGSTART...
|
||||||
b = make([]byte, len(hdrMSGSTART))
|
b = make([]byte, len(hdrMSGSTART))
|
||||||
if _, err = buf.Read(b); err != nil {
|
if _, err = buf.Read(b); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// But we don't need to do anything with it.
|
// But don't need to do anything with it.
|
||||||
} else {
|
} else {
|
||||||
// We've already read MSGSTART as part of the checksum check.
|
// MSGSTART has already been read as part of the checksum check.
|
||||||
r.Checksum = nil
|
r.Checksum = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +362,7 @@ func (r *Request) UnmarshalBinary(data []byte) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we've validated the checksum (if provided), we trim the msgBuf to only RGs.
|
// Now that the checksum (if provided) has validated, trim the msgBuf to only RGs.
|
||||||
// Skip over the BODYSTART, record group count, and record group size.
|
// Skip over the BODYSTART, record group count, and record group size.
|
||||||
if _, err = msgBuf.Read(make([]byte, len(hdrBODYSTART)+(PackedNumSize*2))); err != nil {
|
if _, err = msgBuf.Read(make([]byte, len(hdrBODYSTART)+(PackedNumSize*2))); err != nil {
|
||||||
return
|
return
|
||||||
@@ -375,7 +375,7 @@ func (r *Request) UnmarshalBinary(data []byte) (err error) {
|
|||||||
for idx := 0; idx < rgCnt; idx++ {
|
for idx := 0; idx < rgCnt; idx++ {
|
||||||
rgBuf = new(bytes.Buffer)
|
rgBuf = new(bytes.Buffer)
|
||||||
|
|
||||||
// The RG unmarshaler handles the record count, but we need to read it to discard it in msgBuf.
|
// The RG unmarshaler handles the record count, but it needs to be put in msgBuf to do that.
|
||||||
if _, err = io.CopyN(rgBuf, msgBuf, int64(PackedNumSize)); err != nil {
|
if _, err = io.CopyN(rgBuf, msgBuf, int64(PackedNumSize)); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ func (r *RequestRecord) UnmarshalBinary(data []byte) (err error) {
|
|||||||
}
|
}
|
||||||
size = UnpackInt(b)
|
size = UnpackInt(b)
|
||||||
|
|
||||||
// And now we handle the FVPs themselves.
|
// And now handle the FVPs themselves.
|
||||||
b = make([]byte, size)
|
b = make([]byte, size)
|
||||||
if _, err = buf.Read(b); err != nil {
|
if _, err = buf.Read(b); err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -199,8 +199,8 @@ func (r *RequestRecordGroup) UnmarshalBinary(data []byte) (err error) {
|
|||||||
for idx := 0; idx < cnt; idx++ {
|
for idx := 0; idx < cnt; idx++ {
|
||||||
recBuf = new(bytes.Buffer)
|
recBuf = new(bytes.Buffer)
|
||||||
|
|
||||||
// We skip over the KVP count; that's handled in the record Unmarshaler.
|
// Skip over the KVP count; that's handled in the record Unmarshaler.
|
||||||
// We *do*, however, need to save it to the recBuf.
|
// It does, however, need to be written to recBuf.
|
||||||
if _, err = io.CopyN(recBuf, buf, int64(PackedNumSize)); err != nil {
|
if _, err = io.CopyN(recBuf, buf, int64(PackedNumSize)); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ func (r *Response) MarshalBinary() (data []byte, err error) {
|
|||||||
msgSize += i.Size()
|
msgSize += i.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
// The message "body" - we do this first so we can checksum .
|
// The message "body" - this is done first so it can be checksummed.
|
||||||
if _, err = msgBuf.Write(hdrBODYSTART); err != nil {
|
if _, err = msgBuf.Write(hdrBODYSTART); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ func (r *Response) MarshalBinary() (data []byte, err error) {
|
|||||||
hasErr = true
|
hasErr = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we write the response as a whole.
|
// Now write the response as a whole.
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
if r.Status == RespStatusByteOK && hasErr {
|
if r.Status == RespStatusByteOK && hasErr {
|
||||||
@@ -130,7 +130,7 @@ func (r *Response) MarshalBinary() (data []byte, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checksum -- ALWAYS present for responses!
|
// Checksum; ALWAYS present for responses!
|
||||||
if _, _, err = r.GenChecksum(); err != nil {
|
if _, _, err = r.GenChecksum(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -426,7 +426,7 @@ func (r *Response) UnmarshalBinary(data []byte) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we've validated the checksum, we trim the msgBuf to only RGs.
|
// Now that the checksum has validated, trim the msgBuf to only RGs.
|
||||||
// Skip over the BODYSTART, record group count, and record group size.
|
// Skip over the BODYSTART, record group count, and record group size.
|
||||||
if _, err = msgBuf.Read(make([]byte, len(hdrBODYSTART)+(PackedNumSize*2))); err != nil {
|
if _, err = msgBuf.Read(make([]byte, len(hdrBODYSTART)+(PackedNumSize*2))); err != nil {
|
||||||
return
|
return
|
||||||
@@ -439,7 +439,7 @@ func (r *Response) UnmarshalBinary(data []byte) (err error) {
|
|||||||
for idx := 0; idx < rgCnt; idx++ {
|
for idx := 0; idx < rgCnt; idx++ {
|
||||||
rgBuf = new(bytes.Buffer)
|
rgBuf = new(bytes.Buffer)
|
||||||
|
|
||||||
// The RG unmarshaler handles the record count, but we need to read it into msgBuf.
|
// The RG unmarshaler handles the record count, but it needs to be in msgBuf to do that.
|
||||||
if _, err = io.CopyN(rgBuf, msgBuf, int64(PackedNumSize)); err != nil {
|
if _, err = io.CopyN(rgBuf, msgBuf, int64(PackedNumSize)); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,8 +189,8 @@ func (r *ResponseRecordGroup) UnmarshalBinary(data []byte) (err error) {
|
|||||||
for idx := 0; idx < cnt; idx++ {
|
for idx := 0; idx < cnt; idx++ {
|
||||||
recBuf = new(bytes.Buffer)
|
recBuf = new(bytes.Buffer)
|
||||||
|
|
||||||
// We skip over the KVP count; that's handled in the record Unmarshaler.
|
// Skip over the KVP count; that's handled in the record Unmarshaler.
|
||||||
// We *do*, however, need to save it to the recBuf.
|
// It does need to be written to recBuf, though.
|
||||||
if _, err = io.CopyN(recBuf, buf, int64(PackedNumSize)); err != nil {
|
if _, err = io.CopyN(recBuf, buf, int64(PackedNumSize)); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
6
go.mod
6
go.mod
@@ -1,8 +1,10 @@
|
|||||||
module r00t2.io/wireproto
|
module r00t2.io/wireproto
|
||||||
|
|
||||||
go 1.23
|
go 1.24.5
|
||||||
|
|
||||||
|
toolchain go1.24.6
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
r00t2.io/goutils v1.7.0
|
r00t2.io/goutils v1.9.6
|
||||||
)
|
)
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -5,4 +5,6 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
|||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
r00t2.io/goutils v1.7.0 h1:iQluWlkOyBwOKaK94D5QSnSMYpGKtMb/5WjefmdfHgI=
|
r00t2.io/goutils v1.7.0 h1:iQluWlkOyBwOKaK94D5QSnSMYpGKtMb/5WjefmdfHgI=
|
||||||
r00t2.io/goutils v1.7.0/go.mod h1:9ObJI9S71wDLTOahwoOPs19DhZVYrOh4LEHmQ8SW4Lk=
|
r00t2.io/goutils v1.7.0/go.mod h1:9ObJI9S71wDLTOahwoOPs19DhZVYrOh4LEHmQ8SW4Lk=
|
||||||
|
r00t2.io/goutils v1.9.6 h1:ZMIIAb16y1AEt1vW1JteHLtblfpnFxyQo2c8AZ3Lf7A=
|
||||||
|
r00t2.io/goutils v1.9.6/go.mod h1:76AxpXUeL10uFklxRB11kQsrtj2AKiNm8AwG1bNoBCA=
|
||||||
r00t2.io/sysutils v1.1.1/go.mod h1:Wlfi1rrJpoKBOjWiYM9rw2FaiZqraD6VpXyiHgoDo/o=
|
r00t2.io/sysutils v1.1.1/go.mod h1:Wlfi1rrJpoKBOjWiYM9rw2FaiZqraD6VpXyiHgoDo/o=
|
||||||
|
|||||||
Reference in New Issue
Block a user