在PORT上使用PARSE!值 [英] Using PARSE on a PORT! value

查看:140
本文介绍了在PORT上使用PARSE!值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在PORT上使用PARSE!它不起作用:

 >>解析打开%test-data.r [结束] 
**脚本错误:解析不允许使用端口!因为它的输入参数

当然,如果您读取数据, b
$ b

 >>解析读取打开%test-data.r [结束] 
== true

..但它似乎是有用的,能够使用PARSE的大文件,而无需首先加载到内存中。

是否有一个原因为什么PARSE couldn 't 在PORT上工作! ...或者它只是没有实现吗?

解决方案

简单的答案是否定的,我们不能。 。

解析的方式可能需要回退到输入字符串的前一部分,这可能实际上是完成输入,当它遇到流的最后一个字符时。

端口将它们的数据复制到一个字符串缓冲区,因为它们从一个端口获得它们的输入,所以实际上,从来没有任何事先字符串解析回滚到。它就像量子物理学......只是看着它,它不在那里了。
$ b

但是,正如你所知道的反弹...不,不是一个答案。 ; - )

这就是说,有一种方法可以解析来自端口的数据,一点点工作。

你做的是使用一个缓冲区,和

  APPEND缓冲区COPY /部分连接数量

根据您的数据,金额可能是1个字节或1kb,使用什么是有道理的。



将新输入添加到缓冲区后,解析并添加逻辑以确定是否匹配该缓冲区的部分。 >

如果某些东西正确匹配,则删除/分配与缓冲区匹配的内容,然后继续解析,直到没有任何内容解析。



然后重复上面的步骤,直到输入结束。

我已经在一个实时的EDI tcp服务器中使用了这个服务器,它有一个永远在线的tcp端口来分解一个(可能)连续的输入数据流,这些数据实际上将信息从头到尾地捎带回去。

详细信息



建立这个系统的最好方法是使用/ no-wait和loop,直到端口关闭(你不会收到)。

在解析时,还要确保你有一个检查数据完整性问题的方法(比如跳过的字节或者错误的消息),否则你将永远不会结束。

在我的系统中,当缓冲区超出了特定的大小,我尝试了一个跳过字节的替代规则,直到模式可能进一步在流的下面找到。如果找到一个,记录一个错误,存储部分消息,并提出系统管理员清理该消息的提示。



HTH!


I tried using PARSE on a PORT! and it does not work:

>> parse open %test-data.r [to end]  
** Script error: parse does not allow port! for its input argument

Of course, it works if you read the data in:

>> parse read open %test-data.r [to end]  
== true

...but it seems it would be useful to be able to use PARSE on large files without first loading them into memory.

Is there a reason why PARSE couldn't work on a PORT! ... or is it merely not implemented yet?

解决方案

the easy answer is no we can't...

The way parse works, it may need to roll-back to a prior part of the input string, which might in fact be the head of the complete input, when it meets the last character of the stream.

ports copy their data to a string buffer as they get their input from a port, so in fact, there is never any "prior" string for parse to roll-back to. its like quantum physics... just looking at it, its not there anymore.

But as you know in rebol... no isn't an answer. ;-)

This being said, there is a way to parse data from a port as its being grabbed, but its a bit more work.

what you do is use a buffer, and

APPEND buffer COPY/part connection amount

Depending on your data, amount could be 1 byte or 1kb, use what makes sense.

Once the new input is added to your buffer, parse it and add logic to know if you matched part of that buffer.

If something positively matched, you remove/part what matched from the buffer, and continue parsing until nothing parses.

you then repeat above until you reach the end of input.

I've used this in a real-time EDI tcp server which has an "always on" tcp port in order to break up a (potentially) continuous stream of input data, which actually piggy-backs messages end to end.

details

The best way to setup this system is to use /no-wait and loop until the port closes (you receive none instead of "").

Also make sure you have a way of checking for data integrity problems (like a skipped byte, or erroneous message) when you are parsing, otherwise, you will never reach the end.

In my system, when the buffer was beyond a specific size, I tried an alternate rule which skipped bytes until a pattern might be found further down the stream. If one was found, an error was logged, the partial message stored and a alert raised for sysadmin to sort out the message.

HTH !

这篇关于在PORT上使用PARSE!值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆