Skip to content

Commit

Permalink
Add pkg-dns-simple-server and fix bug in reader.skip. (#2205)
Browse files Browse the repository at this point in the history
Co-authored-by: Kasper Lund <[email protected]>
  • Loading branch information
floitsch and kasperl authored Apr 8, 2024
1 parent 13d9e6c commit 6e6f62e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(TOIT_REPOS
https://github.com/nilwes/LIS3DH
https://github.com/toitlang/jaguar
https://github.com/toitlang/pkg-ar
https://github.com/toitlang/pkg-dns-simple-server
https://github.com/toitlang/pkg-font-tiny
https://github.com/toitlang/pkg-host
https://github.com/toitlang/pkg-http
Expand Down
12 changes: 0 additions & 12 deletions external/gold/toit-zygote__src__setup.toit.gold

This file was deleted.

3 changes: 3 additions & 0 deletions lib/io/reader.toit
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ abstract class Reader implements old-reader.Reader:
buffered := buffered_
if not buffered:
if not more_: throw UNEXPECTED-END-OF-READER
// The call to $more_ may have changed $buffered_ if
// it was null. Read the field again.
buffered = buffered_

while n > 0:
if buffered.size == 0:
Expand Down
12 changes: 12 additions & 0 deletions lib/net/modules/dns.toit
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,18 @@ class SrvResource extends StringResource:
constructor name/string type/int ttl/int flush/bool value/string .priority .weight .port:
super name type ttl flush value

/**
Decodes a name from a DNS (RFC 1035) packet.
The block is invoked with the index of the next data in the packet.
Deprecated. Use $(decode-name reader packet) instead.
*/
decode-name packet/ByteArray position/int [position-block] -> string:
reader := io.Reader packet[position..]
result := decode-name reader packet
position-block.call (position + reader.processed)
return result

/**
Decodes a name from a DNS (RFC 1035) packet.
Expand Down
11 changes: 11 additions & 0 deletions tests/io-reader3-test.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2024 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import expect show *
import io

main:
reader := io.Reader #[1, 2, 3, 4]
reader.skip 2
expect-equals #[3, 4] (reader.read-bytes 2)

0 comments on commit 6e6f62e

Please sign in to comment.