Adding tests for stream serialization
This commit is contained in:
1 parent
52c1e500e6
commit
7104e90fc9
48 files changed
+2827
-2521
No files matched your search
@@ -5,10 +5,9 @@ using System.Collections.Generic;
|
||||
namespace bts {
|
||||
using BCG;
|
||||
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
|
||||
public interface IPubSubMessage {
|
||||
void serialize_into_str(Stream str);
|
||||
@@ -40,28 +39,31 @@ namespace bts {
|
||||
public class SubscribeMsg : IPubSubMessage {
|
||||
|
||||
public string connection;
|
||||
public string subscribing_app;
|
||||
public string subscribing_app = ClientInfo.thisClient.app;
|
||||
public string[] tags;
|
||||
public void serialize_into_str(Stream str) {
|
||||
BinaryWriter bw = new BinaryWriter(str);
|
||||
bw.Write(connection);
|
||||
bw.Write(subscribing_app);
|
||||
bw.write_string_cpp(connection);
|
||||
bw.write_string_cpp(subscribing_app);
|
||||
bw.Write(tags.Length);
|
||||
foreach (var t in tags)
|
||||
bw.Write(t);
|
||||
bw.write_string_cpp(t);
|
||||
}
|
||||
|
||||
public void consruct_deserialize(Stream str) {
|
||||
BinaryReader br = new BinaryReader(str);
|
||||
this.connection = br.ReadString();
|
||||
this.subscribing_app = br.ReadString();
|
||||
this.connection = br.read_string_cpp();
|
||||
this.subscribing_app = br.read_string_cpp();
|
||||
var n_tags = br.ReadInt32();
|
||||
tags = new string[n_tags];
|
||||
for (var i = 0; i < n_tags; i++)
|
||||
tags[i] = br.ReadString();
|
||||
tags[i] = br.read_string_cpp();
|
||||
}
|
||||
public override string ToString() {
|
||||
return $"{GetType().Name} connection: {connection} subscribing_app: {subscribing_app} tags: {tags.Length}";
|
||||
var tgs_str = String.Empty;
|
||||
foreach (var t in tags)
|
||||
tgs_str += t;
|
||||
return $"{GetType().Name} connection: {connection} subscribing_app: {subscribing_app} tags: {tgs_str}";
|
||||
}
|
||||
public override bool Equals(object? obj) {
|
||||
if (obj != null && obj is SubscribeMsg) {
|
||||
@@ -73,6 +75,11 @@ namespace bts {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
var str = ToString();
|
||||
return str.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
// Unsubscribe ////////////////////////////////////////////////////////////
|
||||
@@ -112,17 +119,17 @@ namespace bts {
|
||||
public string publishing_app = ClientInfo.thisClient.app;
|
||||
public string tag;
|
||||
public string tag_type;
|
||||
public bool is_compressed;
|
||||
public bool is_compressed = false;
|
||||
// this is the size that of the msg, regarless of it being serialized or not
|
||||
public long publish_time_epoch_ms;
|
||||
public byte[] data_to_publish;
|
||||
|
||||
public void serialize_into_str(Stream str) {
|
||||
BinaryWriter bw = new BinaryWriter(str);
|
||||
bw.Write(connection);
|
||||
bw.Write(publishing_app);
|
||||
bw.Write(tag);
|
||||
bw.Write(tag_type);
|
||||
bw.write_string_cpp(connection);
|
||||
bw.write_string_cpp(publishing_app);
|
||||
bw.write_string_cpp(tag);
|
||||
bw.write_string_cpp(tag_type);
|
||||
bw.Write(is_compressed);
|
||||
bw.Write(publish_time_epoch_ms);
|
||||
var sz = data_to_publish.Length;
|
||||
@@ -131,10 +138,10 @@ namespace bts {
|
||||
}
|
||||
public void consruct_deserialize(Stream str) {
|
||||
BinaryReader br = new BinaryReader(str);
|
||||
connection = br.ReadString();
|
||||
publishing_app = br.ReadString();
|
||||
tag = br.ReadString();
|
||||
tag_type = br.ReadString();
|
||||
connection = br.read_string_cpp();
|
||||
publishing_app = br.read_string_cpp();
|
||||
tag = br.read_string_cpp();
|
||||
tag_type = br.read_string_cpp();
|
||||
is_compressed = br.ReadBoolean();
|
||||
publish_time_epoch_ms = br.ReadInt64();
|
||||
var size = br.ReadInt32();
|
||||
@@ -277,8 +284,8 @@ namespace bts {
|
||||
public byte[] data;
|
||||
public void serialize_into_str(Stream str) {
|
||||
BinaryWriter bw = new BinaryWriter(str);
|
||||
bw.Write(tag);
|
||||
bw.Write(tag_type);
|
||||
bw.write_string_cpp(tag);
|
||||
bw.write_string_cpp(tag_type);
|
||||
bw.Write(data.Length);
|
||||
bw.Write(data);
|
||||
}
|
||||
@@ -292,8 +299,8 @@ namespace bts {
|
||||
}
|
||||
public void consruct_deserialize(Stream str) {
|
||||
BinaryReader br = new BinaryReader(str);
|
||||
tag = br.ReadString();
|
||||
tag_type = br.ReadString();
|
||||
tag = br.read_string_cpp();
|
||||
tag_type = br.read_string_cpp();
|
||||
var data_sz = br.ReadInt32();
|
||||
data = br.ReadBytes(data_sz);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user