veilidchat work

This commit is contained in:
Christien Rioux 2023-07-12 21:28:00 -04:00
parent d48ce521b2
commit 4078c00098
3 changed files with 39 additions and 3 deletions

View File

@ -55,6 +55,8 @@ sealed class DHTSchema with _$DHTSchema {
_$DHTSchemaFromJson(json);
}
const DHTSchema defaultDHTSchema = DHTSchema.dflt(oCnt: 1);
@freezed
class DHTSchemaMember with _$DHTSchemaMember {
@Assert('mCnt > 0 && mCnt <= 65535', 'value out of range')

View File

@ -47,6 +47,19 @@ abstract class EncodedString extends Equatable {
@override
String toString() => contents;
static T fromBytes<T extends EncodedString>(Uint8List bytes) {
switch (T) {
case FixedEncodedString32:
return FixedEncodedString32.fromBytes(bytes) as T;
case FixedEncodedString43:
return FixedEncodedString43.fromBytes(bytes) as T;
case FixedEncodedString86:
return FixedEncodedString86.fromBytes(bytes) as T;
default:
throw UnimplementedError();
}
}
static T fromString<T extends EncodedString>(String s) {
switch (T) {
case FixedEncodedString32:
@ -72,6 +85,13 @@ class FixedEncodedString32 extends EncodedString {
return 24;
}
factory FixedEncodedString32.fromBytes(Uint8List bytes) {
if (bytes.length != decodedLength()) {
throw Exception("length ${bytes.length} should be ${decodedLength()}");
}
return FixedEncodedString32._(base64UrlNoPadEncode(bytes));
}
factory FixedEncodedString32.fromString(String s) {
var d = base64UrlNoPadDecode(s);
if (d.length != decodedLength()) {
@ -96,6 +116,13 @@ class FixedEncodedString43 extends EncodedString {
return 32;
}
factory FixedEncodedString43.fromBytes(Uint8List bytes) {
if (bytes.length != decodedLength()) {
throw Exception("length ${bytes.length} should be ${decodedLength()}");
}
return FixedEncodedString43._(base64UrlNoPadEncode(bytes));
}
factory FixedEncodedString43.fromString(String s) {
var d = base64UrlNoPadDecode(s);
if (d.length != decodedLength()) {
@ -124,6 +151,13 @@ class FixedEncodedString86 extends EncodedString {
return toString();
}
factory FixedEncodedString86.fromBytes(Uint8List bytes) {
if (bytes.length != decodedLength()) {
throw Exception("length ${bytes.length} should be ${decodedLength()}");
}
return FixedEncodedString86._(base64UrlNoPadEncode(bytes));
}
factory FixedEncodedString86.fromString(String s) {
var d = base64UrlNoPadDecode(s);
if (d.length != decodedLength()) {

View File

@ -1,8 +1,8 @@
[tool.poetry]
name = "veilid-python"
version = "0.1.0"
name = "veilid"
version = "0.5.0"
description = ""
authors = ["Christien Rioux <chris@veilid.org>"]
authors = ["Veilid Team <contact@veilid.com>"]
readme = "README.md"
packages = [{include = "veilid"}]