我正在重新审视字节流的通信协议解析器设计(串行数据,一次接收1个字节).
数据包结构(不能更改)是:
|| Start Delimiter (1 byte) | Message ID (1 byte) | Length (1 byte) | Payload (n bytes) | Checksum (1 byte) ||
Run Code Online (Sandbox Code Playgroud)
过去,我已经采用程序状态机方法实现了这样的系统.当每个数据字节到达时,状态机被驱动以查看输入数据一次/一个字节是否适合有效数据包,并且一旦整个数据包被组装,基于消息ID的switch语句执行适当的消息处理程序.在一些实现中,解析器/状态机/消息处理程序循环位于其自己的线程中,以便不对串行数据接收的事件处理程序造成负担,并且由指示字节已被读取的信号量触发.
我想知道是否有更优雅的解决方案来解决这个常见问题,利用C#和OO设计的一些更现代的语言功能.任何可以解决这个问题的设计模式?事件驱动vs polled vs组合?
我很想听听你的想法.谢谢.
Prembo.
是否有可能检测到活动中的所有触摸事件并捕获它然后作为回传将该事件传递给另一个视图?
例如:
按钮1和按钮2.当按下按钮1时,我想捕获该触摸/点击事件并自动将该触摸事件传递给按钮2,基本上只需按一下/按下即可生成点击并将相同的点击传递给按钮2第二个按钮自动.
我有一个可编辑的UITableView.我通过以下方式提交更改:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
在编辑模式下,我希望用户能够选择一行,这将推送一个新视图.我不知道该怎么做.我怀疑它会在:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
但是如何确定用户是否处于编辑模式?
更新:编辑模式通过以下方式切换:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
Run Code Online (Sandbox Code Playgroud) 我想写一个Delphi函数来注册一个dll.我希望函数在它执行之前检查是否已经调用了OleInitialize.我想我正试图避免两次初始化的后果,因为我不确定它们可能是什么.我担心我的函数不会像regsvr32.exe一样处理各种各样的dll.
我有一个多维数组对象,在循环中我想将一个迭代器附加到键并获取值.演示示例代码:
$array_object->example1 = 1;
$array_object->example2 = 2;
$i = 1;
while ($i <= 2) {
echo ($array_object->example . $i); //this does not work
//how to accomplish same?
$i++
}
Run Code Online (Sandbox Code Playgroud)
提前感谢您的任何建议.
我正在使用html模板:
<script id="locationTemplate" type="application/template" >
<p>
<input id="searchText" type="text" />
<input id="searchlocation" type="submit" value="Search" />
</p>
<p>
<label>Location Name</label>
<input id="locationName" type="text" />
</p>
<div id="map"></div>
</script>
Run Code Online (Sandbox Code Playgroud)
我可以加载模板,但是当我尝试在模板中找到控件时,我不能.
this.template = $('#locationTemplate');
this.searchText = $(this.template.html()).find('input#searchText');
this.locationName = this.template.find('p input#locationName');
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?我尝试了两种不同的方法.
更新:
我有这个代码工作:
this.template = $('#locationTemplate');
this.searchText = $(this.template.html()).find('input#searchText');
this.locationName = $(this.template.html()).find('input#locationName');
Run Code Online (Sandbox Code Playgroud)
但我很困惑为什么我必须将html转储到另一个jQuery实例.为什么我不能只使用template.find方法,因为模板已经包装在jQuery中...
根据我的理解,document.cookie只能获取您所在网站的cookie.恶意网站是否可以通过使用iFrame,修改我的HTTP标头,向目标网站发出请求或其他方法来解决这个问题?
VS2005中的C#:你可以重载.ToString()一个属性的方法吗?
在我的macbook上,当我在浏览我的文件系统然后在textmate中打开一个文件时,它只是打开代码窗口.
如何打开textmate文件资源管理器?
如何跳转到"项目"中的文件?即根文件夹或子文件夹中的文件?
c# ×3
android ×1
append ×1
cocoa-touch ×1
com ×1
cookies ×1
delphi ×1
delphi-7 ×1
gif ×1
iframe ×1
iphone ×1
iterator ×1
jquery ×1
key ×1
macos ×1
objective-c ×1
overloading ×1
php ×1
properties ×1
protocols ×1
security ×1
serial-port ×1
textmate ×1
uitableview ×1