Created
April 25, 2023 10:46
-
-
Save bo-tato/7062c3770cbe7df105b8aa839a244126 to your computer and use it in GitHub Desktop.
protohackers challenge4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :challenge4 | |
(:use cl usocket) | |
(:export main) | |
(:import-from flexi-streams | |
:string-to-octets | |
:octets-to-string) | |
(:import-from serapeum | |
:fmt | |
:@ | |
:dict)) | |
(in-package :challenge4) | |
(defvar *db* (dict "version" "Ken's Key-Value Store 1.0")) | |
(defun handler (msg) | |
(destructuring-bind (key &optional value) | |
(str:split "=" (octets-to-string msg) :limit 2) | |
(if value | |
(unless (string= key "version") | |
(setf (@ *db* key) value) | |
nil) | |
(string-to-octets (fmt "~a=~a" key (@ *db* key)))))) | |
(socket-server "0.0.0.0" 1234 'handler nil :protocol :datagram) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment